Skip to content

Commit 7bf2be5

Browse files
mydeac298lee
authored andcommitted
feat(replay): Add ReplayCanvas integration
Adding this integration in addition to `Replay` will set up canvas recording.
1 parent 687d827 commit 7bf2be5

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

packages/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const INTEGRATIONS = {
2020

2121
export { INTEGRATIONS as Integrations };
2222

23-
export { Replay } from '@sentry/replay';
23+
export { Replay, ReplayCanvas } from '@sentry/replay';
2424
export type {
2525
ReplayEventType,
2626
ReplayEventWithTime,

packages/replay/rollup.bundle.config.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const baseBundleConfig = makeBaseBundleConfig({
88
outputFileBase: () => 'bundles/replay',
99
});
1010

11-
const builds = makeBundleConfigVariants(baseBundleConfig);
11+
const baseCanvasBundleConfig = makeBaseBundleConfig({
12+
bundleType: 'addon',
13+
entrypoints: ['src/canvas.ts'],
14+
jsVersion: 'es6',
15+
licenseTitle: '@sentry/replaycanvas',
16+
outputFileBase: () => 'bundles/replaycanvas',
17+
});
18+
19+
const builds = [...makeBundleConfigVariants(baseBundleConfig), ...makeBundleConfigVariants(baseCanvasBundleConfig)];
1220

1321
export default builds;

packages/replay/src/canvas.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { getCanvasManager } from '@sentry-internal/rrweb';
2+
import type { Integration } from '@sentry/types';
3+
import type { ReplayConfiguration } from './types';
4+
5+
interface ReplayCanvasOptions {
6+
fps: number;
7+
quality: number;
8+
}
9+
10+
/** An integration to add canvas recording to replay. */
11+
export class ReplayCanvas implements Integration {
12+
/**
13+
* @inheritDoc
14+
*/
15+
public static id: string = 'ReplayCanvas';
16+
17+
/**
18+
* @inheritDoc
19+
*/
20+
public name: string;
21+
22+
private _canvasOptions: ReplayCanvasOptions;
23+
24+
public constructor() {
25+
this.name = ReplayCanvas.id;
26+
// TODO FN: Allow to configure this
27+
// But since we haven't finalized how to configure this, this is predefined for now
28+
// to avoid breaking changes
29+
this._canvasOptions = {
30+
fps: 4,
31+
quality: 0.6,
32+
};
33+
}
34+
35+
/** @inheritdoc */
36+
public setupOnce(): void {
37+
// noop
38+
}
39+
40+
/**
41+
* Get the options that should be merged into replay options.
42+
* This is what is actually called by the Replay integration to setup canvas.
43+
*/
44+
public getOptions(): Partial<ReplayConfiguration> {
45+
return {
46+
_experiments: {
47+
canvas: {
48+
...this._canvasOptions,
49+
manager: getCanvasManager,
50+
},
51+
},
52+
};
53+
}
54+
}

packages/replay/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { Replay } from './integration';
2+
export { ReplayCanvas } from './canvas';
23

34
export type {
45
ReplayConfiguration,

0 commit comments

Comments
 (0)