start to support live mode (#73)
1. add a liveMode flag to config, when liveMode is set, the timer will keep running even though all the actions casted 2. add a public method addEvent, which will cast newly added event in sync 3. move mouse in sync mode with the latest position info
This commit is contained in:
@@ -69,6 +69,7 @@ export class Replayer {
|
|||||||
showWarning: true,
|
showWarning: true,
|
||||||
showDebug: false,
|
showDebug: false,
|
||||||
blockClass: 'rr-block',
|
blockClass: 'rr-block',
|
||||||
|
liveMode: false,
|
||||||
};
|
};
|
||||||
this.config = Object.assign({}, defaultConfig, config);
|
this.config = Object.assign({}, defaultConfig, config);
|
||||||
|
|
||||||
@@ -157,6 +158,11 @@ export class Replayer {
|
|||||||
this.emitter.emit(ReplayerEvents.Resume);
|
this.emitter.emit(ReplayerEvents.Resume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addEvent(event: eventWithTime) {
|
||||||
|
const castFn = this.getCastFn(event, true);
|
||||||
|
castFn();
|
||||||
|
}
|
||||||
|
|
||||||
private setupDom() {
|
private setupDom() {
|
||||||
this.wrapper = document.createElement('div');
|
this.wrapper = document.createElement('div');
|
||||||
this.wrapper.classList.add('replayer-wrapper');
|
this.wrapper.classList.add('replayer-wrapper');
|
||||||
@@ -424,8 +430,10 @@ export class Replayer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IncrementalSource.MouseMove:
|
case IncrementalSource.MouseMove:
|
||||||
// skip mouse move in sync mode
|
if (isSync) {
|
||||||
if (!isSync) {
|
const lastPosition = d.positions[d.positions.length - 1];
|
||||||
|
this.moveAndHover(d, lastPosition.x, lastPosition.y, lastPosition.id);
|
||||||
|
} else {
|
||||||
d.positions.forEach(p => {
|
d.positions.forEach(p => {
|
||||||
const action = {
|
const action = {
|
||||||
doAction: () => {
|
doAction: () => {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export default class Timer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (actions.length > 0) {
|
if (actions.length > 0 || self.config.liveMode) {
|
||||||
self.raf = requestAnimationFrame(check);
|
self.raf = requestAnimationFrame(check);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,6 +241,7 @@ export type playerConfig = {
|
|||||||
showWarning: boolean;
|
showWarning: boolean;
|
||||||
showDebug: boolean;
|
showDebug: boolean;
|
||||||
blockClass: string;
|
blockClass: string;
|
||||||
|
liveMode: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type playerMetaData = {
|
export type playerMetaData = {
|
||||||
|
|||||||
1
typings/replay/index.d.ts
vendored
1
typings/replay/index.d.ts
vendored
@@ -22,6 +22,7 @@ export declare class Replayer {
|
|||||||
play(timeOffset?: number): void;
|
play(timeOffset?: number): void;
|
||||||
pause(): void;
|
pause(): void;
|
||||||
resume(timeOffset?: number): void;
|
resume(timeOffset?: number): void;
|
||||||
|
addEvent(event: eventWithTime): void;
|
||||||
private setupDom;
|
private setupDom;
|
||||||
private handleResize;
|
private handleResize;
|
||||||
private getDelay;
|
private getDelay;
|
||||||
|
|||||||
1
typings/types.d.ts
vendored
1
typings/types.d.ts
vendored
@@ -192,6 +192,7 @@ export declare type playerConfig = {
|
|||||||
showWarning: boolean;
|
showWarning: boolean;
|
||||||
showDebug: boolean;
|
showDebug: boolean;
|
||||||
blockClass: string;
|
blockClass: string;
|
||||||
|
liveMode: boolean;
|
||||||
};
|
};
|
||||||
export declare type playerMetaData = {
|
export declare type playerMetaData = {
|
||||||
totalTime: number;
|
totalTime: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user