From 4bae314979d3f6e088734bfac8220570f435624d Mon Sep 17 00:00:00 2001 From: hyrious Date: Thu, 13 Jul 2023 15:35:04 +0800 Subject: [PATCH] fix(flat-stores): make duration equal to the server (#1965) --- .../flat-stores/src/classroom-replay-store/index.ts | 10 +++------- .../flat-stores/src/classroom-replay-store/utils.ts | 4 +++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/flat-stores/src/classroom-replay-store/index.ts b/packages/flat-stores/src/classroom-replay-store/index.ts index 8314bb1565e..2ae6fed65fc 100644 --- a/packages/flat-stores/src/classroom-replay-store/index.ts +++ b/packages/flat-stores/src/classroom-replay-store/index.ts @@ -39,7 +39,7 @@ export class ClassroomReplayStore { public tempTimestamp = 0; // used for displaying instant timestamp before debounced seeking public currentTime = 0; // mirror syncPlayer.currentTime - public duration = 0; // mirror syncPlayer.duration + public duration = 0; // mirror r.endTime - r.beginTime public get currentTimestamp(): number { return this.tempTimestamp || this.realTimestamp; @@ -112,6 +112,7 @@ export class ClassroomReplayStore { this.currentRecording = recording; this.isPlaying = false; this.currentTime = 0; + this.duration = recording.endTime - recording.beginTime; this.video = null; if (this.fastboard) { @@ -192,16 +193,11 @@ export class ClassroomReplayStore { const syncPlayer = new SyncPlayer({ players }); this.sideEffect.add(() => { - const updateDuration = action(() => { - this.duration = syncPlayer.duration; - }); - syncPlayer.on("durationchange", updateDuration); const updateCurrentTime = action(() => { - this.currentTime = syncPlayer.currentTime; + this.currentTime = Math.min(syncPlayer.currentTime, this.duration); }); syncPlayer.on("timeupdate", updateCurrentTime); return () => { - syncPlayer.off("durationchange", updateDuration); syncPlayer.off("timeupdate", updateCurrentTime); }; }, "syncCurrentTime"); diff --git a/packages/flat-stores/src/classroom-replay-store/utils.ts b/packages/flat-stores/src/classroom-replay-store/utils.ts index 8b4cb5e04de..87c5b97f7e5 100644 --- a/packages/flat-stores/src/classroom-replay-store/utils.ts +++ b/packages/flat-stores/src/classroom-replay-store/utils.ts @@ -68,7 +68,9 @@ export async function getRecordings(roomUUID: string): Promise { export async function getRoomRecordings(roomUUID: string): Promise { await roomStore.syncRecordInfo(roomUUID); const room = roomStore.rooms.get(roomUUID)!; - return toJS(room?.recordings) || []; + const recordings = toJS(room?.recordings) || []; + // Remove buggy recordings + return recordings.filter(e => e.beginTime < e.endTime); } const M3U8_EXT = /\.m3u8$/i;