context-mod
context-mod copied to clipboard
Replace websockets with polling
Previously replaced a large swatch of the initial websockets implementation with polling in #91
Currently websockets has become more cumbersome than it is beneficial:
- Requires a separate implementation to "sync" authentication with regular session when client connects (more code to maintain)
- Client is not actually using benefits of bi-directional communication -- its only used for server -> client updates
- Requires more configuration/setup for reverse-proxy which is a barrier to easy deployment
- Recently, for some reason, even though it is only being used on the status page for receiving
opStats
updates it is sending a massive amount of data.
It would be a better develop experience to just remove it entirely and replace it with another polling implementation.
What about server sent events? Would remove the need to poll and you’d be able to handle it just like any other http request?
SSEs are a possibility! With SSEs I'd still need to keep track of authenticated users that are currently connected which was the primary hassle with websockets.
So far I've found polling from the client has been more than sufficient. I replaced all websocket usage on the dashboard for real-time stats and was able to reduce traffic pretty significantly by tying it into the same idle timeouts log streaming is using.
The only place I haven't been able to entirely eliminate websockets is with reddit oauth on the config editor page -- I still need a way to communicate with the main window after oauth in completed from the popup and redirect occurs. I'll see if SSE might fit the bill for this.