Skip to content

Commit

Permalink
fix(desktop): exit room when creator cancel it (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed May 20, 2021
1 parent 99dcc9a commit f2bdff9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions desktop/renderer-app/src/stores/ClassRoomStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { message } from "antd";
import { action, makeAutoObservable, observable, runInAction } from "mobx";
import { action, autorun, makeAutoObservable, observable, runInAction } from "mobx";
import { v4 as uuidv4 } from "uuid";
import dateSub from "date-fns/sub";
import { Rtc as RTCAPI, RtcChannelType } from "../apiMiddleware/Rtc";
Expand Down Expand Up @@ -91,6 +91,8 @@ export class ClassRoomStore {

private readonly recordingConfig: RecordingConfig;

private roomStatusOverride: RoomStatus | null = null;

private _noMoreRemoteMessages = false;

private _collectChannelStatusTimeout?: number;
Expand Down Expand Up @@ -133,6 +135,13 @@ export class ClassRoomStore {
this.whiteboardStore = new WhiteboardStore({
isCreator: this.isCreator,
});

autorun(reaction => {
if (this.whiteboardStore.isKicked) {
reaction.dispose();
this.roomStatusOverride = RoomStatus.Stopped;
}
});
}

public get ownerUUID(): string {
Expand All @@ -156,7 +165,7 @@ export class ClassRoomStore {
}

public get roomStatus(): RoomStatus {
return this.roomInfo?.roomStatus || RoomStatus.Idle;
return this.roomStatusOverride || this.roomInfo?.roomStatus || RoomStatus.Idle;
}

public startClass = (): Promise<void> => this.switchRoomStatus(RoomStatus.Started);
Expand Down
10 changes: 10 additions & 0 deletions desktop/renderer-app/src/stores/WhiteboardStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class WhiteboardStore {
public isWritable: boolean;
public isShowPreviewPanel = false;
public isFileOpen = false;
public isKicked = false;

/** is room Creator */
public readonly isCreator: boolean;
Expand Down Expand Up @@ -152,6 +153,15 @@ export class WhiteboardStore {
onDisconnectWithError: error => {
console.error(error);
},
onKickedWithReason: reason => {
if (
reason === "kickByAdmin" ||
reason === "roomDelete" ||
reason === "roomBan"
) {
this.isKicked = true;
}
},
},
);

Expand Down

0 comments on commit f2bdff9

Please sign in to comment.