refract: firefox support

This commit is contained in:
cv
2021-04-10 11:51:36 +02:00
parent e62b79f84e
commit 9a8c4a8a5a
+25 -25
View File
@@ -1,10 +1,10 @@
class Timer { class Timer {
#current = null; _current = null;
#finishAt = null; _finishAt = null;
#startedAt = null; _startedAt = null;
#pausedAt = null; _pausedAt = null;
#pausedInterval = null; _pausedInterval = null;
#pausedTotal = null; _pausedTotal = null;
state = 'pause'; state = 'pause';
constructor() {} constructor() {}
@@ -15,18 +15,18 @@ class Timer {
const now = new Date().getTime(); const now = new Date().getTime();
// populate targets // populate targets
this.#finishAt = now + seconds * 1000; this._finishAt = now + seconds * 1000;
// start counting // start counting
this.#startedAt = now; this._startedAt = now;
if (autoStart) { if (autoStart) {
this.state = 'start'; this.state = 'start';
} else { } else {
this.#pausedAt = now; this._pausedAt = now;
this.#pausedInterval = 0; this._pausedInterval = 0;
} }
this.#pausedTotal = 0; this._pausedTotal = 0;
this.update(); this.update();
} }
@@ -39,11 +39,11 @@ class Timer {
switch (this.state) { switch (this.state) {
case 'start': case 'start':
// update current timer // update current timer
this.#current = this.#finishAt + this.#pausedTotal - now; this._current = this._finishAt + this._pausedTotal - now;
break; break;
case 'pause': case 'pause':
// update paused time // update paused time
this.#pausedInterval = now - this.#pausedAt; this._pausedInterval = now - this._pausedAt;
break; break;
default: default:
console.error('Timer: no playstate on update call', this.state); console.error('Timer: no playstate on update call', this.state);
@@ -56,17 +56,17 @@ class Timer {
return Math.floor(Math.max(millis * 0.001), 0); return Math.floor(Math.max(millis * 0.001), 0);
} }
#getExpectedFinish() { _getExpectedFinish() {
return this.#finishAt + (this.#pausedInterval + this.#pausedTotal); return this._finishAt + (this._pausedInterval + this._pausedTotal);
} }
// getObject // getObject
getObject() { getObject() {
this.update(); this.update();
return { return {
currentSeconds: Timer.toSeconds(this.#current), currentSeconds: Timer.toSeconds(this._current),
expectedFinish: this.#getExpectedFinish(), expectedFinish: this._getExpectedFinish(),
startedAt: this.#startedAt, startedAt: this._startedAt,
}; };
} }
@@ -74,7 +74,7 @@ class Timer {
getCurrentInSeconds() { getCurrentInSeconds() {
// update timeStamp // update timeStamp
this.update(); this.update();
return Timer.toSeconds(this.#current); return Timer.toSeconds(this._current);
} }
// playback // playback
@@ -83,14 +83,14 @@ class Timer {
if (this.state === 'start') return; if (this.state === 'start') return;
// update start time if needed // update start time if needed
if (!this.#startedAt) { if (!this._startedAt) {
this.#startedAt = new Date().getTime(); this._startedAt = new Date().getTime();
} }
// check if there is paused time // check if there is paused time
if (this.#pausedInterval) { if (this._pausedInterval) {
this.#pausedTotal += this.#pausedInterval; this._pausedTotal += this._pausedInterval;
this.#pausedInterval = null; this._pausedInterval = null;
} }
// change state // change state
@@ -101,7 +101,7 @@ class Timer {
if (this.state === 'pause') return; if (this.state === 'pause') return;
// update pause time // update pause time
this.#pausedAt = new Date().getTime(); this._pausedAt = new Date().getTime();
// change state // change state
this.state = 'pause'; this.state = 'pause';