Skip to content

Commit 729361e

Browse files
authored
Expose constant SKIP_TIME_THRESHOLD as inactivePeriodThreshold in replayer (#1408)
Expose constant SKIP_TIME_THRESHOLD as `inactivePeriodThreshold` config setting in replayer
1 parent 02f50d2 commit 729361e

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ The replayer accepts options as its constructor's second parameter, and it has t
301301
| root | document.body | the root element of replayer |
302302
| loadTimeout | 0 | timeout of loading remote style sheet |
303303
| skipInactive | false | whether to skip inactive time |
304+
| inactivePeriodThreshold | 10000 | the threshold in milliseconds for what should be considered an inactive period |
304305
| showWarning | true | whether to print warning messages during replay |
305306
| showDebug | false | whether to print debug messages during replay |
306307
| blockClass | 'rr-block' | element with the class name will display as a blocked area |

packages/rrweb-player/src/Controller.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
const totalEvents = context.events.length;
115115
const start = context.events[0].timestamp;
116116
const end = context.events[totalEvents - 1].timestamp;
117-
const periods = getInactivePeriods(context.events);
117+
const periods = getInactivePeriods(context.events, replayer.config.inactivePeriodThreshold);
118118
// calculate the indicator width.
119119
const getWidth = (
120120
startTime: number,

packages/rrweb-player/src/utils.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,18 @@ function isUserInteraction(event: eventWithTime): boolean {
161161
);
162162
}
163163

164-
// Forked from 'rrweb' replay/index.ts. A const threshold of inactive time.
165-
const SKIP_TIME_THRESHOLD = 10 * 1000;
166-
167164
/**
168165
* Get periods of time when no user interaction happened from a list of events.
169166
* @param events - all events
167+
* @param inactivePeriodThreshold - threshold of inactive time in milliseconds
170168
* @returns periods of time consist with [start time, end time]
171169
*/
172-
export function getInactivePeriods(events: eventWithTime[]) {
170+
export function getInactivePeriods(events: eventWithTime[], inactivePeriodThreshold: number) {
173171
const inactivePeriods: [number, number][] = [];
174172
let lastActiveTime = events[0].timestamp;
175173
for (const event of events) {
176174
if (!isUserInteraction(event)) continue;
177-
if (event.timestamp - lastActiveTime > SKIP_TIME_THRESHOLD) {
175+
if (event.timestamp - lastActiveTime > inactivePeriodThreshold) {
178176
inactivePeriods.push([lastActiveTime, event.timestamp]);
179177
}
180178
lastActiveTime = event.timestamp;

packages/rrweb/src/replay/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ import './styles/style.css';
8282
import canvasMutation from './canvas';
8383
import { deserializeArg } from './canvas/deserialize-args';
8484

85-
const SKIP_TIME_THRESHOLD = 10 * 1000;
8685
const SKIP_TIME_INTERVAL = 5 * 1000;
8786

8887
// https://github.com/rollup/rollup/issues/1267#issuecomment-296395734
@@ -179,6 +178,7 @@ export class Replayer {
179178
root: document.body,
180179
loadTimeout: 0,
181180
skipInactive: false,
181+
inactivePeriodThreshold: 10 * 1000,
182182
showWarning: true,
183183
showDebug: false,
184184
blockClass: 'rr-block',
@@ -692,7 +692,7 @@ export class Replayer {
692692
if (
693693
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
694694
_event.delay! - event.delay! >
695-
SKIP_TIME_THRESHOLD *
695+
this.config.inactivePeriodThreshold *
696696
this.speedService.state.context.timer.speed
697697
) {
698698
this.nextUserInteractionEvent = _event;

packages/rrweb/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export type playerConfig = {
170170
root: Element;
171171
loadTimeout: number;
172172
skipInactive: boolean;
173+
inactivePeriodThreshold: number;
173174
showWarning: boolean;
174175
showDebug: boolean;
175176
blockClass: string;

0 commit comments

Comments
 (0)