-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ interface OffsetOptions { | |
} | ||
|
||
interface VideoReplayerOptions { | ||
durationMs: 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 _durationMs: number; | ||
public config: VideoReplayerConfig = { | ||
skipInactive: false, | ||
speed: 1.0, | ||
|
@@ -73,6 +75,7 @@ export class VideoReplayer { | |
onFinished, | ||
onLoaded, | ||
clipWindow, | ||
durationMs, | ||
}: VideoReplayerOptions | ||
) { | ||
this._attachments = attachments; | ||
|
@@ -86,6 +89,7 @@ export class VideoReplayer { | |
}; | ||
this._videos = new Map<any, HTMLVideoElement>(); | ||
this._clipDuration = undefined; | ||
this._durationMs = durationMs; | ||
|
||
this.wrapper = document.createElement('div'); | ||
if (root) { | ||
|
@@ -111,7 +115,11 @@ export class VideoReplayer { | |
this.stopReplay(); | ||
}); | ||
} else { | ||
// Otherwise, if there's no clip window set, we should | ||
// Tell the timer to stop at the replay end | ||
this._timer.addNotificationAtTime(this._durationMs, () => { | ||
this.stopReplay(); | ||
}); | ||
// If there's no clip window set, we should | ||
// load the first segment by default so that users are not staring at a | ||
// blank replay. This initially caused some issues | ||
// (https://github.com/getsentry/sentry/pull/67911), but the problem was | ||
|
@@ -247,13 +255,14 @@ export class VideoReplayer { | |
this._isPlaying = true; | ||
this._timer.start(videoOffsetMs); | ||
|
||
// This is used when a replay clip is restarted | ||
// This is used when a replay is restarted | ||
// Add another stop notification so the timer doesn't run over | ||
if (this._clipDuration) { | ||
this._timer.addNotificationAtTime(this._clipDuration, () => { | ||
this._timer.addNotificationAtTime( | ||
this._clipDuration ? this._clipDuration : this._durationMs, | ||
() => { | ||
this.stopReplay(); | ||
}); | ||
} | ||
} | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -297,8 +306,16 @@ export class VideoReplayer { | |
|
||
// No more segments | ||
if (nextIndex >= this._attachments.length) { | ||
if (this.getCurrentTime() < this._durationMs) { | ||
// 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._durationMs, () => { | ||
this.stopReplay(); | ||
}); | ||
return; | ||
} | ||
Comment on lines
+309
to
+317
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 this tested? 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.stopReplay(); | ||
return; | ||
} | ||
|
||
// Final check in case replay was stopped immediately after a video | ||
|
@@ -598,8 +615,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._durationMs, () => { | ||
this.stopReplay(); | ||
}); | ||
return Promise.resolve(); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billyvg i tried to test that here