Skip to content

Commit

Permalink
fix: fix restore connection by first socket id
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Mar 31, 2024
1 parent 024dfdc commit d5f6e71
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function initQueue() {
function getKeyBySocketId(socketId) {
for (let sid in sockets) {
const s = sockets[sid];
if (s.opts && s.opts.socket && s.opts.socket.id == socketId) return sid;
if (s?.opts?.socket?.id === socketId || sid === socketId) return sid;
}
}

Expand All @@ -208,10 +208,10 @@ function serverState() {

const socketsList = [];

// for debug
for (let sid in sockets) {
const s = sockets[sid];
const msg = s.opts && s.opts.socket && s.opts.socket.id != sid ? `${sid} => ${s.opts.socket.id}` : sid;
// const msg = `${sid} => ${sockets[sid].opts.socket.id}`;
const msg = s?.opts?.socket?.id !== sid ? `${sid} => ${s.socket.id}` : sid;
socketsList.push(msg);
}

Expand Down Expand Up @@ -246,7 +246,7 @@ function sendStats(socket) {
}

function onSocketConnection(socket) {
log("user connected to server", socket, true);
log(`user connected to server, connectionId: ${socket.id}`, socket, true);
connections++;
// console.log('socket.id: ', socket.id);
sockets[socket.id] = { socket, opts: {} };
Expand Down

0 comments on commit d5f6e71

Please sign in to comment.