Skip to content

Commit

Permalink
fix(classroom): store not destroyed after leaving room
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Aug 22, 2022
1 parent e08b874 commit 2e8095d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
21 changes: 13 additions & 8 deletions packages/flat-pages/src/utils/use-classroom-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ export function useClassroomStore(config: useClassRoomStoreConfig): ClassroomSto
}, [title]);

useEffect(() => {
let isUnmounted = false;
let classroomStore: ClassroomStore | undefined;
const flatServices = FlatServices.getInstance();

sp(
Promise.all([
flatServices.requestService("videoChat"),
flatServices.requestService("textChat"),
flatServices.requestService("whiteboard"),
]),
).then(([videoChat, textChat, whiteboard]) => {
if (videoChat && textChat && whiteboard) {
const classroomStore = new ClassroomStore({
if (!isUnmounted && videoChat && textChat && whiteboard) {
classroomStore = new ClassroomStore({
...config,
rtc: videoChat,
rtm: textChat,
Expand All @@ -45,12 +47,15 @@ export function useClassroomStore(config: useClassRoomStoreConfig): ClassroomSto
});

return () => {
if (classroomStore) {
classroomStore.destroy();
flatServices.shutdownService("videoChat");
flatServices.shutdownService("textChat");
flatServices.shutdownService("whiteboard");
}
isUnmounted = true;
classroomStore?.destroy().catch(e => {
if (process.env.NODE_ENV !== "production") {
console.error(e);
}
});
flatServices.shutdownService("videoChat");
flatServices.shutdownService("textChat");
flatServices.shutdownService("whiteboard");
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
16 changes: 0 additions & 16 deletions packages/flat-stores/src/classroom-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,24 +398,8 @@ export class ClassroomStore {
public async destroy(): Promise<void> {
this.sideEffect.flushAll();

const promises: Array<Promise<any>> = [];

promises.push(this.rtm.destroy());

// promises.push(this.stopRecording());

promises.push(this.rtc.destroy());

promises.push(this.rtc.destroy());

promises.push(this.whiteboardStore.destroy());

try {
await Promise.all(promises);
} catch (e) {
console.error(e);
}

this.deviceStateStorage = undefined;
this.classroomStorage = undefined;
}
Expand Down

0 comments on commit 2e8095d

Please sign in to comment.