Skip to content

Commit f23b119

Browse files
authored
Missed an edge case where the last part of a session is inactive, and counted that as active. (#24)
* Added support for inactive threshold * Updated version num * Prettified * Fixed names * Fixed name * Renamed * Cleaned code and added handling for edge cases * Updated package num
1 parent 67a42ec commit f23b119

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@highlight-run/rrweb",
3-
"version": "0.9.25",
3+
"version": "0.9.26",
44
"description": "record and replay the web",
55
"scripts": {
66
"test": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register test/**/*.test.ts",

src/replay/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export class Replayer {
102102
private emitter: Emitter = mitt();
103103

104104
private inactiveEndTimestamp: number | null;
105-
private nextUserInteractionEvent: eventWithTime | null;
106105

107106
// tslint:disable-next-line: variable-name
108107
private legacy_missingNodeRetryMap: missingNodeMap = {};
@@ -247,17 +246,21 @@ export class Replayer {
247246
}
248247
// Preprocessing to get all active/inactive segments in a session
249248
const allIntervals: Array<SessionInterval> = [];
250-
const firstEvent = this.service.state.context.events[0];
249+
const metadata = this.getMetaData();
251250
const userInteractionEvents = [
252-
firstEvent,
251+
{ timestamp: metadata.startTime },
253252
...this.service.state.context.events.filter((ev) =>
254253
this.isUserInteraction(ev),
255254
),
255+
{ timestamp: metadata.endTime },
256256
];
257257
for (let i = 1; i < userInteractionEvents.length; i++) {
258258
const currentInterval = userInteractionEvents[i - 1];
259259
const _event = userInteractionEvents[i];
260-
if (_event.timestamp! - currentInterval.timestamp! > SKIP_TIME_THRESHOLD) {
260+
if (
261+
_event.timestamp! - currentInterval.timestamp! >
262+
SKIP_TIME_THRESHOLD
263+
) {
261264
allIntervals.push({
262265
startTime: currentInterval.timestamp!,
263266
endTime: _event.timestamp!,
@@ -292,13 +295,13 @@ export class Replayer {
292295
startTime: currentInterval.startTime,
293296
endTime: allIntervals[allIntervals.length - 1].endTime,
294297
duration:
295-
allIntervals[allIntervals.length - 1].endTime - currentInterval.startTime,
298+
allIntervals[allIntervals.length - 1].endTime -
299+
currentInterval.startTime,
296300
active: allIntervals[allIntervals.length - 1].active,
297301
});
298302
}
299303
// Merges inactive segments that are less than a threshold into surrounding active sessions
300304
// TODO: Change this from a 3n pass to n
301-
const metadata = this.getMetaData();
302305
currentInterval = mergedIntervals[0];
303306
for (let i = 1; i < mergedIntervals.length; i++) {
304307
if (
@@ -1447,7 +1450,7 @@ export class Replayer {
14471450
}
14481451

14491452
private backToNormal() {
1450-
this.nextUserInteractionEvent = null;
1453+
this.inactiveEndTimestamp = null;
14511454
if (this.speedService.state.matches('normal')) {
14521455
return;
14531456
}

0 commit comments

Comments
 (0)