-
Notifications
You must be signed in to change notification settings - Fork 50
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
Efficiently handling WebSockets #93
Comments
While I don't have a strong opinion on several of these points, I do think that wrapping WebSockets in a dojo/request-like interface makes a lot of sense. While WebSockets can improve the speed of a web application, I would argue that the primary feature that they provide is the ability to allow the server to initiate communication with a client. Given that, there are several other technologies that support that as well (e.g. HTTP/2 server push, Server-sent events, ...). While a developer would certainly have to provide some information about how to setup the connection to the server, I would imagine that the interaction with the connection after that could probably be hidden behind a fairly robust abstraction. Using a dojo/request-style interface would allow 80% of the use-cases to simply interact with the abstraction, thus removing the need to understand each technology. For more demanding scenarios the details could be exposes just like dojo/request/xhr exposes the details of the XMLHttpRequest. |
Expanding on @vansimke's thoughts, in some ways the way a promise is to a stream or observable is like an XHR is to a WebSocket, in that promises/XHR resolve once and that's it, whereas streams/WebSockets may be resolved many times. So I'm wondering if the API around a WebSocket should be more of an Observable or a stream than something that returns a single promise? |
Observables make sense from the perspective of the server sending data down to the client, but there would also have to be an aspect of the API to cover the ability to push a message back up. If we continue on the idea of some sort of interface that could be implemented by WebSockets and others, then those implementations that don't provide a native client-side push would have to have a fall back (e.g. an implementation that uses server-sent events might use regular XHRs to generate client-side messages). I think that the beauty of this approach is that any kind of "real-time store", or similar consumer of real-time data could rely on the interface, and not be concerned about how that data is getting there. That would also help to future-proof those components in the event that another real-time strategy comes along. |
What use cases are driving this need? At the moment I am not seeing a use case that would make this a priority. |
The use case in my mind was connecting the dots on how to best use WebSockets with Dojo 2. With Dojo 1, it never felt like we really had thought through the usage, so it always felt like a bit of a hack. I'm sure once dgrid 2 is ready, people will want to see the demo of a real-time stock quote chart (I'm sure Lightstreamer will want to create a demo early on for example). So if we don't have some sort of WebSocket-wrapper, that's fine, but we should at a minimum document the right way to use WebSockets with Dojo 2. |
In Dojo 1.x, WebSockets are mostly an afterthought in how we approach APIs, with most examples using traditional XHR calls, and all provide store implementations using XHR.
For Dojo 2, I think it would nice if it was clear how WebSockets are used. The native APIs for WebSocket events are rather basic, which over the years led to dojox/socket and tube.
As such I think we should consider:
The text was updated successfully, but these errors were encountered: