LordXido commited on
Commit
ed4ca56
·
verified ·
1 Parent(s): 709f56b

Update plme.js

Browse files
Files changed (1) hide show
  1. plme.js +5 -7
plme.js CHANGED
@@ -1,16 +1,14 @@
1
  const timeline = [];
2
- let replaying = false;
3
- let startTime = 0;
4
 
5
  export function record(packet) {
6
  timeline.push(packet);
7
  }
8
 
9
- export function replay(callback) {
10
- replaying = true;
11
- startTime = performance.now();
12
 
13
- timeline.forEach(pkt => {
14
- setTimeout(() => callback(pkt), pkt.timestamp - timeline[0].timestamp);
15
  });
16
  }
 
1
  const timeline = [];
 
 
2
 
3
  export function record(packet) {
4
  timeline.push(packet);
5
  }
6
 
7
+ export function replay(cb) {
8
+ if (!timeline.length) return;
9
+ const t0 = timeline[0].timestamp;
10
 
11
+ timeline.forEach(p => {
12
+ setTimeout(() => cb(p), p.timestamp - t0);
13
  });
14
  }