-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Broadcast / client id #81
Comments
Similarly there's no such thing as an id - but neither should there be. If your application requires an id, you can easily add it as you show above. It makes perfect sense. Regarding some recipes you are absolutely right. Some time should be spent writing documentation for different scenarios. I'll bring that into consideration for future versions! |
Thanks. That's good to know. I'm working a slightly higher level JSON-based communication protocol to realize realtime applications. Very minimal somewhere between RPC and plain messages, with a straight-forward interface. :) I'll let you know once a working prototype is ready. I'd be interested in what you think. I could cover some by-example documentation by describing how I solved my problem using the In order to do a reverse lookup by client-id I need to pollute the ws object, which is not exactly elegant. So I wonder if you'd consider assigning unique client-ids natively (just a counter would be fine). Maybe this makes sense to add to ws directly, shouldn't hurt too much and could be useful in general. What do you think? // Register client on connect
openSession: function(ws) {
ws.id = this.numClients += 1;
this.clients[ws.id] = ws;
},
// Unregister client on disconnect
closeSession: function(ws) {
delete this.clients[ws.id];
}, |
I'll consider that for the next version :) Shouldn't be a problem. |
Thanks. :) |
+1 |
i do need a specefic client id ... so i could use it after close the client connection |
@einaros Any progress on this? |
+1 |
1 similar comment
+1 |
I'm doing something very similar, than the example above, just instead of storing a meaningless id, I use the sessionID provided by Express (and then I can do something like |
I think it's better to not add an id generator in this lib as there are multiple ways to generate ids and they depend on the application. |
Is there have a solution? Who can give me a URL to lean about this question.. |
Do you have a concept of a unique client id built in? I wonder how I'd address certain clients and send them messages. For a broadcast I can iterate over wss.clients. But I wonder what's the best way to pick individual ones. What does actually happen if a client disconnects. It just gets removed from the wss.clients list? I guess the best way to do it is keeping track of clients manually, once they connect.
Something like that:
Would that make sense?
I like that the lib is very low level and doesn't introduce much magic, but some recipes on how to do A or B would be nice to have. :)
The text was updated successfully, but these errors were encountered: