about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-03-24 10:53:50 +0100
committerClaire <claire.github-309c@sitedethib.com>2021-03-24 10:53:50 +0100
commitf60c99a8fb0c99554fce091cac61d9ed07eef573 (patch)
tree27457a4e091b820269daedb2f709ca304bcf5d06 /streaming
parentd7c1c41859549212a6d34ad869fded16acc17b48 (diff)
parent88d69d3261c2f02278d07dc302ff7fc15bd68e8c (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/streaming/index.js b/streaming/index.js
index d17ac64e9..724235712 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -9,9 +9,9 @@ const redis = require('redis');
 const pg = require('pg');
 const log = require('npmlog');
 const url = require('url');
-const { WebSocketServer } = require('@clusterws/cws');
 const uuid = require('uuid');
 const fs = require('fs');
+const WebSocket = require('ws');
 
 const env = process.env.NODE_ENV || 'development';
 const alwaysRequireAuth = process.env.LIMITED_FEDERATION_MODE === 'true' || process.env.WHITELIST_MODE === 'true' || process.env.AUTHORIZED_FETCH === 'true';
@@ -774,7 +774,7 @@ const startWorker = (workerId) => {
     });
   });
 
-  const wss = new WebSocketServer({ server, verifyClient: wsVerifyClient });
+  const wss = new WebSocket.Server({ server, verifyClient: wsVerifyClient });
 
   /**
    * @typedef StreamParams
@@ -1021,6 +1021,12 @@ const startWorker = (workerId) => {
     req.requestId     = uuid.v4();
     req.remoteAddress = ws._socket.remoteAddress;
 
+    ws.isAlive = true;
+
+    ws.on('pong', () => {
+      ws.isAlive = true;
+    });
+
     /**
      * @type {WebSocketSession}
      */
@@ -1070,7 +1076,17 @@ const startWorker = (workerId) => {
     }
   });
 
-  wss.startAutoPing(30000);
+  setInterval(() => {
+    wss.clients.forEach(ws => {
+      if (ws.isAlive === false) {
+        ws.terminate();
+        return;
+      }
+
+      ws.isAlive = false;
+      ws.ping('', false, true);
+    });
+  }, 30000);
 
   attachServerWithConfig(server, address => {
     log.info(`Worker ${workerId} now listening on ${address}`);