fix(assist): fixed issue with agent back compatibility
This commit is contained in:
parent
67f38ba445
commit
ca80f4071f
3 changed files with 28 additions and 13 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue