From 1ff27b7298ace5baa16f3aa05998b690cb08d260 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Tue, 30 Jun 2020 12:48:06 -0500 Subject: [PATCH] fix: store.getState() called while the reducer is executing --- react/features/base/devices/middleware.js | 30 +++++++++++++++++++++-- react/features/base/devices/reducer.js | 20 --------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/react/features/base/devices/middleware.js b/react/features/base/devices/middleware.js index 5884695de..99fae99f3 100644 --- a/react/features/base/devices/middleware.js +++ b/react/features/base/devices/middleware.js @@ -15,14 +15,19 @@ import { NOTIFY_CAMERA_ERROR, NOTIFY_MIC_ERROR, SET_AUDIO_INPUT_DEVICE, - SET_VIDEO_INPUT_DEVICE + SET_VIDEO_INPUT_DEVICE, + UPDATE_DEVICE_LIST } from './actionTypes'; import { removePendingDeviceRequests, setAudioInputDevice, setVideoInputDevice } from './actions'; -import { formatDeviceLabel, setAudioOutputDeviceId } from './functions'; +import { + formatDeviceLabel, + groupDevicesByKind, + setAudioOutputDeviceId +} from './functions'; import logger from './logger'; const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = { @@ -41,6 +46,24 @@ const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = { } }; +/** + * Logs the current device list. + * + * @param {Object} deviceList - Whatever is returned by {@link groupDevicesByKind}. + * @returns {string} + */ +function logDeviceList(deviceList) { + const devicesToStr = list => list.map(device => `\t\t${device.label}[${device.deviceId}]`).join('\n'); + const audioInputs = devicesToStr(deviceList.audioInput); + const audioOutputs = devicesToStr(deviceList.audioOutput); + const videoInputs = devicesToStr(deviceList.videoInput); + + logger.debug('Device list updated:\n' + + `audioInput:\n${audioInputs}\n` + + `audioOutput:\n${audioOutputs}\n` + + `videoInput:\n${videoInputs}`); +} + /** * Implements the middleware of the feature base/devices. * @@ -123,6 +146,9 @@ MiddlewareRegistry.register(store => next => action => { APP.UI.emitEvent(UIEvents.VIDEO_DEVICE_CHANGED, action.deviceId); } break; + case UPDATE_DEVICE_LIST: + logDeviceList(groupDevicesByKind(action.devices)); + break; case CHECK_AND_NOTIFY_FOR_NEW_DEVICE: _checkAndNotifyForNewDevice(store, action.newDevices, action.oldDevices); break; diff --git a/react/features/base/devices/reducer.js b/react/features/base/devices/reducer.js index 206b5e416..1a53c0538 100644 --- a/react/features/base/devices/reducer.js +++ b/react/features/base/devices/reducer.js @@ -19,24 +19,6 @@ const DEFAULT_STATE = { pendingRequests: [] }; -/** - * Logs the current device list. - * - * @param {Object} deviceList - Whatever is returned by {@link groupDevicesByKind}. - * @returns {string} - */ -function logDeviceList(deviceList) { - const devicesToStr = list => list.map(device => `\t\t${device.label}[${device.deviceId}]`).join('\n'); - const audioInputs = devicesToStr(deviceList.audioInput); - const audioOutputs = devicesToStr(deviceList.audioOutput); - const videoInputs = devicesToStr(deviceList.videoInput); - - logger.debug('Device list updated:\n' - + `audioInput:\n${audioInputs}\n` - + `audioOutput:\n${audioOutputs}\n` - + `videoInput:\n${videoInputs}`); -} - /** * Listen for actions which changes the state of known and used devices. * @@ -54,8 +36,6 @@ ReducerRegistry.register( case UPDATE_DEVICE_LIST: { const deviceList = groupDevicesByKind(action.devices); - logDeviceList(deviceList); - return { ...state, availableDevices: deviceList