-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds the ability for a client to send a "ping" to the server and receive a "pong" response. The motivation for this is that sometimes the socket underlying the `Connection` may not reliably report its connection state (for example if using a wrapper around a "vanilla" websocket that handles reconnection). The most bullet-proof way for a client to determine its connection state is to actually make a request to the server and assert that it receives a timely response. The implementation of ping/pong is arguably a websocket concern, especially since it's already [defined by the spec][1]. However, the browser JavaScript [`WebSocket`][2] does not expose this functionality, so we have to add our own ping/pong layer on top anyway. It's also worth noting that consumers of this library can't easily send their own ping messages down the socket, since ShareDB will [error][3] for unknown messages. Note that this change only adds the ability for a client to ping the server, and not the other way around. This is because: - the `Agent` is not an `Emitter`, and emitting a `pong` on the `Backend` is pretty meaningless - server-side implementations of WebSockets, such as `ws`, _do_ [expose a `ping` API][4] [1]: https://www.rfc-editor.org/rfc/rfc6455#section-5.5.2 [2]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket [3]: https://github.com/share/sharedb/blob/8b531bedf19860ffe0b37a3e1c8da7a32b5005bd/lib/agent.js#L451 [4]: https://github.com/websockets/ws/blob/966f9d47cd0ff5aa9db0b2aa262f9819d3f4d414/lib/websocket.js#L351
- Loading branch information
1 parent
8b531be
commit 5cb2dc5
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters