leonardoventurini / helene

Real-time Web Apps for Node.js
https://helene.techster.tech
MIT License
37 stars 1 forks source link

The server sent events mode might not fully work on multi instance clusters #17

Open leonardoventurini opened 1 year ago

leonardoventurini commented 1 year ago

Right now the init call (http) needs to occur on the same server as the event source connection is established at for some event event functionality to work.

Authentication actually works fine since we send the token in the HTTP request for the EventSoource:

https://github.com/leonardoventurini/helene/blob/3db53f62eb6c882f1da5c29c7e19bb4eda180a1e/packages/server/src/transports/http-transport.ts#L149

The problem is when we call sendEvent to the connection instance coming from a method call:

https://github.com/leonardoventurini/helene/blob/e47b02a9e9d73ee9ebeb4a60aae905d5a2587ec0/packages/server/src/client-node.ts#L153

We need to leverage Redis pub/sub for this.

For now using the normal event functionality should work fine.

leonardoventurini commented 1 year ago

The main reason I opted to implement SSE/EventSource is because WebSockets don't play well with iOS/Safari PWAs. Once you minimize and then bring it back after some time the WS connection cannot be re-established. I tried all workarounds I could possibly think of to no avail.