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.
This commit is contained in:
Richard Hansen 2021-06-16 01:28:36 -04:00
parent 7ca336c28e
commit 53cca5a743

View file

@ -1121,36 +1121,27 @@ 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', type: 'COLLABROOM',
data: { data: {
type: 'USER_NEWINFO', type: 'USER_NEWINFO',
userInfo: { userInfo: {
colorId: authorColorId, colorId: authorColorId,
name: authorName,
userId: authorID, userId: authorID,
}, },
}, },
}; });
// Add the authorname of this new User, if avaiable // Notify this new user about other users.
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) => { await Promise.all(_getRoomSockets(pad.id).map(async (roomSocket) => {
// Jump over, if this session is the connection session if (roomSocket.id === socket.id) return;
if (roomSocket.id === socket.id) {
return;
}
// Since sessioninfos might change while being enumerated, check if the // sessioninfos might change while enumerating, so check if the sessionID is still assigned to a
// sessionID is still assigned to a valid session // valid session.
const sessionInfo = sessioninfos[roomSocket.id]; const sessionInfo = sessioninfos[roomSocket.id];
if (sessionInfo == null) return; if (sessionInfo == null) return;
@ -1171,7 +1162,6 @@ const handleClientReady = async (socket, message, authorID) => {
return; return;
} }
// Send the new User a Notification about this other user
const msg = { const msg = {
type: 'COLLABROOM', type: 'COLLABROOM',
data: { data: {
@ -1186,7 +1176,6 @@ const handleClientReady = async (socket, message, authorID) => {
socket.json.send(msg); socket.json.send(msg);
})); }));
}
}; };
/** /**