Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sometimes currentTime is smaller than the totalTime when player is finished #445

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class Replayer {
// defer finish event if the last event is a mouse move
setTimeout(() => {
finish();
}, Math.max(0, -event.data.positions[0].timeOffset));
}, Math.max(0, -event.data.positions[0].timeOffset + 50)); // Add 50 to make sure the timer would check the last mousemove event. Otherwise, the timer may be stopped by the service before checking the last event.
} else {
finish();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mark-Fenng do you think the 50ms buffer is also valid to be applied to the } else { branch here?

I've another unrelated use-case; namely to ensure that we don't prematurely finish when new events are being rapidly added via addEvent ... see #606 — I'm thinking to add the setTimeout ... 50 to before both calls to finish().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eoghanmurray I think setTimeout at else branch can work out.

}
Expand Down
3 changes: 2 additions & 1 deletion src/replay/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class Timer {
let lastTimestamp = performance.now();
const { actions } = this;
const self = this;
function check(time: number) {
function check() {
const time = performance.now();
self.timeOffset += (time - lastTimestamp) * self.speed;
lastTimestamp = time;
while (actions.length) {
Expand Down