Skip to content

Commit

Permalink
impl auto play
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuyz0112 committed Jan 24, 2019
1 parent 9099a8a commit f3de701
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"svelte": "^2.16.0"
},
"dependencies": {
"rrweb": "^0.7.2"
"rrweb": "^0.7.7"
},
"scripts": {
"build": "rollup -c",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
target: document.body,
data: {
events,
autoPlay: false,
},
});
</script>
Expand Down
10 changes: 9 additions & 1 deletion src/Controller.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,19 @@
onupdate({ changed, current, previous }) {
if (current.replayer && !previous) {
window.replayer = current.replayer;
// auto play
setTimeout(() => {
this.set({ isPlaying: true });
}, 0);
current.replayer.play(0);
if (!current.autoPlay) {
let firstFullSnapshotRebuilded = false;
current.replayer.on('fullsnapshot-rebuilded', () => {
if (!firstFullSnapshotRebuilded) {
firstFullSnapshotRebuilded = true;
current.replayer.pause();
}
});
}
current.replayer.on('pause', () => {
this.set({ isPlaying: false });
});
Expand Down
4 changes: 3 additions & 1 deletion src/Player.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="rr-player" ref:player style="{playerStyle}">
<div class="rr-player__frame" ref:frame { style }></div>
{#if replayer}
<Controller { replayer } {showController} on:fullscreen="fullscreen()" />
<Controller { replayer } {showController} {autoPlay} on:fullscreen="fullscreen()" />
{/if}
</div>

Expand All @@ -28,6 +28,7 @@
width: 1024,
height: 576,
events: [],
autoPlay: true,
replayer: null,
};
},
Expand Down Expand Up @@ -66,6 +67,7 @@
speed: 1,
root: this.refs.frame,
skipInactive: true,
showWarning: true,
});
replayer.on('resize', (dimension) =>
this.updateScale(replayer.wrapper, dimension)
Expand Down
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
export function formatTime(ms) {
if (ms <= 0) {
return '00:00';
}
const hour = Math.floor(ms / HOUR);
ms = ms % HOUR;
const minute = Math.floor(ms / MINUTE);
Expand Down

0 comments on commit f3de701

Please sign in to comment.