Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider allevents for inactivity #31

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@highlight-run/rrweb",
"version": "0.10.0",
"version": "0.10.1",
"description": "record and replay the web",
"scripts": {
"test": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register test/**/*.test.ts",
Expand Down
47 changes: 28 additions & 19 deletions src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class Replayer {
logConfig: defaultLogConfig,
inactiveThreshold: 0.02,
inactiveSkipTime: SKIP_TIME_INTERVAL,
maxSkipSpeed: 360,
};
this.config = Object.assign({}, defaultConfig, config);
if (!this.config.logConfig.replayLogger)
Expand Down Expand Up @@ -292,16 +291,14 @@ export class Replayer {
// Preprocessing to get all active/inactive segments in a session
const allIntervals: Array<SessionInterval> = [];
const metadata = this.getMetaData();
const userInteractionEvents = [
const allEvents = [
{ timestamp: metadata.startTime },
...this.service.state.context.events.filter((ev) =>
this.isUserInteraction(ev),
),
...this.service.state.context.events,
{ timestamp: metadata.endTime },
];
for (let i = 1; i < userInteractionEvents.length; i++) {
const currentInterval = userInteractionEvents[i - 1];
const _event = userInteractionEvents[i];
for (let i = 1; i < allEvents.length; i++) {
const currentInterval = allEvents[i - 1];
const _event = allEvents[i];
if (
_event.timestamp! - currentInterval.timestamp! >
SKIP_TIME_THRESHOLD
Expand Down Expand Up @@ -531,19 +528,23 @@ export class Replayer {
* This will add more value to the custom event and allows the client to react for custom-event.
*/
this.emitter.emit(ReplayerEvents.CustomEvent, event);
this.handleInactivity(event.timestamp);
};
break;
case EventType.Meta:
castFn = () =>
castFn = () => {
this.emitter.emit(ReplayerEvents.Resize, {
width: event.data.width,
height: event.data.height,
});
this.handleInactivity(event.timestamp);
};
break;
case EventType.FullSnapshot:
castFn = () => {
this.rebuildFullSnapshot(event, isSync);
this.iframe.contentWindow!.scrollTo(event.data.initialOffset);
this.handleInactivity(event.timestamp);
};
break;
case EventType.IncrementalSnapshot:
Expand Down Expand Up @@ -594,7 +595,6 @@ export class Replayer {
private handleInactivity(timestamp: number, resetNext?: boolean) {
if (timestamp === this.inactiveEndTimestamp || resetNext) {
this.inactiveEndTimestamp = null;
this.backToNormal();
}
if (this.config.skipInactive && !this.inactiveEndTimestamp) {
for (const interval of this.getActivityIntervals()) {
Expand All @@ -608,15 +608,24 @@ export class Replayer {
}
}
if (this.inactiveEndTimestamp) {
const skipTime = this.inactiveEndTimestamp! - timestamp!;
const payload = {
speed: Math.min(
Math.round(skipTime / this.config.inactiveSkipTime),
this.config.maxSkipSpeed,
),
};
this.speedService.send({ type: 'FAST_FORWARD', payload });
this.emitter.emit(ReplayerEvents.SkipStart, payload);
const skipOffset =
this.inactiveEndTimestamp - this.getMetaData().startTime;
if (this.service.state.matches('paused')) {
this.service.send({
type: 'PLAY',
payload: { timeOffset: skipOffset },
});
} else {
this.service.send({ type: 'PAUSE' });
this.service.send({
type: 'PLAY',
payload: { timeOffset: skipOffset },
});
}
this.iframe.contentDocument
?.getElementsByTagName('html')[0]
.classList.remove('rrweb-paused');
this.emitter.emit(ReplayerEvents.Start);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ export type playerConfig = {
logConfig: LogReplayConfig;
inactiveThreshold: number;
inactiveSkipTime: number;
maxSkipSpeed: number;
};

export type LogReplayConfig = {
Expand Down