From e67493c13d1540b531b73a6c7fa52fbed431ef4f Mon Sep 17 00:00:00 2001 From: Ayush Mukherjee Date: Wed, 24 Mar 2021 21:15:00 +0530 Subject: [PATCH] refactor fix --- src/index.js | 8 +++++--- src/ws/streams.js | 12 +++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index de98a56..c64ad89 100644 --- a/src/index.js +++ b/src/index.js @@ -45,12 +45,14 @@ server.on('upgrade', (req, socket, head) => { if (pathname[1] === 'ws' && get(token)) { wss1.handleUpgrade(req, socket, head, (socket) => { req.id = token - wss1.emit('connection', socket, req); + wss1.emit('connection', socket, req) }) } else if (pathname[1] === 'stream') { wss2.handleUpgrade(req, socket, head, (socket) => { - req.id = token - wss2.emit('connection', socket, req); + if (req.id != null || req.id != '') { + req.id = token + wss2.emit('connection', socket, req) + } }) } }) \ No newline at end of file diff --git a/src/ws/streams.js b/src/ws/streams.js index 9ceef28..a65464c 100644 --- a/src/ws/streams.js +++ b/src/ws/streams.js @@ -37,13 +37,11 @@ const recvUpdate = async (channel, data) => { const sendInitial = async (id) => { const c = connections[id] - if (c.streamid !== null) { - const stream = await crud['streams'].getById(c.streamid) - c.connection.send(JSON.stringify({ - event: 'streams:read', - data: stream, - })) - } + const stream = await crud['streams'].getById(c.streamid) + c.connection.send(JSON.stringify({ + event: 'streams:read', + data: stream, + })) } module.exports = {