From 010f0cb0d79a6e74689a357d77c34099a69020e2 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 22 Jun 2017 14:32:49 -0600 Subject: [PATCH] Added support for keep alive websocket frames --- README.md | 1 + config.js | 6 +++++- graph/subscriptions.js | 8 +++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ea9ff0e4..68547e7a8 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ sign and verify tokens via a `HS256` algorithm. - `TALK_RECAPTCHA_SECRET` (*required for reCAPTCHA support*) - server secret used for enabling reCAPTCHA powered logins. If not provided it will instead default to providing only a time based lockout. - `TALK_RECAPTCHA_PUBLIC` (*required for reCAPTCHA support*) - client secret used for enabling reCAPTCHA powered logins. If not provided it will instead default to providing only a time based lockout. - `TALK_PLUGINS_JSON` (_optional_) - used to specify the plugin config via the environment +- `TALK_KEEP_ALIVE` (_optional_) - The keepalive timeout that should be used to send keep alive messages through the websocket to keep the socket alive. (Default `30s`) Refer to the wiki page on [Configuration Loading](https://github.com/coralproject/talk/wiki/Configuration-Loading) for alternative methods of loading configuration during development. diff --git a/config.js b/config.js index 3d75f44a8..02f95d070 100644 --- a/config.js +++ b/config.js @@ -56,7 +56,11 @@ const CONFIG = { // The URL for this Talk Instance as viewable from the outside. ROOT_URL: process.env.TALK_ROOT_URL, - + + // The keepalive timeout (in ms) that should be used to send keep alive + // messages through the websocket to keep the socket alive. + KEEP_ALIVE: process.env.TALK_KEEP_ALIVE || '30s', + //------------------------------------------------------------------------------ // Recaptcha configuration //------------------------------------------------------------------------------ diff --git a/graph/subscriptions.js b/graph/subscriptions.js index 2ba0c2c1f..ec2d5b786 100644 --- a/graph/subscriptions.js +++ b/graph/subscriptions.js @@ -10,6 +10,11 @@ const plugins = require('../services/plugins'); const {deserializeUser} = require('../services/subscriptions'); +const ms = require('ms'); +const { + KEEP_ALIVE +} = require('../config'); + const { SUBSCRIBE_COMMENT_ACCEPTED, SUBSCRIBE_COMMENT_REJECTED, @@ -119,7 +124,8 @@ const createSubscriptionManager = (server) => new SubscriptionServer({ }; return baseParams; - } + }, + keepAlive: ms(KEEP_ALIVE) }, { server, path: '/api/v1/live'