-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(replay): create a wrapper class to init rrweb player alongside video replayer #69927
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
12 commits
Select commit
Hold shift + click to select a range
4c3de70
feat(replays): create a wrapper class to init rrweb player alongside …
michellewzhang f83878d
add full snapshot event
michellewzhang baa0eb2
fix timestamp
michellewzhang 656f16e
Merge remote-tracking branch 'origin/master' into mz/wrapper-class
michellewzhang 58825f2
Merge remote-tracking branch 'origin/master' into mz/wrapper-class
michellewzhang e229e81
Merge remote-tracking branch 'origin/master' into mz/wrapper-class
michellewzhang f0eae62
gestures
michellewzhang e691731
mousetails working
michellewzhang 674d931
scrubbing works
michellewzhang 0554259
address pr comments
michellewzhang c7f4428
public -> private
michellewzhang 883969a
last NIT
michellewzhang 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
152 changes: 152 additions & 0 deletions
152
static/app/components/replays/videoReplayerWithInteractions.tsx
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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import type {Theme} from '@emotion/react'; | ||
import {type eventWithTime, Replayer} from '@sentry-internal/rrweb'; | ||
|
||
import { | ||
VideoReplayer, | ||
type VideoReplayerConfig, | ||
} from 'sentry/components/replays/videoReplayer'; | ||
import type {ClipWindow, VideoEvent} from 'sentry/utils/replays/types'; | ||
|
||
type RootElem = HTMLDivElement | null; | ||
|
||
interface VideoReplayerWithInteractionsOptions { | ||
durationMs: number; | ||
events: eventWithTime[]; | ||
onBuffer: (isBuffering: boolean) => void; | ||
onFinished: () => void; | ||
onLoaded: (event: any) => void; | ||
root: RootElem; | ||
start: number; | ||
theme: Theme; | ||
videoApiPrefix: string; | ||
videoEvents: VideoEvent[]; | ||
clipWindow?: ClipWindow; | ||
} | ||
|
||
/** | ||
* A wrapper replayer that wraps both VideoReplayer and the rrweb Replayer. | ||
* We need both instances in order to render the video playback alongside gestures. | ||
*/ | ||
export class VideoReplayerWithInteractions { | ||
public config: VideoReplayerConfig = { | ||
skipInactive: false, | ||
speed: 1.0, | ||
}; | ||
private videoReplayer: VideoReplayer; | ||
private replayer: Replayer; | ||
|
||
constructor({ | ||
videoEvents, | ||
events, | ||
root, | ||
start, | ||
videoApiPrefix, | ||
onBuffer, | ||
onFinished, | ||
onLoaded, | ||
clipWindow, | ||
durationMs, | ||
theme, | ||
}: VideoReplayerWithInteractionsOptions) { | ||
this.videoReplayer = new VideoReplayer(videoEvents, { | ||
videoApiPrefix, | ||
root, | ||
start, | ||
onFinished, | ||
onLoaded, | ||
onBuffer, | ||
clipWindow, | ||
durationMs, | ||
}); | ||
|
||
root?.classList.add('video-replayer'); | ||
|
||
const eventsWithSnapshots: eventWithTime[] = []; | ||
events.forEach(e => { | ||
eventsWithSnapshots.push(e); | ||
if (e.type === 4) { | ||
// Create a mock full snapshot event, in order to render rrweb gestures properly | ||
// Need to add one for every meta event we see | ||
// The hardcoded data.node.id here should match the ID of the data being sent | ||
// in the `positions` arrays | ||
const fullSnapshotEvent = { | ||
type: 2, | ||
data: { | ||
node: { | ||
type: 0, | ||
childNodes: [ | ||
{ | ||
type: 1, | ||
name: 'html', | ||
publicId: '', | ||
systemId: '', | ||
}, | ||
{ | ||
type: 2, | ||
tagName: 'html', | ||
attributes: { | ||
lang: 'en', | ||
}, | ||
childNodes: [], | ||
}, | ||
], | ||
id: 0, | ||
}, | ||
}, | ||
timestamp: e.timestamp, | ||
}; | ||
eventsWithSnapshots.push(fullSnapshotEvent); | ||
} | ||
}); | ||
|
||
this.replayer = new Replayer(eventsWithSnapshots, { | ||
root: root as Element, | ||
blockClass: 'sentry-block', | ||
mouseTail: { | ||
duration: 0.75 * 1000, | ||
lineCap: 'round', | ||
lineWidth: 2, | ||
strokeStyle: theme.purple200, | ||
}, | ||
plugins: [], | ||
skipInactive: false, | ||
speed: this.config.speed, | ||
}); | ||
} | ||
|
||
public destroy() { | ||
this.videoReplayer.destroy(); | ||
this.replayer.destroy(); | ||
} | ||
|
||
/** | ||
* Returns the current video time, using the video's external timer. | ||
*/ | ||
public getCurrentTime() { | ||
return this.videoReplayer.getCurrentTime(); | ||
} | ||
|
||
/** | ||
* Play both the rrweb and video player. | ||
*/ | ||
public play(videoOffsetMs: number) { | ||
this.videoReplayer.play(videoOffsetMs); | ||
this.replayer.play(videoOffsetMs); | ||
} | ||
|
||
/** | ||
* Pause both the rrweb and video player. | ||
*/ | ||
public pause(videoOffsetMs: number) { | ||
this.videoReplayer.pause(videoOffsetMs); | ||
this.replayer.pause(videoOffsetMs); | ||
} | ||
|
||
/** | ||
* Equivalent to rrweb's `setConfig()`, but here we only support the `speed` configuration. | ||
*/ | ||
public setConfig(config: Partial<VideoReplayerConfig>): void { | ||
this.videoReplayer.setConfig(config); | ||
this.replayer.setConfig(config); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.