-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(replays): sync replay timer with shown duration #69074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ interface OffsetOptions { | |
} | ||
|
||
interface VideoReplayerOptions { | ||
duration: number; | ||
onBuffer: (isBuffering: boolean) => void; | ||
onFinished: () => void; | ||
onLoaded: (event: any) => void; | ||
|
@@ -56,6 +57,7 @@ export class VideoReplayer { | |
private _videos: Map<any, HTMLVideoElement>; | ||
private _videoApiPrefix: string; | ||
private _clipDuration: number | undefined; | ||
private _duration: number; | ||
public config: VideoReplayerConfig = { | ||
skipInactive: false, | ||
speed: 1.0, | ||
|
@@ -73,6 +75,7 @@ export class VideoReplayer { | |
onFinished, | ||
onLoaded, | ||
clipWindow, | ||
duration, | ||
}: VideoReplayerOptions | ||
) { | ||
this._attachments = attachments; | ||
|
@@ -86,6 +89,7 @@ export class VideoReplayer { | |
}; | ||
this._videos = new Map<any, HTMLVideoElement>(); | ||
this._clipDuration = undefined; | ||
this._duration = duration; | ||
|
||
this.wrapper = document.createElement('div'); | ||
if (root) { | ||
|
@@ -297,7 +301,12 @@ export class VideoReplayer { | |
|
||
// No more segments | ||
if (nextIndex >= this._attachments.length) { | ||
this.stopReplay(); | ||
// If we're at the end of a segment, but there's a gap | ||
// at the end, force the replay to play until the end duration | ||
// rather than stopping right away. | ||
this._timer.addNotificationAtTime(this._duration, () => { | ||
this.stopReplay(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a chance of a race condition here where by the time this notification is added, the timer is already passed duration and will continue on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one relates to the case where the replay stops early because we've hit a gap/the end of the segment -- the old code here was just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking about the case where we do not have a gap, and we want to stop the replay:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohhh i see what you're saying! let me add another check that stops the replay if the time is over There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something like
|
||
return; | ||
} | ||
|
||
|
@@ -598,8 +607,13 @@ export class VideoReplayer { | |
const loadedSegmentIndex = await this.loadSegmentAtTime(videoOffsetMs); | ||
|
||
if (loadedSegmentIndex === undefined) { | ||
// TODO: this shouldn't happen, loadSegment should load the previous | ||
// segment until it's time to start the next segment | ||
// If we end up here, we seeked into a gap | ||
// at the end of the replay. | ||
// This tells the timer to stop at the specified duration | ||
// and prevents the timer from running infinitely. | ||
this._timer.addNotificationAtTime(this._duration, () => { | ||
this.stopReplay(); | ||
}); | ||
return Promise.resolve(); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.