Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding subscription handling to dwn server. #68

Closed
wants to merge 6 commits into from

Conversation

andorsk
Copy link
Contributor

@andorsk andorsk commented Sep 28, 2023

Server updates for #508. In draft as #508 is still in progress and still working out some kinks. Subscriptions only work on web socket connections. It's a little different than the rest of the processMessage records, as the server has to manage the live socket connection pipes given by the dwn.

In DRAFT until everything is together and also some of the tests aren't working yet (fixing today).

Do NOT merge yet, but sharing for transparency about direction.

@codesandbox
Copy link

codesandbox bot commented Sep 28, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@andorsk
Copy link
Contributor Author

andorsk commented Oct 2, 2023

@finn-tbd if you have any time, can you take a look and give some feedback? I feel like there's some better ways to handle a few of these pieces, but wanted to get your thoughts if possible.

export class SubscriptionManager {
private wss: WebSocketServer;
private dwn: Dwn;
private connections: Map<string, Subscription>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep track of all the subscriptions here. IMPORTANT is to close the subscription when it's finished.

if (
messageType === DwnInterfaceName.Records + DwnMethodName.Write &&
!dataStream
) {
reply = await dwn.synchronizePrunedInitialRecordsWrite(target, message);
} else if (
messageType ===
DwnInterfaceName.Subscriptions + DwnMethodName.Request
Copy link
Contributor Author

@andorsk andorsk Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to handle subscription requests differently than a normal request, because we also need to setup and manage the socket connection, unlike most messages which terminate after the data is sent.

@@ -22,4 +22,8 @@ export const config = {

// log level - trace/debug/info/warn/error
logLevel: process.env.DWN_SERVER_LOG_LEVEL || 'INFO',

subscriptionsEnabled:
{ on: true, off: false }[process.env.SUBSCRIPTIONS] ?? true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the environment variable to DWN_SUBSCRIPTIONS. I realize not all environment variables currently follow that convention, but I would like to move in that direction.

@finn-block
Copy link
Member

sorry i think this got lost in the shuffle. I made one comment but i'm hoping to do more in depth looking later today.

@finn-block
Copy link
Member

i looked through this more, it seems fine for now.

@LiranCohen
Copy link
Member

Closing in favor of: #107

@LiranCohen LiranCohen closed this Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants