Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(classroom): fix user join room race condition #579

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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