feat: add new socket message when user joins room

This commit is contained in:
Arnošt Pleskot 2023-07-15 14:27:39 +02:00
parent 28b0095c8a
commit bef0f3e51d
No known key found for this signature in database
3 changed files with 49 additions and 0 deletions

View File

@ -698,6 +698,21 @@ class Collab extends PureComponent<Props, CollabState> {
});
break;
}
case "USER_JOINED": {
const { username, userId, socketId } = decryptedData.payload;
const collaborators = upsertMap(
userId,
{
username,
userId,
socketId,
},
this.collaborators,
);
this.excalidrawAPI.updateScene({
collaborators: new Map(collaborators),
});
}
}
},
);
@ -766,6 +781,15 @@ class Collab extends PureComponent<Props, CollabState> {
} else {
this.portal.socketInitialized = true;
}
if (this.portal.socket) {
this.portal.brodcastUserJoinedRoom({
username: this.state.username,
userId: this.state.userId,
socketId: this.portal.socket.id,
});
}
return null;
};

View File

@ -229,6 +229,23 @@ class Portal {
);
}
};
brodcastUserJoinedRoom = (payload: {
username: string;
userId: string;
socketId: string;
}) => {
if (this.socket) {
const data: SocketUpdateDataSource["USER_JOINED"] = {
type: "USER_JOINED",
payload,
};
return this._broadcastSocketData(
data as SocketUpdateData,
false, // volatile
);
}
};
}
export default Portal;

View File

@ -123,6 +123,14 @@ export type SocketUpdateDataSource = {
socketId: string;
};
};
USER_JOINED: {
type: "USER_JOINED";
payload: {
username: string;
userId: string;
socketId: string;
};
};
};
export type SocketUpdateDataIncoming =