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 = {