Skip to content

Commit 0e37dbd

Browse files
address pr comments
1 parent 674d931 commit 0e37dbd

File tree

3 files changed

+64
-69
lines changed

3 files changed

+64
-69
lines changed

static/app/components/replays/replayContext.tsx

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
ReplayPrefs,
1616
} from 'sentry/components/replays/preferences/replayPreferences';
1717
import useReplayHighlighting from 'sentry/components/replays/useReplayHighlighting';
18-
import {WrapperReplayer} from 'sentry/components/replays/wrapperReplayer';
18+
import {VideoReplayerWithInteractions} from 'sentry/components/replays/videoReplayerWithInteractions';
1919
import {trackAnalytics} from 'sentry/utils/analytics';
2020
import clamp from 'sentry/utils/number/clamp';
2121
import type useInitialOffsetMs from 'sentry/utils/replays/hooks/useInitialTimeOffsetMs';
@@ -481,36 +481,35 @@ function ProviderNonMemo({
481481

482482
// This is a wrapper class that wraps both the VideoReplayer
483483
// and the rrweb Replayer
484-
const inst = new WrapperReplayer(
485-
{videoEvents, events: events ?? []},
486-
{
487-
// video specific
488-
videoApiPrefix: `/api/0/projects/${
489-
organization.slug
490-
}/${projectSlug}/replays/${replay?.getReplay().id}/videos/`,
491-
start: startTimestampMs,
492-
onFinished: setReplayFinished,
493-
onLoaded: event => {
494-
const {videoHeight, videoWidth} = event.target;
495-
if (!videoHeight || !videoWidth) {
496-
return;
497-
}
498-
setDimensions({
499-
height: videoHeight,
500-
width: videoWidth,
501-
});
502-
},
503-
onBuffer: buffering => {
504-
setVideoBuffering(buffering);
505-
},
506-
clipWindow,
507-
durationMs,
508-
// rrweb specific
509-
theme,
510-
// common to both
511-
root,
512-
}
513-
);
484+
const inst = new VideoReplayerWithInteractions({
485+
// video specific
486+
videoEvents,
487+
videoApiPrefix: `/api/0/projects/${
488+
organization.slug
489+
}/${projectSlug}/replays/${replay?.getReplay().id}/videos/`,
490+
start: startTimestampMs,
491+
onFinished: setReplayFinished,
492+
onLoaded: event => {
493+
const {videoHeight, videoWidth} = event.target;
494+
if (!videoHeight || !videoWidth) {
495+
return;
496+
}
497+
setDimensions({
498+
height: videoHeight,
499+
width: videoWidth,
500+
});
501+
},
502+
onBuffer: buffering => {
503+
setVideoBuffering(buffering);
504+
},
505+
clipWindow,
506+
durationMs,
507+
// rrweb specific
508+
theme,
509+
events: events ?? [],
510+
// common to both
511+
root,
512+
});
514513
// `.current` is marked as readonly, but it's safe to set the value from
515514
// inside a `useEffect` hook.
516515
// See: https://reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables

static/app/components/replays/replayPlayer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ const SentryPlayerRoot = styled(PlayerRoot)`
283283
}
284284
}
285285
286+
/* Correctly positions the canvas for video replays and show the purple "mousetails" */
286287
&.video-replayer {
287288
.replayer-wrapper {
288289
position: absolute;

static/app/components/replays/wrapperReplayer.tsx renamed to static/app/components/replays/videoReplayerWithInteractions.tsx

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,47 @@ import type {ClipWindow, VideoEvent} from 'sentry/utils/replays/types';
99

1010
type RootElem = HTMLDivElement | null;
1111

12-
interface WrapperReplayerOptions {
12+
interface VideoReplayerWithInteractionsOptions {
1313
durationMs: number;
14+
events: eventWithTime[];
1415
onBuffer: (isBuffering: boolean) => void;
1516
onFinished: () => void;
1617
onLoaded: (event: any) => void;
1718
root: RootElem;
1819
start: number;
1920
theme: Theme;
2021
videoApiPrefix: string;
22+
videoEvents: VideoEvent[];
2123
clipWindow?: ClipWindow;
2224
}
2325

2426
/**
2527
* A wrapper replayer that wraps both VideoReplayer and the rrweb Replayer.
2628
* We need both instances in order to render the video playback alongside gestures.
2729
*/
28-
export class WrapperReplayer {
30+
export class VideoReplayerWithInteractions {
2931
public config: VideoReplayerConfig = {
3032
skipInactive: false,
3133
speed: 1.0,
3234
};
3335
public iframe = {};
34-
public videoInst: VideoReplayer;
35-
public rrwebInst: Replayer;
36+
public videoReplayer: VideoReplayer;
37+
public replayer: Replayer;
3638

37-
constructor(
38-
{videoEvents, events}: {events: eventWithTime[]; videoEvents: VideoEvent[]},
39-
{
40-
root,
41-
start,
42-
videoApiPrefix,
43-
onBuffer,
44-
onFinished,
45-
onLoaded,
46-
clipWindow,
47-
durationMs,
48-
theme,
49-
}: WrapperReplayerOptions
50-
) {
51-
this.videoInst = new VideoReplayer(videoEvents, {
39+
constructor({
40+
videoEvents,
41+
events,
42+
root,
43+
start,
44+
videoApiPrefix,
45+
onBuffer,
46+
onFinished,
47+
onLoaded,
48+
clipWindow,
49+
durationMs,
50+
theme,
51+
}: VideoReplayerWithInteractionsOptions) {
52+
this.videoReplayer = new VideoReplayer(videoEvents, {
5253
videoApiPrefix,
5354
root,
5455
start,
@@ -61,9 +62,9 @@ export class WrapperReplayer {
6162

6263
root?.classList.add('video-replayer');
6364

64-
const modifiedEvents: eventWithTime[] = [];
65+
const eventsWithSnapshots: eventWithTime[] = [];
6566
events.forEach((e, idx) => {
66-
modifiedEvents.push(e);
67+
eventsWithSnapshots.push(e);
6768
if (e.type === 4) {
6869
// Create a mock full snapshot event, in order to render rrweb gestures properly
6970
// Need to add one for every meta event we see
@@ -80,7 +81,6 @@ export class WrapperReplayer {
8081
name: 'html',
8182
publicId: '',
8283
systemId: '',
83-
id: 0,
8484
},
8585
{
8686
type: 2,
@@ -89,23 +89,18 @@ export class WrapperReplayer {
8989
lang: 'en',
9090
},
9191
childNodes: [],
92-
id: 0,
9392
},
9493
],
9594
id: 0,
9695
},
97-
initialOffset: {
98-
left: 0,
99-
top: 0,
100-
},
10196
},
10297
timestamp: events[idx].timestamp,
10398
};
104-
modifiedEvents.push(fullSnapshotEvent);
99+
eventsWithSnapshots.push(fullSnapshotEvent);
105100
}
106101
});
107102

108-
this.rrwebInst = new Replayer(modifiedEvents, {
103+
this.replayer = new Replayer(eventsWithSnapshots, {
109104
root: root as Element,
110105
blockClass: 'sentry-block',
111106
mouseTail: {
@@ -121,38 +116,38 @@ export class WrapperReplayer {
121116
}
122117

123118
public destroy() {
124-
this.videoInst.destroy();
125-
this.rrwebInst.destroy();
119+
this.videoReplayer.destroy();
120+
this.replayer.destroy();
126121
}
127122

128123
/**
129124
* Returns the current video time, using the video's external timer.
130125
*/
131126
public getCurrentTime() {
132-
return this.videoInst.getCurrentTime();
127+
return this.videoReplayer.getCurrentTime();
133128
}
134129

135130
/**
136131
* Play both the rrweb and video player.
137132
*/
138133
public play(videoOffsetMs: number) {
139-
this.videoInst.play(videoOffsetMs);
140-
this.rrwebInst.play(videoOffsetMs);
134+
this.videoReplayer.play(videoOffsetMs);
135+
this.replayer.play(videoOffsetMs);
141136
}
142137

143138
/**
144139
* Pause both the rrweb and video player.
145140
*/
146141
public pause(videoOffsetMs: number) {
147-
this.videoInst.pause(videoOffsetMs);
148-
this.rrwebInst.pause(videoOffsetMs);
142+
this.videoReplayer.pause(videoOffsetMs);
143+
this.replayer.pause(videoOffsetMs);
149144
}
150145

151146
/**
152147
* Equivalent to rrweb's `setConfig()`, but here we only support the `speed` configuration.
153148
*/
154149
public setConfig(config: Partial<VideoReplayerConfig>): void {
155-
this.videoInst.setConfig(config);
156-
this.rrwebInst.setConfig(config);
150+
this.videoReplayer.setConfig(config);
151+
this.replayer.setConfig(config);
157152
}
158153
}

0 commit comments

Comments
 (0)