You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* global APP */
  2. import { CONFERENCE_JOINED } from '../conference';
  3. import { processExternalDeviceRequest } from '../../device-selection';
  4. import { MiddlewareRegistry } from '../redux';
  5. import UIEvents from '../../../../service/UI/UIEvents';
  6. import { removePendingDeviceRequests } from './actions';
  7. import {
  8. SET_AUDIO_INPUT_DEVICE,
  9. SET_VIDEO_INPUT_DEVICE
  10. } from './actionTypes';
  11. /**
  12. * Implements the middleware of the feature base/devices.
  13. *
  14. * @param {Store} store - Redux store.
  15. * @returns {Function}
  16. */
  17. // eslint-disable-next-line no-unused-vars
  18. MiddlewareRegistry.register(store => next => action => {
  19. switch (action.type) {
  20. case CONFERENCE_JOINED:
  21. return _conferenceJoined(store, next, action);
  22. case SET_AUDIO_INPUT_DEVICE:
  23. APP.UI.emitEvent(UIEvents.AUDIO_DEVICE_CHANGED, action.deviceId);
  24. break;
  25. case SET_VIDEO_INPUT_DEVICE:
  26. APP.UI.emitEvent(UIEvents.VIDEO_DEVICE_CHANGED, action.deviceId);
  27. break;
  28. }
  29. return next(action);
  30. });
  31. /**
  32. * Does extra sync up on properties that may need to be updated after the
  33. * conference was joined.
  34. *
  35. * @param {Store} store - The redux store in which the specified {@code action}
  36. * is being dispatched.
  37. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  38. * specified {@code action} to the specified {@code store}.
  39. * @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is
  40. * being dispatched in the specified {@code store}.
  41. * @private
  42. * @returns {Object} The value returned by {@code next(action)}.
  43. */
  44. function _conferenceJoined({ dispatch, getState }, next, action) {
  45. const result = next(action);
  46. const state = getState();
  47. const { pendingRequests } = state['features/base/devices'];
  48. pendingRequests.forEach(request => {
  49. processExternalDeviceRequest(
  50. dispatch,
  51. getState,
  52. request,
  53. request.responseCallback);
  54. });
  55. dispatch(removePendingDeviceRequests());
  56. return result;
  57. }