fix(assist): fixed issue with agent back compatibility

This commit is contained in:
Alexander Zavorotynskiy 2023-06-19 16:18:33 +02:00
parent 67f38ba445
commit ca80f4071f
3 changed files with 28 additions and 13 deletions

View file

@ -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);

View file

@ -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}`);

View file

@ -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}`);