diff --git a/assist/servers/websocket.js b/assist/servers/websocket.js index f146057e0..1ef75ec32 100644 --- a/assist/servers/websocket.js +++ b/assist/servers/websocket.js @@ -196,10 +196,15 @@ const autocomplete = async function (req, res) { } const findSessionSocketId = async (io, roomId, tabId) => { + let pickFirstSession = tabId === undefined; const connected_sockets = await io.in(roomId).fetchSockets(); for (let item of connected_sockets) { - if (item.handshake.query.identity === IDENTITIES.session && item.tabId === tabId) { - return item.id; + if (item.handshake.query.identity === IDENTITIES.session) { + if (pickFirstSession) { + return item.id; + } else if (item.tabId === tabId) { + return item.id; + } } } return null; @@ -368,8 +373,8 @@ module.exports = { return } // Back compatibility (add top layer with meta information) - if (args[0].meta === undefined) { - args[0] = {meta: {tabId: socket.tabId}, data: args[0]}; + if (args[0].meta === undefined && socket.identity === IDENTITIES.session) { + args[0] = {meta: {tabId: socket.tabId, version: 1}, data: args[0]}; } if (socket.identity === IDENTITIES.session) { debug && console.log(`received event:${eventName}, from:${socket.identity}, sending message to room:${socket.roomId}`); @@ -377,7 +382,7 @@ module.exports = { socket.to(socket.roomId).emit(eventName, args[0]); } else { debug && console.log(`received event:${eventName}, from:${socket.identity}, sending message to session of room:${socket.roomId}`); - let socketId = await findSessionSocketId(io, socket.roomId, args[0].meta.tabId); + let socketId = await findSessionSocketId(io, socket.roomId, args[0].meta?.tabId); if (socketId === null) { debug && console.log(`session not found for:${socket.roomId}`); io.to(socket.id).emit(EVENTS_DEFINITION.emit.NO_SESSIONS); diff --git a/ee/assist/servers/websocket-cluster.js b/ee/assist/servers/websocket-cluster.js index 4cad9dcb1..3b2231c44 100644 --- a/ee/assist/servers/websocket-cluster.js +++ b/ee/assist/servers/websocket-cluster.js @@ -247,10 +247,15 @@ const autocomplete = async function (req, res) { } const findSessionSocketId = async (io, roomId, tabId) => { + let pickFirstSession = tabId === undefined; const connected_sockets = await io.in(roomId).fetchSockets(); for (let item of connected_sockets) { - if (item.handshake.query.identity === IDENTITIES.session && item.tabId === tabId) { - return item.id; + if (item.handshake.query.identity === IDENTITIES.session) { + if (pickFirstSession) { + return item.id; + } else if (item.tabId === tabId) { + return item.id; + } } } return null; @@ -421,8 +426,8 @@ module.exports = { return } // Back compatibility (add top layer with meta information) - if (args[0].meta === undefined) { - args[0] = {meta: {tabId: socket.tabId}, data: args[0]}; + if (args[0].meta === undefined && socket.identity === IDENTITIES.session) { + args[0] = {meta: {tabId: socket.tabId, version: 1}, data: args[0]}; } if (socket.identity === IDENTITIES.session) { debug && console.log(`received event:${eventName}, from:${socket.identity}, sending message to room:${socket.roomId}`); diff --git a/ee/assist/servers/websocket.js b/ee/assist/servers/websocket.js index 4411593e4..32921fa49 100644 --- a/ee/assist/servers/websocket.js +++ b/ee/assist/servers/websocket.js @@ -216,10 +216,15 @@ const autocomplete = async function (req, res) { } const findSessionSocketId = async (io, roomId, tabId) => { + let pickFirstSession = tabId === undefined; const connected_sockets = await io.in(roomId).fetchSockets(); for (let item of connected_sockets) { - if (item.handshake.query.identity === IDENTITIES.session && item.tabId === tabId) { - return item.id; + if (item.handshake.query.identity === IDENTITIES.session) { + if (pickFirstSession) { + return item.id; + } else if (item.tabId === tabId) { + return item.id; + } } } return null; @@ -389,8 +394,8 @@ module.exports = { return } // Back compatibility (add top layer with meta information) - if (args[0].meta === undefined) { - args[0] = {meta: {tabId: socket.tabId}, data: args[0]}; + if (args[0].meta === undefined && socket.identity === IDENTITIES.session) { + args[0] = {meta: {tabId: socket.tabId, version: 1}, data: args[0]}; } if (socket.identity === IDENTITIES.session) { debug && console.log(`received event:${eventName}, from:${socket.identity}, sending message to room:${socket.peerId}`);