diff options
author | ThibG <thib@sitedethib.com> | 2019-05-23 20:49:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-23 20:49:18 +0200 |
commit | c394d3cb25ad39f169fbf45d18153a51d34c43ad (patch) | |
tree | 11d01b48950d43991005ae1ba7190165edfd2c2b /streaming/index.js | |
parent | 0744d6e57186292e751026fbb749728d56a8ed2d (diff) | |
parent | a1143a19c076c55bf97b3429796db93dd96e0812 (diff) |
Merge pull request #1065 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'streaming/index.js')
-rw-r--r-- | streaming/index.js | 25 |
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}`); |