forked from enisdenjo/graphql-ws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Bidirectional ping/pong message types (enisdenjo#201)
BREAKING CHANGE: Because of the Protocol's strictness, an instant connection termination will happen whenever an invalid message is identified; meaning, all previous implementations will fail when receiving the new subprotocol ping/pong messages. **Beware,** the client will NOT ping the server by default. Please make sure to upgrade your stack in order to support the new ping/pong message types. A simple recipe showcasing a client that times out if no pong is received and measures latency, looks like this: ```js import { createClient } from 'graphql-ws'; let activeSocket, timedOut, pingSentAt = 0, latency = 0; createClient({ url: 'ws://i.time.out:4000/and-measure/latency', keepAlive: 10_000, // ping server every 10 seconds on: { connected: (socket) => (activeSocket = socket), ping: (received) => { if (!received /* sent */) { pingSentAt = Date.now(); timedOut = setTimeout(() => { if (activeSocket.readyState === WebSocket.OPEN) activeSocket.close(4408, 'Request Timeout'); }, 5_000); // wait 5 seconds for the pong and then close the connection } }, pong: (received) => { if (received) { latency = Date.now() - pingSentAt; clearTimeout(timedOut); // pong is received, clear connection close timeout } }, }, }); ```
- Loading branch information
Showing
14 changed files
with
562 additions
and
124 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[graphql-ws](../README.md) / [common](../modules/common.md) / PingMessage | ||
|
||
# Interface: PingMessage | ||
|
||
[common](../modules/common.md).PingMessage | ||
|
||
## Table of contents | ||
|
||
### Properties | ||
|
||
- [type](common.pingmessage.md#type) | ||
|
||
## Properties | ||
|
||
### type | ||
|
||
• `Readonly` **type**: [Ping](../enums/common.messagetype.md#ping) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[graphql-ws](../README.md) / [common](../modules/common.md) / PongMessage | ||
|
||
# Interface: PongMessage | ||
|
||
[common](../modules/common.md).PongMessage | ||
|
||
## Table of contents | ||
|
||
### Properties | ||
|
||
- [type](common.pongmessage.md#type) | ||
|
||
## Properties | ||
|
||
### type | ||
|
||
• `Readonly` **type**: [Pong](../enums/common.messagetype.md#pong) |
Oops, something went wrong.