Spaces:
Running
Running
| const timeline = []; | |
| export function record(packet) { | |
| timeline.push(packet); | |
| } | |
| export function replay(cb) { | |
| if (!timeline.length) return; | |
| const t0 = timeline[0].timestamp; | |
| timeline.forEach(p => { | |
| setTimeout(() => cb(p), p.timestamp - t0); | |
| }); | |
| } |