export timer to public API
This commit is contained in:
@@ -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<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.
|
||||
* Since we minimized the data collected from recorder, we do not
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user