diff --git a/src/replay/index.ts b/src/replay/index.ts index 581e6075..d027e9ab 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -40,6 +40,8 @@ const defaultConfig: playerConfig = { export class Replayer { public wrapper: HTMLDivElement; + public timer: Timer; + private events: eventWithTime[] = []; private config: playerConfig = defaultConfig; @@ -55,8 +57,6 @@ export class Replayer { private nextUserInteractionEvent: eventWithTime | null; private noramlSpeed: number; - private timer: Timer; - private missingNodeRetryMap: missingNodeMap = {}; constructor(events: eventWithTime[], config?: Partial) { @@ -90,6 +90,10 @@ export class Replayer { }; } + public getTimeOffset(): number { + return this.baselineTime - this.events[0].timestamp; + } + /** * This API was designed to be used as play at any time offset. * Since we minimized the data collected from recorder, we do not diff --git a/src/replay/timer.ts b/src/replay/timer.ts index be4434d0..6dd7c3b3 100644 --- a/src/replay/timer.ts +++ b/src/replay/timer.ts @@ -1,6 +1,8 @@ import { playerConfig, actionWithDelay } from '../types'; export default class Timer { + public timeOffset: number = 0; + private actions: actionWithDelay[]; private config: playerConfig; private raf: number; @@ -27,16 +29,16 @@ export default class Timer { public start() { this.actions.sort((a1, a2) => a1.delay - a2.delay); - let delayed = 0; + this.timeOffset = 0; let lastTimestamp = performance.now(); const { actions, config } = this; const self = this; function check(time: number) { - delayed += (time - lastTimestamp) * config.speed; + self.timeOffset += (time - lastTimestamp) * config.speed; lastTimestamp = time; while (actions.length) { const action = actions[0]; - if (delayed >= action.delay) { + if (self.timeOffset >= action.delay) { actions.shift(); action.doAction(); } else {