fix: store.getState() called while the reducer is executing

This commit is contained in:
paweldomas 2020-06-30 12:48:06 -05:00 committed by Paweł Domas
parent bc43f00d28
commit 1ff27b7298
2 changed files with 28 additions and 22 deletions

View File

@ -15,14 +15,19 @@ import {
NOTIFY_CAMERA_ERROR, NOTIFY_CAMERA_ERROR,
NOTIFY_MIC_ERROR, NOTIFY_MIC_ERROR,
SET_AUDIO_INPUT_DEVICE, SET_AUDIO_INPUT_DEVICE,
SET_VIDEO_INPUT_DEVICE SET_VIDEO_INPUT_DEVICE,
UPDATE_DEVICE_LIST
} from './actionTypes'; } from './actionTypes';
import { import {
removePendingDeviceRequests, removePendingDeviceRequests,
setAudioInputDevice, setAudioInputDevice,
setVideoInputDevice setVideoInputDevice
} from './actions'; } from './actions';
import { formatDeviceLabel, setAudioOutputDeviceId } from './functions'; import {
formatDeviceLabel,
groupDevicesByKind,
setAudioOutputDeviceId
} from './functions';
import logger from './logger'; import logger from './logger';
const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = { 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. * 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); APP.UI.emitEvent(UIEvents.VIDEO_DEVICE_CHANGED, action.deviceId);
} }
break; break;
case UPDATE_DEVICE_LIST:
logDeviceList(groupDevicesByKind(action.devices));
break;
case CHECK_AND_NOTIFY_FOR_NEW_DEVICE: case CHECK_AND_NOTIFY_FOR_NEW_DEVICE:
_checkAndNotifyForNewDevice(store, action.newDevices, action.oldDevices); _checkAndNotifyForNewDevice(store, action.newDevices, action.oldDevices);
break; break;

View File

@ -19,24 +19,6 @@ const DEFAULT_STATE = {
pendingRequests: [] 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. * Listen for actions which changes the state of known and used devices.
* *
@ -54,8 +36,6 @@ ReducerRegistry.register(
case UPDATE_DEVICE_LIST: { case UPDATE_DEVICE_LIST: {
const deviceList = groupDevicesByKind(action.devices); const deviceList = groupDevicesByKind(action.devices);
logDeviceList(deviceList);
return { return {
...state, ...state,
availableDevices: deviceList availableDevices: deviceList