Skip to content

Commit 18099c1

Browse files
committed
convert to fn
1 parent 0717515 commit 18099c1

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

packages/replay-canvas/src/canvas.ts

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CanvasManager } from '@sentry-internal/rrweb';
2+
import { convertIntegrationFnToClass } from '@sentry/core';
23
import type { CanvasManagerInterface } from '@sentry/replay';
3-
import type { Integration } from '@sentry/types';
4+
import { IntegrationFn } from '@sentry/types';
45

56
interface ReplayCanvasOptions {
67
quality: 'low' | 'medium' | 'high';
@@ -48,43 +49,28 @@ const CANVAS_QUALITY = {
4849
},
4950
};
5051

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';
5753

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+
};
7161

72-
/** @inheritdoc */
73-
public setupOnce(): void {
74-
// noop
75-
}
62+
return {
63+
name: INTEGRATION_NAME,
64+
getOptions(): ReplayCanvasIntegrationOptions {
65+
const { quality } = _canvasOptions;
7666

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;
8375

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

Comments
 (0)