Skip to content

Commit

Permalink
fix(classroom): fix user join room race condition (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Apr 23, 2021
1 parent dce8ee6 commit 2d28915
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 9 additions & 5 deletions desktop/renderer-app/src/stores/ClassRoomStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,11 @@ export class ClassRoomStore {

await this.whiteboardStore.joinWhiteboardRoom();

channel.on("MemberJoined", userUUID => {
// not use errorTips function (because there is no need)
this.users.addUser(userUUID).catch(console.warn);
});
// add user on RequestChannelStatus
// channel.on("MemberJoined", userUUID => {
// // not use errorTips function (because there is no need)
// this.users.addUser(userUUID).catch(console.warn);
// });
channel.on("MemberLeft", this.users.removeUser);

this.onRTCEvents();
Expand Down Expand Up @@ -723,8 +724,10 @@ export class ClassRoomStore {
}
});

this.rtm.on(RTMessageType.RequestChannelStatus, (status, senderId) => {
this.rtm.on(RTMessageType.RequestChannelStatus, async (status, senderId) => {
if (status.roomUUID === this.roomUUID) {
// not use errorTips function (because there is no need)
await this.users.addUser(senderId).catch(console.warn);
this.users.updateUsers(user => {
if (user.userUUID === senderId) {
if (this.users.creator && user.userUUID === this.users.creator.userUUID) {
Expand All @@ -733,6 +736,7 @@ export class ClassRoomStore {
}
user.camera = status.user.camera;
user.mic = status.user.mic;

return false;
}
return true;
Expand Down
12 changes: 12 additions & 0 deletions desktop/renderer-app/src/stores/UserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,20 @@ export class UserStore {
if (user.userUUID === this.ownerUUID) {
this.creator = user;
} else if (user.isSpeak) {
const index = this.speakingJoiners.findIndex(
({ userUUID }) => userUUID === user.userUUID,
);
if (index >= 0) {
this.speakingJoiners.splice(index, 1);
}
this.speakingJoiners.push(user);
} else if (user.isRaiseHand) {
const index = this.handRaisingJoiners.findIndex(
({ userUUID }) => userUUID === user.userUUID,
);
if (index >= 0) {
this.handRaisingJoiners.splice(index, 1);
}
this.handRaisingJoiners.push(user);
} else {
this.otherJoiners.push(user);
Expand Down

0 comments on commit 2d28915

Please sign in to comment.