export timer to public API
This commit is contained in:
@@ -40,6 +40,8 @@ const defaultConfig: playerConfig = {
|
|||||||
export class Replayer {
|
export class Replayer {
|
||||||
public wrapper: HTMLDivElement;
|
public wrapper: HTMLDivElement;
|
||||||
|
|
||||||
|
public timer: Timer;
|
||||||
|
|
||||||
private events: eventWithTime[] = [];
|
private events: eventWithTime[] = [];
|
||||||
private config: playerConfig = defaultConfig;
|
private config: playerConfig = defaultConfig;
|
||||||
|
|
||||||
@@ -55,8 +57,6 @@ export class Replayer {
|
|||||||
private nextUserInteractionEvent: eventWithTime | null;
|
private nextUserInteractionEvent: eventWithTime | null;
|
||||||
private noramlSpeed: number;
|
private noramlSpeed: number;
|
||||||
|
|
||||||
private timer: Timer;
|
|
||||||
|
|
||||||
private missingNodeRetryMap: missingNodeMap = {};
|
private missingNodeRetryMap: missingNodeMap = {};
|
||||||
|
|
||||||
constructor(events: eventWithTime[], config?: Partial<playerConfig>) {
|
constructor(events: eventWithTime[], config?: Partial<playerConfig>) {
|
||||||
@@ -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.
|
* This API was designed to be used as play at any time offset.
|
||||||
* Since we minimized the data collected from recorder, we do not
|
* Since we minimized the data collected from recorder, we do not
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { playerConfig, actionWithDelay } from '../types';
|
import { playerConfig, actionWithDelay } from '../types';
|
||||||
|
|
||||||
export default class Timer {
|
export default class Timer {
|
||||||
|
public timeOffset: number = 0;
|
||||||
|
|
||||||
private actions: actionWithDelay[];
|
private actions: actionWithDelay[];
|
||||||
private config: playerConfig;
|
private config: playerConfig;
|
||||||
private raf: number;
|
private raf: number;
|
||||||
@@ -27,16 +29,16 @@ export default class Timer {
|
|||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
this.actions.sort((a1, a2) => a1.delay - a2.delay);
|
this.actions.sort((a1, a2) => a1.delay - a2.delay);
|
||||||
let delayed = 0;
|
this.timeOffset = 0;
|
||||||
let lastTimestamp = performance.now();
|
let lastTimestamp = performance.now();
|
||||||
const { actions, config } = this;
|
const { actions, config } = this;
|
||||||
const self = this;
|
const self = this;
|
||||||
function check(time: number) {
|
function check(time: number) {
|
||||||
delayed += (time - lastTimestamp) * config.speed;
|
self.timeOffset += (time - lastTimestamp) * config.speed;
|
||||||
lastTimestamp = time;
|
lastTimestamp = time;
|
||||||
while (actions.length) {
|
while (actions.length) {
|
||||||
const action = actions[0];
|
const action = actions[0];
|
||||||
if (delayed >= action.delay) {
|
if (self.timeOffset >= action.delay) {
|
||||||
actions.shift();
|
actions.shift();
|
||||||
action.doAction();
|
action.doAction();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user