dan-cooke / remix-sse

Server Sent Events (SSE) for the remix framework
Apache License 2.0
78 stars 3 forks source link

Example that uses an external trigger #24

Closed andersr closed 6 months ago

andersr commented 7 months ago

Hi, this packages looks very interesting but it's not clear how I would trigger an event from outside the resource route. All the current examples are "self-triggering" ie just using an interval timer. How would I, for example, trigger a new event if something is created in a form in the action of a different route? Thanks for any insights!

dan-cooke commented 7 months ago

Hi @andersr

This is something that I actually came upon myself recently. I have not yet added an example to the repo, but let me have a play around and see how it would work with remix-sse

dan-cooke commented 7 months ago

Ok @andersr

So to answer your question, firstly because Server Sent Events are unidirectional - we cannot send data to the streaming route to say "hey start sending events"

So with that in mind, the solution is as follows

If you need more communication than this, then I would recommend a Websocket instead

Heres a quick PR I made that adds an example to the repo

https://github.com/dan-cooke/remix-sse/pull/25/files

Let me know if you have any other questions!

Have a nice day :)

andersr commented 7 months ago

@dan-cooke thanks so much for looking into this and for posting an example. Yes, using a session store as the "connector" between a non-resource route and the SSE route makes a lot of sense. Going to give that a shot. Thanks again!

dan-cooke commented 6 months ago

Closing this in the meantime!