mirror of
https://github.com/wassname/talk.git
synced 2026-07-01 04:17:35 +08:00
[next] Websocket Keep Alive (#2394)
* feat: added keepalive config * fix: format * fix: adjusted client timeout default * Update server.ts
This commit is contained in:
@@ -385,6 +385,9 @@ the variables in a `.env` file in the root of the project in a simple
|
||||
- `CLUSTER_METRICS_PORT` - If `CONCURRENCY` is more than `1`, the metrics are provided at this port under `/cluster_metrics`. (Default `3001`)
|
||||
- `DISABLE_LIVE_UPDATES` - When `true`, disables subscriptions for the comment
|
||||
stream for all stories across all tenants (Default `false`)
|
||||
- `WEBSOCKET_KEEP_ALIVE_TIMEOUT` - A duration in a parsable format (e.g. `30 seconds`
|
||||
, `1 minute`) that should be used to send keep alive messages through the
|
||||
websocket to keep the socket alive (Default `30 seconds`)
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ export default function createManagedSubscriptionClient(
|
||||
if (!subscriptionClient) {
|
||||
subscriptionClient = new SubscriptionClient(url, {
|
||||
reconnect: true,
|
||||
timeout: 60000,
|
||||
connectionCallback: err => {
|
||||
if (err) {
|
||||
// If an error is thrown as a result of live updates being
|
||||
|
||||
@@ -173,6 +173,14 @@ const config = convict({
|
||||
env: "STATIC_URI",
|
||||
arg: "staticUri",
|
||||
},
|
||||
websocket_keep_alive_timeout: {
|
||||
doc:
|
||||
"The keepalive timeout (in ms) that should be used to send keep alive messages through the websocket to keep the socket alive",
|
||||
format: "duration",
|
||||
default: "30 seconds",
|
||||
env: "WEBSOCKET_KEEP_ALIVE_TIMEOUT",
|
||||
arg: "websocketKeepAliveTimeout",
|
||||
},
|
||||
disable_tenant_caching: {
|
||||
doc:
|
||||
"Disables the tenant caching, all tenants will be loaded from MongoDB each time it's needed",
|
||||
|
||||
@@ -223,6 +223,13 @@ export function createSubscriptionServer(
|
||||
schema: GraphQLSchema,
|
||||
options: Options
|
||||
) {
|
||||
const keepAlive = options.config.get("websocket_keep_alive_timeout");
|
||||
if (typeof keepAlive !== "number" || keepAlive <= 0) {
|
||||
throw new Error(
|
||||
"expected the websocket_keep_alive_timeout configuration to be a positive number"
|
||||
);
|
||||
}
|
||||
|
||||
return SubscriptionServer.create(
|
||||
{
|
||||
schema,
|
||||
@@ -230,6 +237,7 @@ export function createSubscriptionServer(
|
||||
subscribe,
|
||||
onConnect: onConnect(options),
|
||||
onOperation: onOperation(options),
|
||||
keepAlive,
|
||||
},
|
||||
{
|
||||
server,
|
||||
|
||||
Reference in New Issue
Block a user