summaryrefslogtreecommitdiffstats
path: root/streaming/index.js
diff options
context:
space:
mode:
authorabcang <abcang1015@gmail.com>2019-05-23 01:19:16 +0900
committerEugen Rochko <eugen@zeonfederated.com>2019-05-22 18:19:16 +0200
commitca6c93a2f51ce0c9b81d909faa94a5cdb5c25c63 (patch)
tree72645e738249aa76b06b2f68e3b49a3d086fcf2c /streaming/index.js
parent8a378d4c3d8bd74f3070af0b70725da4a6d10375 (diff)
Migrate from uws to cws (#10805)
Diffstat (limited to 'streaming/index.js')
-rw-r--r--streaming/index.js25
1 files changed, 4 insertions, 21 deletions
diff --git a/streaming/index.js b/streaming/index.js
index 2a51a1a0daa..5582677002e 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');
@@ -536,20 +536,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) {
@@ -610,17 +603,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}`);