Skip to content

Commit

Permalink
Fun with timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesremuscat committed Jun 17, 2024
1 parent fabb516 commit 502cd59
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ export class Replay {
return await this.getStateAt(this.manifest.startTime + relTime);
}

/**
* Pass a function that will be called once for each frame in this recording,
* in order.
*
* The returned timestamp is a Unix-style timestamp (without milliseconds).
*
* @param {function} callback Function that will get called with arguments
* `(state, timestamp)` for each frame in the recording.
*/
async forEachFrame(callback) {
const keyframes = Object.keys(this._keyframes).map(k => parseInt(k, 10)).sort();
const iframes = Object.keys(this._iframes).map(k => parseInt(k, 10)).sort();
Expand All @@ -132,7 +141,9 @@ export class Replay {
const i = iframes.shift();
const ifr = await this.readEntry(this._iframes[i]);
prevFrame = await applyIframe(prevFrame, ifr);
prevFrame.lastUpdated = i;
// Internal lastUpdated is a JS timestamp (with milliseconds)
prevFrame.lastUpdated = i * 1000;
// Callback gets a Unix timestamp (no milliseconds)
callback(prevFrame, i);
}
}
Expand Down

0 comments on commit 502cd59

Please sign in to comment.