diff options
Diffstat (limited to 'app/client/live')
| -rw-r--r-- | app/client/live/live.reducer.js | 14 | ||||
| -rw-r--r-- | app/client/live/player.js | 43 |
2 files changed, 45 insertions, 12 deletions
diff --git a/app/client/live/live.reducer.js b/app/client/live/live.reducer.js index 60bcb41..e7ef569 100644 --- a/app/client/live/live.reducer.js +++ b/app/client/live/live.reducer.js @@ -10,6 +10,7 @@ const liveInitialState = { epochs: ['latest'], sequences: [], fps: 0, + playing: false, frame: { i: 0, sequence_i: 0, sequence_len: '1' } } @@ -70,6 +71,18 @@ const liveReducer = (state = liveInitialState, action) => { frame: action.meta } : state + case types.player.pausing: + return { + ...state, + playing: false, + } + + case types.player.playing: + return { + ...state, + playing: true, + } + case types.player.start_recording: return { ...state, @@ -86,7 +99,6 @@ const liveReducer = (state = liveInitialState, action) => { recordFrames: (state.opt.recordFrames || 0) + 1, } } - case types.player.save_frame: FileSaver.saveAs( action.blob, diff --git a/app/client/live/player.js b/app/client/live/player.js index 808e79e..37f7cab 100644 --- a/app/client/live/player.js +++ b/app/client/live/player.js @@ -66,15 +66,36 @@ export function onFrame (data) { img.src = url } -setInterval(() => { - store.dispatch({ - type: types.player.set_fps, - fps: fps, - }) - store.dispatch({ - type: types.player.current_frame, - meta: last_frame, - }) - fps = 0 -}, 1000) +let previousValue, currentValue +function handleChange() { + let previousValue = currentValue + currentValue = store.getState().live.playing + + if (previousValue !== currentValue) { + if (currentValue) { + startWatchingFPS() + } else { + stopWatchingFPS() + } + } +} + +let fpsInterval; +function startWatchingFPS(){ + clearInterval(fpsInterval) + fpsInterval = setInterval(() => { + store.dispatch({ + type: types.player.set_fps, + fps: fps, + }) + store.dispatch({ + type: types.player.current_frame, + meta: last_frame, + }) + fps = 0 + }, 1000) +} +function stopWatchingFPS(){ + clearInterval(fpsInterval) +}
\ No newline at end of file |
