diff --git a/src/replay/index.ts b/src/replay/index.ts index 7af8bf63..fc5dddd1 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -129,8 +129,6 @@ export class Replayer { events: Array, config?: Partial, ) { - events.sort((a1, a2) => a1.timestamp - a2.timestamp); - if (!config?.liveMode && events.length < 2) { throw new Error('Replayer need at least 2 events.'); } @@ -199,12 +197,14 @@ export class Replayer { const timer = new Timer([], config?.speed || defaultConfig.speed); this.service = createPlayerService( { - events: events.map((e) => { - if (config && config.unpackFn) { - return config.unpackFn(e as string); - } - return e as eventWithTime; - }), + events: events + .map((e) => { + if (config && config.unpackFn) { + return config.unpackFn(e as string); + } + return e as eventWithTime; + }) + .sort((a1, a2) => a1.timestamp - a2.timestamp), timer, timeOffset: 0, baselineTime: 0, diff --git a/src/replay/machine.ts b/src/replay/machine.ts index d2e3313f..61dbb58b 100644 --- a/src/replay/machine.ts +++ b/src/replay/machine.ts @@ -243,7 +243,7 @@ export function createPlayerService( // fast track events.push(event); } else { - let insertion_index = -1; + let insertionIndex = -1; let start = 0; while (start <= end) { let mid = Math.floor((start + end) / 2); @@ -253,13 +253,12 @@ export function createPlayerService( end = mid - 1; } } - if (insertion_index === -1) { - insertion_index = start; + if (insertionIndex === -1) { + insertionIndex = start; } - events.splice(insertion_index, 0, event); + events.splice(insertionIndex, 0, event); } - const isSync = event.timestamp < baselineTime; const castFn = getCastFn(event, isSync); if (isSync) {