From 0f3b67e53ea5d29cddeca39905e6473e097f4d6c Mon Sep 17 00:00:00 2001 From: Radium Zheng Date: Wed, 11 Jul 2018 00:26:16 +1000 Subject: [PATCH] reducer should be a pure function --- react/features/local-recording/actionTypes.js | 10 ++++++---- react/features/local-recording/actions.js | 11 +++++++---- .../components/LocalRecordingInfoDialog.js | 12 ++++++------ react/features/local-recording/middleware.js | 4 +++- react/features/local-recording/reducer.js | 4 ++-- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/react/features/local-recording/actionTypes.js b/react/features/local-recording/actionTypes.js index 5f002eab1..c154100ff 100644 --- a/react/features/local-recording/actionTypes.js +++ b/react/features/local-recording/actionTypes.js @@ -3,7 +3,8 @@ * (as in: {@code RecordingAdapter} is actively collecting audio data). * * { - * type: LOCAL_RECORDING_ENGAGED + * type: LOCAL_RECORDING_ENGAGED, + * recordingEngagedAt: Date * } */ export const LOCAL_RECORDING_ENGAGED = Symbol('LOCAL_RECORDING_ENGAGED'); @@ -29,11 +30,12 @@ export const LOCAL_RECORDING_TOGGLE_DIALOG = Symbol('LOCAL_RECORDING_TOGGLE_DIALOG'); /** - * Action to update {@code LocalRecordingInfoDialog} with stats - * from all clients. + * Action to update {@code LocalRecordingInfoDialog} with stats from all + * clients. * * { - * type: LOCAL_RECORDING_STATS_UPDATE + * type: LOCAL_RECORDING_STATS_UPDATE, + * stats: Object * } */ export const LOCAL_RECORDING_STATS_UPDATE diff --git a/react/features/local-recording/actions.js b/react/features/local-recording/actions.js index fea3cdb83..8f184dbc3 100644 --- a/react/features/local-recording/actions.js +++ b/react/features/local-recording/actions.js @@ -14,15 +14,18 @@ import { // recording in the UI. /** - * Signals that local recording has started. + * Signals that local recording has been engaged. * + * @param {Date} startTime - Time when the recording is engaged. * @returns {{ - * type: LOCAL_RECORDING_ENGAGED + * type: LOCAL_RECORDING_ENGAGED, + * recordingEngagedAt: Date * }} */ -export function localRecordingEngaged() { +export function localRecordingEngaged(startTime: Date) { return { - type: LOCAL_RECORDING_ENGAGED + type: LOCAL_RECORDING_ENGAGED, + recordingEngagedAt: startTime }; } diff --git a/react/features/local-recording/components/LocalRecordingInfoDialog.js b/react/features/local-recording/components/LocalRecordingInfoDialog.js index 1a1d47e15..7b0103e0c 100644 --- a/react/features/local-recording/components/LocalRecordingInfoDialog.js +++ b/react/features/local-recording/components/LocalRecordingInfoDialog.js @@ -44,7 +44,7 @@ type Props = { * The start time of the current local recording session. * Used to calculate the duration of recording. */ - recordingStartedAt: Date, + recordingEngagedAt: Date, /** * Stats of all the participant. @@ -103,11 +103,11 @@ class LocalRecordingInfoDialog extends Component { this._timer = setInterval( () => { this.setState((_prevState, props) => { - const nowTime = new Date(Date.now()); + const nowTime = new Date(); return { durationString: this._getDuration(nowTime, - props.recordingStartedAt) + props.recordingEngagedAt) }; }); try { @@ -312,7 +312,7 @@ class LocalRecordingInfoDialog extends Component { * encodingFormat: string, * isModerator: boolean, * isOn: boolean, - * recordingStartedAt: Date, + * recordingEngagedAt: Date, * stats: Object * }} */ @@ -320,7 +320,7 @@ function _mapStateToProps(state) { const { encodingFormat, isEngaged: isOn, - recordingStartedAt, + recordingEngagedAt, stats } = state['features/local-recording']; const isModerator @@ -330,7 +330,7 @@ function _mapStateToProps(state) { encodingFormat, isModerator, isOn, - recordingStartedAt, + recordingEngagedAt, stats }; } diff --git a/react/features/local-recording/middleware.js b/react/features/local-recording/middleware.js index 2c904b349..133636fdd 100644 --- a/react/features/local-recording/middleware.js +++ b/react/features/local-recording/middleware.js @@ -24,7 +24,9 @@ MiddlewareRegistry.register(({ getState, dispatch }) => next => action => { // react to state changes in recordingController. recordingController.onStateChanged = function(isEngaged) { if (isEngaged) { - dispatch(localRecordingEngaged()); + const nowTime = new Date(); + + dispatch(localRecordingEngaged(nowTime)); } else { dispatch(localRecordingUnengaged()); } diff --git a/react/features/local-recording/reducer.js b/react/features/local-recording/reducer.js index 7e370e64c..619590320 100644 --- a/react/features/local-recording/reducer.js +++ b/react/features/local-recording/reducer.js @@ -15,7 +15,7 @@ ReducerRegistry.register('features/local-recording', (state = {}, action) => { return { ...state, isEngaged: true, - recordingStartedAt: new Date(Date.now()), + recordingEngagedAt: action.recordingEngagedAt, encodingFormat: recordingController._format }; } @@ -23,7 +23,7 @@ ReducerRegistry.register('features/local-recording', (state = {}, action) => { return { ...state, isEngaged: false, - recordingStartedAt: null + recordingEngagedAt: null }; case LOCAL_RECORDING_TOGGLE_DIALOG: return {