Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/replay/backend/api/ReplayTick.ts
1030 views
1
import ReplayTabState from '~backend/api/ReplayTabState';
2
import ReplayTime from '~backend/api/ReplayTime';
3
4
export type IEventType = 'command' | 'paint' | 'focus' | 'mouse' | 'scroll' | 'page' | 'init';
5
export default class ReplayTick {
6
public isNewDocumentTick = false;
7
public documentOrigin: string;
8
9
public documentLoadPaintIndex: number;
10
11
public highlightNodeIds?: { frameIdPath: string; nodeIds: number[] } = null;
12
public paintEventIdx?: number = null;
13
public scrollEventTick?: number = null;
14
public focusEventTick?: number = null;
15
public mouseEventTick?: number = null;
16
public get playbarOffsetPercent() {
17
return this._playbarOffsetPercent;
18
}
19
20
public set playbarOffsetPercent(value) {
21
this._playbarOffsetPercent = Math.floor(1000 * value) / 1000;
22
}
23
24
private _playbarOffsetPercent: number;
25
private eventDate: Date;
26
private lastDurationMillis: number;
27
28
constructor(
29
state: ReplayTabState,
30
readonly eventType: IEventType,
31
public eventTypeTick: number,
32
readonly commandId: number,
33
readonly timestamp: number,
34
readonly label?: string,
35
) {
36
this.eventDate = new Date(timestamp);
37
this.updateDuration(state.replayTime);
38
}
39
40
public isMajor() {
41
return this.eventType === 'command' || this.eventType === 'init';
42
}
43
44
public toJSON() {
45
return {
46
commandId: this.commandId,
47
label: this.label,
48
playbarOffsetPercent: this.playbarOffsetPercent,
49
};
50
}
51
52
public updateDuration(replayTime: ReplayTime) {
53
if (this.eventType === 'init') {
54
this.playbarOffsetPercent = 0;
55
return;
56
}
57
58
if (replayTime.millis === this.lastDurationMillis) return;
59
this.lastDurationMillis = replayTime.millis;
60
61
const millis = this.eventDate.getTime() - replayTime.start.getTime();
62
this.playbarOffsetPercent = (100 * millis) / replayTime.millis;
63
}
64
}
65
66