2019-03-28 12:21:38 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-06-04 03:12:04 +00:00
|
|
|
import { UPDATE_DEVICE_LIST } from '../base/devices';
|
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
|
|
|
|
2019-03-28 12:21:38 +00:00
|
|
|
declare var APP: Object;
|
|
|
|
|
2017-06-04 03:12:04 +00:00
|
|
|
/**
|
|
|
|
* Implements the middleware of the feature device-selection.
|
|
|
|
*
|
|
|
|
* @param {Store} store - Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
if (action.type === UPDATE_DEVICE_LIST) {
|
2019-03-28 12:21:38 +00:00
|
|
|
const state = store.getState();
|
|
|
|
const { popupDialogData } = state['features/device-selection'];
|
2019-03-28 16:29:30 +00:00
|
|
|
const { availableDevices } = state['features/base/devices'];
|
2017-06-04 03:12:04 +00:00
|
|
|
|
|
|
|
if (popupDialogData) {
|
2019-03-28 12:21:38 +00:00
|
|
|
popupDialogData.transport.sendEvent({
|
|
|
|
name: 'deviceListChanged',
|
2019-03-28 16:29:30 +00:00
|
|
|
devices: availableDevices
|
2019-03-28 12:21:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof APP !== 'undefined') {
|
2019-03-28 16:29:30 +00:00
|
|
|
APP.API.notifyDeviceListChanged(availableDevices);
|
2017-06-04 03:12:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|