Skip to content

Commit

Permalink
fix(flat-stores): make duration equal to the server (#1965)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious authored Jul 13, 2023
1 parent 182ff68 commit 4bae314
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 3 additions & 7 deletions packages/flat-stores/src/classroom-replay-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion packages/flat-stores/src/classroom-replay-store/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export async function getRecordings(roomUUID: string): Promise<Recording[]> {
export async function getRoomRecordings(roomUUID: string): Promise<RoomRecording[]> {
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;
Expand Down

0 comments on commit 4bae314

Please sign in to comment.