feat(assist): added back compatibility for sessions without tabId
This commit is contained in:
parent
5f8fed8b02
commit
b51cc1ecf4
3 changed files with 29 additions and 7 deletions
|
|
@ -266,6 +266,9 @@ module.exports = {
|
|||
let {projectKey: connProjectKey, sessionId: connSessionId, tabId:connTabId} = extractPeerId(socket.handshake.query.peerId);
|
||||
socket.peerId = socket.handshake.query.peerId;
|
||||
socket.roomId = extractRoomId(socket.peerId);
|
||||
if (connTabId === null) {
|
||||
connTabId = "back-compatibility";
|
||||
}
|
||||
socket.tabId = connTabId;
|
||||
socket.identity = socket.handshake.query.identity;
|
||||
debug && console.log(`connProjectKey:${connProjectKey}, connSessionId:${connSessionId}, connTabId:${connTabId}, roomId:${socket.roomId}`);
|
||||
|
|
@ -338,6 +341,10 @@ module.exports = {
|
|||
debug && console.log('Ignoring update event.');
|
||||
return
|
||||
}
|
||||
// Back compatibility (add top layer with meta information)
|
||||
if (args[0].meta === undefined) {
|
||||
args[0] = {meta: {tabId: socket.tabId}, data: args[0]};
|
||||
}
|
||||
Object.assign(socket.handshake.query.sessionInfo, args[0].data, {tabId: args[0].meta.tabId});
|
||||
socket.to(socket.roomId).emit(EVENTS_DEFINITION.emit.UPDATE_EVENT, args[0]);
|
||||
// Update sessionInfo for all sessions (TODO: rewrite this)
|
||||
|
|
@ -369,10 +376,9 @@ 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}`);
|
||||
// TODO: new message structure: {meta: {tabId: string::id}, data: xxx -> args[0]}
|
||||
// Back compatibility (add top layer with meta information)
|
||||
if (args[0].meta === undefined) {
|
||||
debug && console.log(`received event:${eventName}, from:${socket.identity}, but message structure is wrong, stopping onAny.`);
|
||||
return
|
||||
args[0] = {meta: {tabId: socket.tabId}, data: args[0]};
|
||||
}
|
||||
let socketId = await findSessionSocketId(io, socket.roomId, args[0].meta.tabId);
|
||||
if (socketId === null) {
|
||||
|
|
|
|||
|
|
@ -316,6 +316,10 @@ module.exports = {
|
|||
let {projectKey: connProjectKey, sessionId: connSessionId, tabId:connTabId} = extractPeerId(socket.handshake.query.peerId);
|
||||
socket.peerId = socket.handshake.query.peerId;
|
||||
socket.roomId = extractRoomId(socket.peerId);
|
||||
// Set default tabId for back compatibility
|
||||
if (connTabId === null) {
|
||||
connTabId = "back-compatibility"
|
||||
}
|
||||
socket.tabId = connTabId;
|
||||
socket.identity = socket.handshake.query.identity;
|
||||
debug && console.log(`connProjectKey:${connProjectKey}, connSessionId:${connSessionId}, connTabId:${connTabId}, roomId:${socket.roomId}`);
|
||||
|
|
@ -389,6 +393,10 @@ module.exports = {
|
|||
debug && console.log('Ignoring update event.');
|
||||
return
|
||||
}
|
||||
// Back compatibility (add top layer with meta information)
|
||||
if (args[0].meta === undefined) {
|
||||
args[0] = {meta: {tabId: socket.tabId}, data: args[0]};
|
||||
}
|
||||
Object.assign(socket.handshake.query.sessionInfo, args[0].data, {tabId: args[0].meta.tabId});
|
||||
socket.to(socket.roomId).emit(EVENTS_DEFINITION.emit.UPDATE_EVENT, args[0]);
|
||||
// Update sessionInfo for all sessions (TODO: rewrite this)
|
||||
|
|
@ -420,9 +428,9 @@ 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}`);
|
||||
// Back compatibility (add top layer with meta information)
|
||||
if (args[0].meta === undefined) {
|
||||
debug && console.log(`received event:${eventName}, from:${socket.identity}, but message structure is wrong, stopping onAny.`);
|
||||
return
|
||||
args[0] = {meta: {tabId: socket.tabId}, data: args[0]};
|
||||
}
|
||||
let socketId = await findSessionSocketId(io, socket.roomId, args[0].meta.tabId);
|
||||
if (socketId === null) {
|
||||
|
|
|
|||
|
|
@ -286,6 +286,10 @@ module.exports = {
|
|||
let {projectKey: connProjectKey, sessionId: connSessionId, tabId:connTabId} = extractPeerId(socket.handshake.query.peerId);
|
||||
socket.peerId = socket.handshake.query.peerId;
|
||||
socket.roomId = extractRoomId(socket.peerId);
|
||||
// Set default tabId for back compatibility
|
||||
if (connTabId === null) {
|
||||
connTabId = "back-compatibility"
|
||||
}
|
||||
socket.tabId = connTabId;
|
||||
socket.identity = socket.handshake.query.identity;
|
||||
debug && console.log(`connProjectKey:${connProjectKey}, connSessionId:${connSessionId}, connTabId:${connTabId}, roomId:${socket.roomId}`);
|
||||
|
|
@ -358,6 +362,10 @@ module.exports = {
|
|||
debug && console.log('Ignoring update event.');
|
||||
return
|
||||
}
|
||||
// Back compatibility (add top layer with meta information)
|
||||
if (args[0].meta === undefined) {
|
||||
args[0] = {meta: {tabId: socket.tabId}, data: args[0]};
|
||||
}
|
||||
Object.assign(socket.handshake.query.sessionInfo, args[0].data, {tabId: args[0].meta.tabId});
|
||||
socket.to(socket.roomId).emit(EVENTS_DEFINITION.emit.UPDATE_EVENT, args[0]);
|
||||
// Update sessionInfo for all sessions (TODO: rewrite this)
|
||||
|
|
@ -388,9 +396,9 @@ 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.peerId}`);
|
||||
// Back compatibility (add top layer with meta information)
|
||||
if (args[0].meta === undefined) {
|
||||
debug && console.log(`received event:${eventName}, from:${socket.identity}, but message structure is wrong, stopping onAny.`);
|
||||
return
|
||||
args[0] = {meta: {tabId: socket.tabId}, data: args[0]};
|
||||
}
|
||||
let socketId = await findSessionSocketId(io, socket.roomId, args[0].meta.tabId);
|
||||
if (socketId === null) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue