kweb-core
kweb-core copied to clipboard
Make communication channel more robust
There is some evidence that websockets may not be reliable in some circumstances. @gtod did some research on the subject, which I've pasted below.
There are steps that can be taken to make them more robust, for example this JS library that we should be able to implement quite easily in KWeb. We could also fall-back to "comet"-style polling if there is a problem with websockets (perhaps because the user agent is older).
See WebSockets: caution required and You might not need a websocket. Some of the issues discussed in both the articles and accompanying hacker news discussions follow.
Flaky client websocket connections
Especially over mobile when the user loses their office wifi and reverts to 4G or 3G. What will happen in kweb?
Use Server Sent Events instead
From You might not need a WebSocket:
Arnout Kazemier (“WebSuckets”, Primus) recently posed this thought about EventSource: “It’s there. It’s really cool. It has automatic reconnect. It works through proxies […]. And it’s streaming. So why are we not using it?” Good question.
Of course, it's unidirectional...
Using https exclusively
Looks like we can use nginx as a reverse proxy for websockets so that needs to be tested.
Messaging patterns
See MessageBus for a Rails messaging protocol as opposed to using the raw bidirectional websocket.
Connections are lower level than AJAX/apollo-client
AJAX requests mean we don't care about TCP/IP, persistent connections, re-connections, timeouts. By using a websocket directly some of these issues are now back in our face.
Writing to a closed websocket can crash your iphone.
This is/was Safari in 2013. websuckets (2013)
Firefox can create ghost connections when you connects during ws.onclose
Mobile providers block differently
Corporate firewalls block ws ports
Obviated by using HTTPS exclusively? This is an older issue, I think ws connections are now happy to coexist on port 443...
Maybe it should use fresh'n'hot rsocket? http://rsocket.io/
We've done a lot of work with this, closing.