|
|
@ -7,7 +7,7 @@ const redis = require('redis'); |
|
|
|
const pg = require('pg'); |
|
|
|
const pg = require('pg'); |
|
|
|
const log = require('npmlog'); |
|
|
|
const log = require('npmlog'); |
|
|
|
const url = require('url'); |
|
|
|
const url = require('url'); |
|
|
|
const WebSocket = require('uws'); |
|
|
|
const { WebSocketServer } = require('@clusterws/cws'); |
|
|
|
const uuid = require('uuid'); |
|
|
|
const uuid = require('uuid'); |
|
|
|
const fs = require('fs'); |
|
|
|
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 => { |
|
|
|
wss.on('connection', (ws, req) => { |
|
|
|
const req = ws.upgradeReq; |
|
|
|
|
|
|
|
const location = url.parse(req.url, true); |
|
|
|
const location = url.parse(req.url, true); |
|
|
|
req.requestId = uuid.v4(); |
|
|
|
req.requestId = uuid.v4(); |
|
|
|
req.remoteAddress = ws._socket.remoteAddress; |
|
|
|
req.remoteAddress = ws._socket.remoteAddress; |
|
|
|
|
|
|
|
|
|
|
|
ws.isAlive = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws.on('pong', () => { |
|
|
|
|
|
|
|
ws.isAlive = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let channel; |
|
|
|
let channel; |
|
|
|
|
|
|
|
|
|
|
|
switch(location.query.stream) { |
|
|
|
switch(location.query.stream) { |
|
|
@ -610,17 +603,7 @@ const startWorker = (workerId) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
setInterval(() => { |
|
|
|
wss.startAutoPing(30000); |
|
|
|
wss.clients.forEach(ws => { |
|
|
|
|
|
|
|
if (ws.isAlive === false) { |
|
|
|
|
|
|
|
ws.terminate(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws.isAlive = false; |
|
|
|
|
|
|
|
ws.ping('', false, true); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, 30000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachServerWithConfig(server, address => { |
|
|
|
attachServerWithConfig(server, address => { |
|
|
|
log.info(`Worker ${workerId} now listening on ${address}`); |
|
|
|
log.info(`Worker ${workerId} now listening on ${address}`); |
|
|
|