about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-05-23 19:01:30 +0200
committerThibaut Girka <thib@sitedethib.com>2019-05-23 19:01:30 +0200
commitc0dc247bcee9080989d5e5354e54f9d320be1f13 (patch)
tree708074cbed581c48d619008f8ed58d962e0f15b7 /streaming
parent0744d6e57186292e751026fbb749728d56a8ed2d (diff)
parent89d600bedb023a9656b98d22deab10f8c051a664 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/models/account.rb
- app/views/settings/profiles/show.html.haml
- spec/controllers/api/v1/accounts/credentials_controller_spec.rb

Conflicts were due to an increase in account bio length upstream, which
is already covered in glitch-soc through `MAX_BIO_CHARS`.
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js25
1 files changed, 4 insertions, 21 deletions
diff --git a/streaming/index.js b/streaming/index.js
index d4fb8cad3..55ecc3ba3 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -7,7 +7,7 @@ const redis = require('redis');
 const pg = require('pg');
 const log = require('npmlog');
 const url = require('url');
-const WebSocket = require('uws');
+const { WebSocketServer } = require('@clusterws/cws');
 const uuid = require('uuid');
 const fs = require('fs');
 
@@ -542,20 +542,13 @@ const startWorker = (workerId) => {
     });
   });
 
-  const wss = new WebSocket.Server({ server, verifyClient: wsVerifyClient });
+  const wss = new WebSocketServer({ server, verifyClient: wsVerifyClient });
 
-  wss.on('connection', ws => {
-    const req      = ws.upgradeReq;
+  wss.on('connection', (ws, req) => {
     const location = url.parse(req.url, true);
     req.requestId  = uuid.v4();
     req.remoteAddress = ws._socket.remoteAddress;
 
-    ws.isAlive = true;
-
-    ws.on('pong', () => {
-      ws.isAlive = true;
-    });
-
     let channel;
 
     switch(location.query.stream) {
@@ -616,17 +609,7 @@ const startWorker = (workerId) => {
     }
   });
 
-  setInterval(() => {
-    wss.clients.forEach(ws => {
-      if (ws.isAlive === false) {
-        ws.terminate();
-        return;
-      }
-
-      ws.isAlive = false;
-      ws.ping('', false, true);
-    });
-  }, 30000);
+  wss.startAutoPing(30000);
 
   attachServerWithConfig(server, address => {
     log.info(`Worker ${workerId} now listening on ${address}`);