fix #535 add play-back event to reset mirror and replayer
This commit is contained in:
@@ -193,6 +193,10 @@ export class Replayer {
|
|||||||
this.applyInput(d);
|
this.applyInput(d);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.emitter.on(ReplayerEvents.PlayBack, () => {
|
||||||
|
this.firstPlayedEvent = null;
|
||||||
|
mirror.reset();
|
||||||
|
});
|
||||||
|
|
||||||
const timer = new Timer([], config?.speed || defaultConfig.speed);
|
const timer = new Timer([], config?.speed || defaultConfig.speed);
|
||||||
this.service = createPlayerService(
|
this.service = createPlayerService(
|
||||||
|
|||||||
@@ -173,17 +173,21 @@ export function createPlayerService(
|
|||||||
}
|
}
|
||||||
const neededEvents = discardPriorSnapshots(events, baselineTime);
|
const neededEvents = discardPriorSnapshots(events, baselineTime);
|
||||||
|
|
||||||
|
let lastPlayedTimestamp = lastPlayedEvent?.timestamp;
|
||||||
|
if (
|
||||||
|
lastPlayedEvent?.type === EventType.IncrementalSnapshot &&
|
||||||
|
lastPlayedEvent.data.source === IncrementalSource.MouseMove
|
||||||
|
) {
|
||||||
|
lastPlayedTimestamp =
|
||||||
|
lastPlayedEvent.timestamp +
|
||||||
|
lastPlayedEvent.data.positions[0]?.timeOffset;
|
||||||
|
}
|
||||||
|
if (baselineTime < (lastPlayedTimestamp || 0)) {
|
||||||
|
emitter.emit(ReplayerEvents.PlayBack);
|
||||||
|
}
|
||||||
|
|
||||||
const actions = new Array<actionWithDelay>();
|
const actions = new Array<actionWithDelay>();
|
||||||
for (const event of neededEvents) {
|
for (const event of neededEvents) {
|
||||||
let lastPlayedTimestamp = lastPlayedEvent?.timestamp;
|
|
||||||
if (
|
|
||||||
lastPlayedEvent?.type === EventType.IncrementalSnapshot &&
|
|
||||||
lastPlayedEvent.data.source === IncrementalSource.MouseMove
|
|
||||||
) {
|
|
||||||
lastPlayedTimestamp =
|
|
||||||
lastPlayedEvent.timestamp +
|
|
||||||
lastPlayedEvent.data.positions[0]?.timeOffset;
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
lastPlayedTimestamp &&
|
lastPlayedTimestamp &&
|
||||||
lastPlayedTimestamp < baselineTime &&
|
lastPlayedTimestamp < baselineTime &&
|
||||||
|
|||||||
@@ -489,6 +489,7 @@ export type Mirror = {
|
|||||||
getNode: (id: number) => INode | null;
|
getNode: (id: number) => INode | null;
|
||||||
removeNodeFromMap: (n: INode) => void;
|
removeNodeFromMap: (n: INode) => void;
|
||||||
has: (id: number) => boolean;
|
has: (id: number) => boolean;
|
||||||
|
reset: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type throttleOptions = {
|
export type throttleOptions = {
|
||||||
@@ -577,6 +578,7 @@ export enum ReplayerEvents {
|
|||||||
CustomEvent = 'custom-event',
|
CustomEvent = 'custom-event',
|
||||||
Flush = 'flush',
|
Flush = 'flush',
|
||||||
StateChange = 'state-change',
|
StateChange = 'state-change',
|
||||||
|
PlayBack = 'play-back',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MaskInputFn = (text: string) => string;
|
export type MaskInputFn = (text: string) => string;
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ export const mirror: Mirror = {
|
|||||||
has(id) {
|
has(id) {
|
||||||
return mirror.map.hasOwnProperty(id);
|
return mirror.map.hasOwnProperty(id);
|
||||||
},
|
},
|
||||||
|
reset() {
|
||||||
|
mirror.map = {};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// copy from underscore and modified
|
// copy from underscore and modified
|
||||||
|
|||||||
Reference in New Issue
Block a user