-
Notifications
You must be signed in to change notification settings - Fork 13
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
WebSocket new features #27
Comments
|
Thank you for replying. It would be good if WebSocket and WebSocketStream evolve in parallel since I think many applications do not need all the power of WebSocketStream. It would be great if WebSocket supported auto reconnection, auto ping checking at a user-defined time, and also a custom type. Please discuss with your team about custom type as there are many crutches and think many would like to have built-in user type support |
Item number 4 is actually a really good idea. According to RFC 6455 when one end of the socket receives a ping that end is expected to send a pong. Since these are control frames they can be intermixed with data frames without conflict or collision. There are sufficient controls in place with something like Node that you can make a best guess determination on the health of a socket using a ping/pong round trip, but there is no access to control frames or frame headers within the browser so you are completely at the mercy of the browser that may not share the same concerns as the application maintainer. I would recommend this feature as follows (TypeScript): type pingCallback: (error:Error) => void;
type ping:(ttl:number, callback:pingCallback) => void; This method would require a TTL (time to live) and a callback.
Example: socket.ping(50, function (err) {
if (err === null) {
console.log("Socket is healthy");
} else {
console.log(err);
}
}); |
The try {
await socket.ping(AbortSignal.timeout(50));
console.log("Socket is healthy");
} catch (err) {
console.log(err);
} |
Try/catch breaks compilation in the immediate scope, so its generally not considered a best practice in high performance code. Promise chains offer a non-breaking catch which is better, but promise chains ( The AbortSignal API is for imposing a breaking halt between the DOM and execution of an event handler such that the event maybe arbitrarily cancelled whether by timeout or by an additional user interaction. Network interfaces should be isolated from external considerations, such as the DOM. A network health check could be called dynamically by a variety of means not in response from a DOM event. Edit. Before this is over engineered to death here is all it needs to be successfull: Operating scenarios:
The only complexity in this is to identify the pong corresponding to the given ping. Control frames have 119 bytes of payload available for storing an identifier. Additionally, there are the 3 rsv bits that can be flipped to identify a frame apart from other similar frames and the rsv bits are not used by the browser at all. Then the server must merely return a pong with the same payload body (unmasked) and same rsv bits (if used). Everything is vanity and supplemental. |
Sorry for my english. I'm just a fan of web technology
WebSocket has not been updated for more than 10 years. And here's what I think you can do in the following versions of WebSocket and/or WebSocketStream:
1) WebSocket custom type as variant we can set new opcode in frame and in next frames send custom type string. Server-Sent Events can send custom type
2) In WebSocket send method first arg must be custom type and second arg must be data which we want send
3) In WebSocket send method auto convert to JSON for object, array or null
4) Client ping method for checking is we connected to server
5) Add static property WebSocket.VERSION (for checking - is support options in a current version)
6) Use options object as second argument for WebSocket constructor
The text was updated successfully, but these errors were encountered: