Skip to content

Commit

Permalink
feat(session replay): adding timeout into config
Browse files Browse the repository at this point in the history
  • Loading branch information
jxiwang committed Sep 24, 2024
1 parent ecde7f2 commit fd67792
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface SessionReplayPrivacyConfig {

export interface SessionReplayPerformanceConfig {
enabled: boolean;
timeout?: number;
}

export interface SessionReplayOptions {
Expand Down
1 change: 1 addition & 0 deletions packages/session-replay-browser/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface SessionReplayVersion {

export interface SessionReplayPerformanceConfig {
enabled: boolean;
timeout?: number;
}

export type SessionReplayType = 'standalone' | 'plugin' | 'segment';
11 changes: 7 additions & 4 deletions packages/session-replay-browser/src/events/event-compressor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ interface TaskQueue {
sessionId: number;
}

const DEFAULT_TIMEOUT = 2000;
export class EventCompressor {
taskQueue: TaskQueue[] = [];
isProcessing = false;
eventsManager?: SessionReplayEventsManager<'replay' | 'interaction', string>;
config: SessionReplayJoinedConfig;
deviceId: string | undefined;
canUseIdleCallback: boolean | undefined;
timeout: number;

constructor(
eventsManager: SessionReplayEventsManager<'replay' | 'interaction', string>,
Expand All @@ -27,6 +29,7 @@ export class EventCompressor {
this.eventsManager = eventsManager;
this.config = config;
this.deviceId = deviceId;
this.timeout = config.performanceConfig?.timeout || DEFAULT_TIMEOUT;
}

// Schedule processing during idle time
Expand All @@ -37,7 +40,7 @@ export class EventCompressor {
(idleDeadline) => {
this.processQueue(idleDeadline);
},
{ timeout: 2000 },
{ timeout: this.timeout },
);
}
}
Expand Down Expand Up @@ -69,20 +72,20 @@ export class EventCompressor {
(idleDeadline) => {
this.processQueue(idleDeadline);
},
{ timeout: 2000 },
{ timeout: this.timeout },
);
} else {
this.isProcessing = false;
}
}

compressEvents = (event: eventWithTime) => {
compressEvent = (event: eventWithTime) => {
const packedEvent = pack(event);
return JSON.stringify(packedEvent);
};

public addCompressedEvent = (event: eventWithTime, sessionId: number) => {
const compressedEvent = this.compressEvents(event);
const compressedEvent = this.compressEvent(event);

if (this.eventsManager && this.deviceId) {
this.eventsManager.addEvent({
Expand Down
1 change: 0 additions & 1 deletion packages/session-replay-browser/src/session-replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ export class SessionReplay implements AmplitudeSessionReplay {
recordEvents() {
const shouldRecord = this.getShouldRecord();
const sessionId = this.identifiers?.sessionId;
// const canDelayCompression = globalScope && 'requestIdleCallback' in globalScope;
if (!shouldRecord || !sessionId || !this.config) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('EventCompressor', () => {
sampleRate: 1,
performanceConfig: {
enabled: true,
timeout: 2000,
},
});

Expand Down

0 comments on commit fd67792

Please sign in to comment.