PadMessageHandler: Also send `USER_NEWINFO` messages on reconnect
Now the user list is correct after a reconnect. This also allows ep_webrtc to automatically recover after a temporary network glitch.pull/5074/head
parent
7ca336c28e
commit
53cca5a743
|
@ -1121,72 +1121,61 @@ const handleClientReady = async (socket, message, authorID) => {
|
||||||
|
|
||||||
// Save the current revision in sessioninfos, should be the same as in clientVars
|
// Save the current revision in sessioninfos, should be the same as in clientVars
|
||||||
sessionInfo.rev = pad.getHeadRevisionNumber();
|
sessionInfo.rev = pad.getHeadRevisionNumber();
|
||||||
|
}
|
||||||
|
|
||||||
// prepare the notification for the other users on the pad, that this user joined
|
// Notify other users about this new user.
|
||||||
const messageToTheOtherUsers = {
|
socket.broadcast.to(padIds.padId).json.send({
|
||||||
|
type: 'COLLABROOM',
|
||||||
|
data: {
|
||||||
|
type: 'USER_NEWINFO',
|
||||||
|
userInfo: {
|
||||||
|
colorId: authorColorId,
|
||||||
|
name: authorName,
|
||||||
|
userId: authorID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Notify this new user about other users.
|
||||||
|
await Promise.all(_getRoomSockets(pad.id).map(async (roomSocket) => {
|
||||||
|
if (roomSocket.id === socket.id) return;
|
||||||
|
|
||||||
|
// sessioninfos might change while enumerating, so check if the sessionID is still assigned to a
|
||||||
|
// valid session.
|
||||||
|
const sessionInfo = sessioninfos[roomSocket.id];
|
||||||
|
if (sessionInfo == null) return;
|
||||||
|
|
||||||
|
// get the authorname & colorId
|
||||||
|
const authorId = sessionInfo.author;
|
||||||
|
// The authorId of this other user might be unknown if the other user just connected and has
|
||||||
|
// not yet sent a CLIENT_READY message.
|
||||||
|
if (authorId == null) return;
|
||||||
|
|
||||||
|
// reuse previously created cache of author's data
|
||||||
|
const authorInfo = historicalAuthorData[authorId] || await authorManager.getAuthor(authorId);
|
||||||
|
if (authorInfo == null) {
|
||||||
|
messageLogger.error(
|
||||||
|
`Author ${authorId} connected via socket.io session ${roomSocket.id} is missing from ` +
|
||||||
|
'the global author database. This should never happen because the author ID is ' +
|
||||||
|
'generated by the same code that adds the author to the database.');
|
||||||
|
// Don't bother telling the new user about this mystery author.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const msg = {
|
||||||
type: 'COLLABROOM',
|
type: 'COLLABROOM',
|
||||||
data: {
|
data: {
|
||||||
type: 'USER_NEWINFO',
|
type: 'USER_NEWINFO',
|
||||||
userInfo: {
|
userInfo: {
|
||||||
colorId: authorColorId,
|
colorId: authorInfo.colorId,
|
||||||
userId: authorID,
|
name: authorInfo.name,
|
||||||
|
userId: authorId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add the authorname of this new User, if avaiable
|
socket.json.send(msg);
|
||||||
if (authorName != null) {
|
}));
|
||||||
messageToTheOtherUsers.data.userInfo.name = authorName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// notify all existing users about new user
|
|
||||||
socket.broadcast.to(padIds.padId).json.send(messageToTheOtherUsers);
|
|
||||||
|
|
||||||
// Get sessions for this pad and update them (in parallel)
|
|
||||||
await Promise.all(_getRoomSockets(pad.id).map(async (roomSocket) => {
|
|
||||||
// Jump over, if this session is the connection session
|
|
||||||
if (roomSocket.id === socket.id) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since sessioninfos might change while being enumerated, check if the
|
|
||||||
// sessionID is still assigned to a valid session
|
|
||||||
const sessionInfo = sessioninfos[roomSocket.id];
|
|
||||||
if (sessionInfo == null) return;
|
|
||||||
|
|
||||||
// get the authorname & colorId
|
|
||||||
const authorId = sessionInfo.author;
|
|
||||||
// The authorId of this other user might be unknown if the other user just connected and has
|
|
||||||
// not yet sent a CLIENT_READY message.
|
|
||||||
if (authorId == null) return;
|
|
||||||
|
|
||||||
// reuse previously created cache of author's data
|
|
||||||
const authorInfo = historicalAuthorData[authorId] || await authorManager.getAuthor(authorId);
|
|
||||||
if (authorInfo == null) {
|
|
||||||
messageLogger.error(
|
|
||||||
`Author ${authorId} connected via socket.io session ${roomSocket.id} is missing from ` +
|
|
||||||
'the global author database. This should never happen because the author ID is ' +
|
|
||||||
'generated by the same code that adds the author to the database.');
|
|
||||||
// Don't bother telling the new user about this mystery author.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the new User a Notification about this other user
|
|
||||||
const msg = {
|
|
||||||
type: 'COLLABROOM',
|
|
||||||
data: {
|
|
||||||
type: 'USER_NEWINFO',
|
|
||||||
userInfo: {
|
|
||||||
colorId: authorInfo.colorId,
|
|
||||||
name: authorInfo.name,
|
|
||||||
userId: authorId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.json.send(msg);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue