|
1 | 1 | import { CanvasManager } from '@sentry-internal/rrweb';
|
| 2 | +import { convertIntegrationFnToClass } from '@sentry/core'; |
2 | 3 | import type { CanvasManagerInterface } from '@sentry/replay';
|
3 |
| -import type { Integration } from '@sentry/types'; |
| 4 | +import { IntegrationFn } from '@sentry/types'; |
4 | 5 |
|
5 | 6 | interface ReplayCanvasOptions {
|
6 | 7 | quality: 'low' | 'medium' | 'high';
|
@@ -48,43 +49,28 @@ const CANVAS_QUALITY = {
|
48 | 49 | },
|
49 | 50 | };
|
50 | 51 |
|
51 |
| -/** An integration to add canvas recording to replay. */ |
52 |
| -export class ReplayCanvas implements Integration { |
53 |
| - /** |
54 |
| - * @inheritDoc |
55 |
| - */ |
56 |
| - public static id: string = 'ReplayCanvas'; |
| 52 | +const INTEGRATION_NAME = 'ReplayCanvas'; |
57 | 53 |
|
58 |
| - /** |
59 |
| - * @inheritDoc |
60 |
| - */ |
61 |
| - public name: string; |
62 |
| - |
63 |
| - private _canvasOptions: ReplayCanvasOptions; |
64 |
| - |
65 |
| - public constructor(options: Partial<ReplayCanvasOptions> = {}) { |
66 |
| - this.name = ReplayCanvas.id; |
67 |
| - this._canvasOptions = { |
68 |
| - quality: options.quality || 'medium', |
69 |
| - }; |
70 |
| - } |
| 54 | +/** |
| 55 | + * An integration to add canvas recording to replay. |
| 56 | + */ |
| 57 | +const replayCanvasIntegration = ((options: Partial<ReplayCanvasOptions> = {}) => { |
| 58 | + const _canvasOptions = { |
| 59 | + quality: options.quality || 'medium', |
| 60 | + }; |
71 | 61 |
|
72 |
| - /** @inheritdoc */ |
73 |
| - public setupOnce(): void { |
74 |
| - // noop |
75 |
| - } |
| 62 | + return { |
| 63 | + name: INTEGRATION_NAME, |
| 64 | + getOptions(): ReplayCanvasIntegrationOptions { |
| 65 | + const { quality } = _canvasOptions; |
76 | 66 |
|
77 |
| - /** |
78 |
| - * Get the options that should be merged into replay options. |
79 |
| - * This is what is actually called by the Replay integration to setup canvas. |
80 |
| - */ |
81 |
| - public getOptions(): ReplayCanvasIntegrationOptions { |
82 |
| - const { quality } = this._canvasOptions; |
| 67 | + return { |
| 68 | + recordCanvas: true, |
| 69 | + getCanvasManager: (options: ConstructorParameters<typeof CanvasManager>[0]) => new CanvasManager(options), |
| 70 | + ...(CANVAS_QUALITY[quality || 'medium'] || CANVAS_QUALITY.medium), |
| 71 | + }; |
| 72 | + } |
| 73 | + }; |
| 74 | +}) satisfies IntegrationFn; |
83 | 75 |
|
84 |
| - return { |
85 |
| - recordCanvas: true, |
86 |
| - getCanvasManager: (options: ConstructorParameters<typeof CanvasManager>[0]) => new CanvasManager(options), |
87 |
| - ...(CANVAS_QUALITY[quality || 'medium'] || CANVAS_QUALITY.medium), |
88 |
| - }; |
89 |
| - } |
90 |
| -} |
| 76 | +export const ReplayCanvasIntegration = convertIntegrationFnToClass(replayCanvasIntegration, INTEGRATION_NAME); |
0 commit comments