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

Question: How to subscribe client to different channels on demand #19

Open
JavoByte opened this issue Jul 26, 2017 · 3 comments
Open

Question: How to subscribe client to different channels on demand #19

JavoByte opened this issue Jul 26, 2017 · 3 comments

Comments

@JavoByte
Copy link

Hi

I have a problem and I don't exactly know how to solve it. Currently, I'm using this library to subscribe clients to specific events. However, in my case, a client can subscribe to multiple events. So, I have to open an EventSource per event source.

My question is, could it be possible to have only one EventSource and in my node server have a route like
events/:eventID/subscribe
which, assuming the client has already opened an EventSource and a SseChannel for the eventID exists, add the client to the SseChannel so the next message sent to the channel is received by the client?

The response content type of this url should be application/json just saying something like "Ok, you'll receive updates in your EventSource" and may be, trigger a message in the EventSource.

How would you solve this or attack this problem? I'm a clueless here.

@wKovacs64
Copy link
Contributor

I ran into this as well and I ended up solving it by constructing my own logical channels rather than utilizing the literal channels included in sse-channel. Each message that gets sent out includes a channels array and the client is responsible for handling channel-targeted messages accordingly (the client knows what channels it cares about). This worked in my environment because I wrote both the API and the client code, and the data is not sensitive (all clients receive every message and that's OK). Whether or not this approach would work for you depends on the details of your specific use case, of course.

@elf-pavlik
Copy link

How about having a SseChannel per event and use query params which would have array of events cilents want to subscribe to. Then in the handler of that route you could add that client to all the channels listed in that query param.

@joepie91
Copy link

See #25 for a proposed feature that would solve these requirements.

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

No branches or pull requests

4 participants