@highlight-run/rrweb 2.0.1 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugins/console-record.js +408 -609
- package/dist/plugins/console-record.min.js +12 -15
- package/dist/plugins/console-record.min.js.map +1 -1
- package/dist/plugins/console-replay.js +142 -271
- package/dist/plugins/console-replay.min.js +4 -15
- package/dist/plugins/console-replay.min.js.map +1 -1
- package/dist/plugins/sequential-id-record.js +23 -26
- package/dist/plugins/sequential-id-record.min.js +1 -1
- package/dist/plugins/sequential-id-record.min.js.map +1 -1
- package/dist/plugins/sequential-id-replay.js +26 -30
- package/dist/plugins/sequential-id-replay.min.js +1 -1
- package/dist/plugins/sequential-id-replay.min.js.map +1 -1
- package/dist/record/rrweb-record-pack.js +63 -146
- package/dist/record/rrweb-record-pack.min.js +3 -15
- package/dist/record/rrweb-record-pack.min.js.map +1 -1
- package/dist/record/rrweb-record.js +3002 -3118
- package/dist/record/rrweb-record.min.js +4 -15
- package/dist/record/rrweb-record.min.js.map +1 -1
- package/dist/replay/rrweb-replay-unpack.js +4354 -4054
- package/dist/replay/rrweb-replay-unpack.min.js +5 -17
- package/dist/replay/rrweb-replay-unpack.min.js.map +1 -1
- package/dist/replay/rrweb-replay.js +4286 -3984
- package/dist/replay/rrweb-replay.min.js +5 -17
- package/dist/replay/rrweb-replay.min.js.map +1 -1
- package/dist/rrweb-all.js +7634 -7453
- package/dist/rrweb-all.min.js +16 -17
- package/dist/rrweb-all.min.js.map +1 -1
- package/dist/rrweb.js +7339 -7075
- package/dist/rrweb.min.js +6 -17
- package/dist/rrweb.min.js.map +1 -1
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/es/rrweb/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/rrweb/_virtual/image-bitmap-data-url-worker.js +6 -0
- package/es/rrweb/ext/mitt/dist/mitt.es.js +1 -1
- package/es/rrweb/ext/tslib/tslib.es6.js +38 -0
- package/es/rrweb/packages/rrdom/es/virtual-dom.js +1099 -0
- package/es/rrweb/packages/rrweb/src/index.js +6 -4
- package/es/rrweb/packages/rrweb/src/packer/base.js +1 -1
- package/es/rrweb/packages/rrweb/src/packer/pack.js +4 -5
- package/es/rrweb/packages/rrweb/src/packer/unpack.js +24 -24
- package/es/rrweb/packages/rrweb/src/plugins/console/record/error-stack-parser.js +175 -176
- package/es/rrweb/packages/rrweb/src/plugins/console/record/index.js +109 -128
- package/es/rrweb/packages/rrweb/src/plugins/console/record/stringify.js +125 -138
- package/es/rrweb/packages/rrweb/src/plugins/console/replay/index.js +88 -105
- package/es/rrweb/packages/rrweb/src/plugins/sequential-id/record/index.js +19 -20
- package/es/rrweb/packages/rrweb/src/plugins/sequential-id/replay/index.js +25 -25
- package/es/rrweb/packages/rrweb/src/record/iframe-manager.js +29 -30
- package/es/rrweb/packages/rrweb/src/record/index.js +348 -373
- package/es/rrweb/packages/rrweb/src/record/mutation.js +487 -528
- package/es/rrweb/packages/rrweb/src/record/observer.js +584 -659
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/2d.js +44 -73
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas-manager.js +166 -87
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/canvas.js +21 -26
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/serialize-args.js +119 -112
- package/es/rrweb/packages/rrweb/src/record/observers/canvas/webgl.js +53 -72
- package/es/rrweb/packages/rrweb/src/record/shadow-dom-manager.js +38 -40
- package/es/rrweb/packages/rrweb/src/record/stylesheet-manager.js +31 -0
- package/es/rrweb/packages/rrweb/src/replay/canvas/2d.js +27 -23
- package/es/rrweb/packages/rrweb/src/replay/canvas/deserialize-args.js +67 -0
- package/es/rrweb/packages/rrweb/src/replay/canvas/index.js +37 -29
- package/es/rrweb/packages/rrweb/src/replay/canvas/webgl.js +58 -120
- package/es/rrweb/packages/rrweb/src/replay/index.js +1545 -1854
- package/es/rrweb/packages/rrweb/src/replay/machine.js +275 -315
- package/es/rrweb/packages/rrweb/src/replay/smoothscroll.js +216 -218
- package/es/rrweb/packages/rrweb/src/replay/styles/inject-style.js +7 -7
- package/es/rrweb/packages/rrweb/src/replay/timer.js +87 -91
- package/es/rrweb/packages/rrweb/src/types.js +72 -72
- package/es/rrweb/packages/rrweb/src/utils.js +312 -506
- package/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +195 -71
- package/lib/plugins/console-record.js +469 -627
- package/lib/plugins/console-replay.js +198 -268
- package/lib/plugins/sequential-id-record.js +19 -20
- package/lib/plugins/sequential-id-replay.js +25 -25
- package/lib/record/rrweb-record-pack.js +184 -139
- package/lib/record/rrweb-record.js +2473 -2425
- package/lib/replay/rrweb-replay-unpack.js +3797 -3343
- package/lib/replay/rrweb-replay.js +3742 -3288
- package/lib/rrweb-all.js +6725 -6247
- package/lib/rrweb.js +6157 -5632
- package/package.json +14 -13
- package/typings/packer/base.d.ts +1 -1
- package/typings/plugins/console/record/index.d.ts +1 -1
- package/typings/plugins/console/record/stringify.d.ts +1 -1
- package/typings/plugins/sequential-id/record/index.d.ts +1 -1
- package/typings/plugins/sequential-id/replay/index.d.ts +1 -1
- package/typings/record/iframe-manager.d.ts +3 -3
- package/typings/record/index.d.ts +1 -1
- package/typings/record/mutation.d.ts +2 -1
- package/typings/record/observers/canvas/2d.d.ts +2 -1
- package/typings/record/observers/canvas/canvas-manager.d.ts +5 -2
- package/typings/record/observers/canvas/canvas.d.ts +1 -1
- package/typings/record/observers/canvas/serialize-args.d.ts +5 -5
- package/typings/record/observers/canvas/webgl.d.ts +2 -1
- package/typings/record/shadow-dom-manager.d.ts +2 -1
- package/typings/record/stylesheet-manager.d.ts +12 -0
- package/typings/record/workers/image-bitmap-data-url-worker.d.ts +5 -0
- package/typings/replay/canvas/2d.d.ts +3 -3
- package/typings/replay/canvas/deserialize-args.d.ts +7 -0
- package/typings/replay/canvas/index.d.ts +4 -3
- package/typings/replay/canvas/webgl.d.ts +3 -5
- package/typings/replay/index.d.ts +7 -10
- package/typings/types.d.ts +45 -17
- package/typings/utils.d.ts +17 -44
- package/dist/replay/rrweb-replay-unpack.min.css +0 -2
- package/dist/replay/rrweb-replay-unpack.min.css.map +0 -1
- package/dist/replay/rrweb-replay.min.css +0 -2
- package/dist/replay/rrweb-replay.min.css.map +0 -1
- package/dist/rrweb-all.min.css +0 -2
- package/dist/rrweb-all.min.css.map +0 -1
- package/dist/rrweb.min.css +0 -2
- package/dist/rrweb.min.css.map +0 -1
- package/es/rrweb/packages/rrweb/ext/tslib/tslib.es6.js +0 -78
- package/es/rrweb/packages/rrweb/src/replay/virtual-styles.js +0 -121
- package/typings/replay/virtual-styles.d.ts +0 -43
|
@@ -1,321 +1,281 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { interpret as v, createMachine as s, assign as o } from '../../../../ext/@xstate/fsm/es/index.js';
|
|
1
|
+
import { interpret as v, createMachine as s, assign as o } from './../../../../ext/@xstate/fsm/es/index.js';
|
|
3
2
|
import { EventType, IncrementalSource, ReplayerEvents } from '../types.js';
|
|
4
3
|
import { addDelay } from './timer.js';
|
|
5
4
|
|
|
6
|
-
function discardPriorSnapshots(events, baselineTime) {
|
|
7
|
-
for (
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
if (
|
|
11
|
-
return events.slice(idx);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return events;
|
|
16
|
-
}
|
|
17
|
-
function createPlayerService(context,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
},
|
|
186
|
-
}),
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
FAST_FORWARD: {
|
|
281
|
-
target: 'skipping',
|
|
282
|
-
actions: ['recordSpeed', 'setSpeed'],
|
|
283
|
-
},
|
|
284
|
-
SET_SPEED: {
|
|
285
|
-
target: 'normal',
|
|
286
|
-
actions: ['setSpeed'],
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
skipping: {
|
|
291
|
-
on: {
|
|
292
|
-
BACK_TO_NORMAL: {
|
|
293
|
-
target: 'normal',
|
|
294
|
-
actions: ['restoreSpeed'],
|
|
295
|
-
},
|
|
296
|
-
SET_SPEED: {
|
|
297
|
-
target: 'normal',
|
|
298
|
-
actions: ['setSpeed'],
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
}, {
|
|
304
|
-
actions: {
|
|
305
|
-
setSpeed: function (ctx, event) {
|
|
306
|
-
if ('payload' in event) {
|
|
307
|
-
ctx.timer.setSpeed(event.payload.speed);
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
recordSpeed: o({
|
|
311
|
-
normalSpeed: function (ctx) { return ctx.timer.speed; },
|
|
312
|
-
}),
|
|
313
|
-
restoreSpeed: function (ctx) {
|
|
314
|
-
ctx.timer.setSpeed(ctx.normalSpeed);
|
|
315
|
-
},
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
return v(speedMachine);
|
|
5
|
+
function discardPriorSnapshots(events, baselineTime) {
|
|
6
|
+
for (let idx = events.length - 1; idx >= 0; idx--) {
|
|
7
|
+
const event = events[idx];
|
|
8
|
+
if (event.type === EventType.Meta) {
|
|
9
|
+
if (event.timestamp <= baselineTime) {
|
|
10
|
+
return events.slice(idx);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return events;
|
|
15
|
+
}
|
|
16
|
+
function createPlayerService(context, { getCastFn, applyEventsSynchronously, emitter }) {
|
|
17
|
+
const playerMachine = s({
|
|
18
|
+
id: 'player',
|
|
19
|
+
context,
|
|
20
|
+
initial: 'paused',
|
|
21
|
+
states: {
|
|
22
|
+
playing: {
|
|
23
|
+
on: {
|
|
24
|
+
PAUSE: {
|
|
25
|
+
target: 'paused',
|
|
26
|
+
actions: ['pause'],
|
|
27
|
+
},
|
|
28
|
+
CAST_EVENT: {
|
|
29
|
+
target: 'playing',
|
|
30
|
+
actions: 'castEvent',
|
|
31
|
+
},
|
|
32
|
+
END: {
|
|
33
|
+
target: 'paused',
|
|
34
|
+
actions: ['resetLastPlayedEvent', 'pause'],
|
|
35
|
+
},
|
|
36
|
+
ADD_EVENT: {
|
|
37
|
+
target: 'playing',
|
|
38
|
+
actions: ['addEvent'],
|
|
39
|
+
},
|
|
40
|
+
REPLACE_EVENTS: {
|
|
41
|
+
target: 'playing',
|
|
42
|
+
actions: ['replaceEvents'],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
paused: {
|
|
47
|
+
on: {
|
|
48
|
+
PLAY: {
|
|
49
|
+
target: 'playing',
|
|
50
|
+
actions: ['recordTimeOffset', 'play'],
|
|
51
|
+
},
|
|
52
|
+
CAST_EVENT: {
|
|
53
|
+
target: 'paused',
|
|
54
|
+
actions: 'castEvent',
|
|
55
|
+
},
|
|
56
|
+
TO_LIVE: {
|
|
57
|
+
target: 'live',
|
|
58
|
+
actions: ['startLive'],
|
|
59
|
+
},
|
|
60
|
+
ADD_EVENT: {
|
|
61
|
+
target: 'paused',
|
|
62
|
+
actions: ['addEvent'],
|
|
63
|
+
},
|
|
64
|
+
REPLACE_EVENTS: {
|
|
65
|
+
target: 'paused',
|
|
66
|
+
actions: ['replaceEvents'],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
live: {
|
|
71
|
+
on: {
|
|
72
|
+
ADD_EVENT: {
|
|
73
|
+
target: 'live',
|
|
74
|
+
actions: ['addEvent'],
|
|
75
|
+
},
|
|
76
|
+
CAST_EVENT: {
|
|
77
|
+
target: 'live',
|
|
78
|
+
actions: ['castEvent'],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}, {
|
|
84
|
+
actions: {
|
|
85
|
+
castEvent: o({
|
|
86
|
+
lastPlayedEvent: (ctx, event) => {
|
|
87
|
+
if (event.type === 'CAST_EVENT') {
|
|
88
|
+
return event.payload.event;
|
|
89
|
+
}
|
|
90
|
+
return ctx.lastPlayedEvent;
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
recordTimeOffset: o((ctx, event) => {
|
|
94
|
+
let timeOffset = ctx.timeOffset;
|
|
95
|
+
if ('payload' in event && 'timeOffset' in event.payload) {
|
|
96
|
+
timeOffset = event.payload.timeOffset;
|
|
97
|
+
}
|
|
98
|
+
return Object.assign(Object.assign({}, ctx), { timeOffset, baselineTime: ctx.events[0].timestamp + timeOffset });
|
|
99
|
+
}),
|
|
100
|
+
play(ctx) {
|
|
101
|
+
var _a;
|
|
102
|
+
const { timer, events, baselineTime, lastPlayedEvent } = ctx;
|
|
103
|
+
timer.clear();
|
|
104
|
+
for (const event of events) {
|
|
105
|
+
addDelay(event, baselineTime);
|
|
106
|
+
}
|
|
107
|
+
const neededEvents = discardPriorSnapshots(events, baselineTime);
|
|
108
|
+
let lastPlayedTimestamp = lastPlayedEvent === null || lastPlayedEvent === void 0 ? void 0 : lastPlayedEvent.timestamp;
|
|
109
|
+
if ((lastPlayedEvent === null || lastPlayedEvent === void 0 ? void 0 : lastPlayedEvent.type) === EventType.IncrementalSnapshot &&
|
|
110
|
+
lastPlayedEvent.data.source === IncrementalSource.MouseMove) {
|
|
111
|
+
lastPlayedTimestamp =
|
|
112
|
+
lastPlayedEvent.timestamp +
|
|
113
|
+
((_a = lastPlayedEvent.data.positions[0]) === null || _a === void 0 ? void 0 : _a.timeOffset);
|
|
114
|
+
}
|
|
115
|
+
if (baselineTime < (lastPlayedTimestamp || 0)) {
|
|
116
|
+
emitter.emit(ReplayerEvents.PlayBack);
|
|
117
|
+
}
|
|
118
|
+
const syncEvents = new Array();
|
|
119
|
+
const actions = new Array();
|
|
120
|
+
for (const event of neededEvents) {
|
|
121
|
+
if (lastPlayedTimestamp &&
|
|
122
|
+
lastPlayedTimestamp < baselineTime &&
|
|
123
|
+
(event.timestamp <= lastPlayedTimestamp ||
|
|
124
|
+
event === lastPlayedEvent)) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (event.timestamp < baselineTime) {
|
|
128
|
+
syncEvents.push(event);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const castFn = getCastFn(event, false);
|
|
132
|
+
actions.push({
|
|
133
|
+
doAction: () => {
|
|
134
|
+
castFn();
|
|
135
|
+
},
|
|
136
|
+
delay: event.delay,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
applyEventsSynchronously(syncEvents);
|
|
141
|
+
emitter.emit(ReplayerEvents.Flush);
|
|
142
|
+
timer.addActions(actions);
|
|
143
|
+
timer.start();
|
|
144
|
+
},
|
|
145
|
+
pause(ctx) {
|
|
146
|
+
ctx.timer.clear();
|
|
147
|
+
},
|
|
148
|
+
resetLastPlayedEvent: o((ctx) => {
|
|
149
|
+
return Object.assign(Object.assign({}, ctx), { lastPlayedEvent: null });
|
|
150
|
+
}),
|
|
151
|
+
startLive: o({
|
|
152
|
+
baselineTime: (ctx, event) => {
|
|
153
|
+
ctx.timer.toggleLiveMode(true);
|
|
154
|
+
ctx.timer.start();
|
|
155
|
+
if (event.type === 'TO_LIVE' && event.payload.baselineTime) {
|
|
156
|
+
return event.payload.baselineTime;
|
|
157
|
+
}
|
|
158
|
+
return Date.now();
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
replaceEvents: o((ctx, machineEvent) => {
|
|
162
|
+
const { events: curEvents, timer, baselineTime } = ctx;
|
|
163
|
+
if (machineEvent.type === 'REPLACE_EVENTS') {
|
|
164
|
+
const { events: newEvents } = machineEvent.payload;
|
|
165
|
+
curEvents.length = 0;
|
|
166
|
+
const actions = [];
|
|
167
|
+
for (const event of newEvents) {
|
|
168
|
+
addDelay(event, baselineTime);
|
|
169
|
+
curEvents.push(event);
|
|
170
|
+
if (event.timestamp >= timer.timeOffset + baselineTime) {
|
|
171
|
+
const castFn = getCastFn(event, false);
|
|
172
|
+
actions.push({
|
|
173
|
+
doAction: () => {
|
|
174
|
+
castFn();
|
|
175
|
+
},
|
|
176
|
+
delay: event.delay,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (timer.isActive()) {
|
|
181
|
+
timer.replaceActions(actions);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return Object.assign(Object.assign({}, ctx), { events: curEvents });
|
|
185
|
+
}),
|
|
186
|
+
addEvent: o((ctx, machineEvent) => {
|
|
187
|
+
const { baselineTime, timer, events } = ctx;
|
|
188
|
+
if (machineEvent.type === 'ADD_EVENT') {
|
|
189
|
+
const { event } = machineEvent.payload;
|
|
190
|
+
addDelay(event, baselineTime);
|
|
191
|
+
let end = events.length - 1;
|
|
192
|
+
if (!events[end] || events[end].timestamp <= event.timestamp) {
|
|
193
|
+
events.push(event);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
let insertionIndex = -1;
|
|
197
|
+
let start = 0;
|
|
198
|
+
while (start <= end) {
|
|
199
|
+
const mid = Math.floor((start + end) / 2);
|
|
200
|
+
if (events[mid].timestamp <= event.timestamp) {
|
|
201
|
+
start = mid + 1;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
end = mid - 1;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (insertionIndex === -1) {
|
|
208
|
+
insertionIndex = start;
|
|
209
|
+
}
|
|
210
|
+
events.splice(insertionIndex, 0, event);
|
|
211
|
+
}
|
|
212
|
+
const isSync = event.timestamp < baselineTime;
|
|
213
|
+
const castFn = getCastFn(event, isSync);
|
|
214
|
+
if (isSync) {
|
|
215
|
+
castFn();
|
|
216
|
+
}
|
|
217
|
+
else if (timer.isActive()) {
|
|
218
|
+
timer.addAction({
|
|
219
|
+
doAction: () => {
|
|
220
|
+
castFn();
|
|
221
|
+
},
|
|
222
|
+
delay: event.delay,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return Object.assign(Object.assign({}, ctx), { events });
|
|
227
|
+
}),
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
return v(playerMachine);
|
|
231
|
+
}
|
|
232
|
+
function createSpeedService(context) {
|
|
233
|
+
const speedMachine = s({
|
|
234
|
+
id: 'speed',
|
|
235
|
+
context,
|
|
236
|
+
initial: 'normal',
|
|
237
|
+
states: {
|
|
238
|
+
normal: {
|
|
239
|
+
on: {
|
|
240
|
+
FAST_FORWARD: {
|
|
241
|
+
target: 'skipping',
|
|
242
|
+
actions: ['recordSpeed', 'setSpeed'],
|
|
243
|
+
},
|
|
244
|
+
SET_SPEED: {
|
|
245
|
+
target: 'normal',
|
|
246
|
+
actions: ['setSpeed'],
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
skipping: {
|
|
251
|
+
on: {
|
|
252
|
+
BACK_TO_NORMAL: {
|
|
253
|
+
target: 'normal',
|
|
254
|
+
actions: ['restoreSpeed'],
|
|
255
|
+
},
|
|
256
|
+
SET_SPEED: {
|
|
257
|
+
target: 'normal',
|
|
258
|
+
actions: ['setSpeed'],
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
}, {
|
|
264
|
+
actions: {
|
|
265
|
+
setSpeed: (ctx, event) => {
|
|
266
|
+
if ('payload' in event) {
|
|
267
|
+
ctx.timer.setSpeed(event.payload.speed);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
recordSpeed: o({
|
|
271
|
+
normalSpeed: (ctx) => ctx.timer.speed,
|
|
272
|
+
}),
|
|
273
|
+
restoreSpeed: (ctx) => {
|
|
274
|
+
ctx.timer.setSpeed(ctx.normalSpeed);
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
return v(speedMachine);
|
|
319
279
|
}
|
|
320
280
|
|
|
321
281
|
export { createPlayerService, createSpeedService, discardPriorSnapshots };
|