diff --git a/packages/flat-pages/src/utils/use-classroom-store.ts b/packages/flat-pages/src/utils/use-classroom-store.ts index 8b2afb5b5ea..627f60c38cf 100644 --- a/packages/flat-pages/src/utils/use-classroom-store.ts +++ b/packages/flat-pages/src/utils/use-classroom-store.ts @@ -20,8 +20,10 @@ 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"), @@ -29,8 +31,8 @@ export function useClassroomStore(config: useClassRoomStoreConfig): ClassroomSto 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, @@ -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 }, []); diff --git a/packages/flat-stores/src/classroom-store/index.ts b/packages/flat-stores/src/classroom-store/index.ts index 107f72d4e13..63a36e8de88 100644 --- a/packages/flat-stores/src/classroom-store/index.ts +++ b/packages/flat-stores/src/classroom-store/index.ts @@ -398,24 +398,8 @@ export class ClassroomStore { public async destroy(): Promise { this.sideEffect.flushAll(); - const promises: Array> = []; - - 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; }