diff --git a/package.json b/package.json index 3c44026f..aa016338 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "svelte": "^2.16.0" }, "dependencies": { - "rrweb": "^0.6.11" + "rrweb": "^0.7.0" }, "scripts": { "build": "rollup -c", diff --git a/src/Controller.html b/src/Controller.html index a1ba8454..84db820c 100644 --- a/src/Controller.html +++ b/src/Controller.html @@ -49,8 +49,15 @@ {/if} {#each [1, 2, 4, 8] as s} - + {/each} + {/if} @@ -59,10 +66,15 @@ import { formatTime } from './utils.js'; export default { + components: { + Switch: './components/Switch.html', + }, data() { return { currentTime: 0, isPlaying: false, + isSkipping: false, + skipInactive: true, speed: 1, }; }, @@ -80,29 +92,23 @@ }, methods: { loopTimer() { - const now = performance.now(); - let lastStep = now; const self = this; - function update(step) { - let { currentTime, meta, isPlaying, speed } = self.get(); + function update() { + const { meta, isPlaying, replayer } = self.get(); if (!isPlaying) { self.timer = null; return; } - const stepDiff = Math.floor(step - lastStep); - lastStep = step; - currentTime += speed * stepDiff; + const currentTime = + replayer.timer.timeOffset + replayer.getTimeOffset(); self.set({ - currentTime: Math.min(currentTime, meta.totalTime), + currentTime, }); if (currentTime < meta.totalTime) { requestAnimationFrame(update); - } else { - self.timer = null; - self.set({ isPlaying: false, currentTime: 0 }); } } @@ -130,9 +136,11 @@ } }, setSpeed(speed) { - const { replayer } = this.get(); + const { replayer, currentTime } = this.get(); + replayer.pause(); replayer.setConfig({ speed }); this.set({ speed }); + replayer.resume(currentTime); }, handleProgressClick(event) { const progressRect = this.refs.progress.getBoundingClientRect(); @@ -165,12 +173,27 @@ current.replayer.on('resume', () => { this.set({ isPlaying: true }); }); + current.replayer.on('finish', () => { + this.timer = null; + this.set({ isPlaying: false, currentTime: 0 }); + }); + current.replayer.on('skip-start', payload => { + payload.isSkipping = true; + this.set(payload); + }); + current.replayer.on('skip-end', payload => { + payload.isSkipping = false; + this.set(payload); + }); } if (changed.isPlaying) { if (current.isPlaying && !this.timer) { this.loopTimer(); } } + if (changed.skipInactive) { + current.replayer.setConfig({ skipInactive: changed.skipInactive }); + } }, ondestroy() { const { isPlaying } = this.get(); @@ -233,6 +256,9 @@ .rr-controller__btns { display: flex; + align-items: center; + justify-content: center; + font-size: 13px; } .rr-controller__btns button { @@ -256,4 +282,8 @@ color: #fff; background: rgb(73, 80, 246); } + + .rr-controller__btns button:disabled { + cursor: not-allowed; + } diff --git a/src/Player.html b/src/Player.html index 2c3e0a90..cd8666ec 100644 --- a/src/Player.html +++ b/src/Player.html @@ -46,6 +46,7 @@ const replayer = new Replayer(events, { speed: 1, root: this.refs.frame, + skipInactive: true, }); replayer.on('resize', (dimension) => this.updateScale(replayer.wrapper, dimension) diff --git a/src/components/Switch.html b/src/components/Switch.html new file mode 100644 index 00000000..ffe11be2 --- /dev/null +++ b/src/components/Switch.html @@ -0,0 +1,77 @@ +
+ + {label} +
+ + diff --git a/src/utils.js b/src/utils.js index 8b47b558..030a77e3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -27,7 +27,7 @@ export function formatTime(ms) { ms = ms % MINUTE; const second = Math.round(ms / SECOND); if (hour) { - return `${padZero(hour)}:${padZero(minute)}:${padZero(minute)}`; + return `${padZero(hour)}:${padZero(minute)}:${padZero(second)}`; } return `${padZero(minute)}:${padZero(second)}`; }