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.

reducer.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {
  2. ADD_PENDING_DEVICE_REQUEST,
  3. REMOVE_PENDING_DEVICE_REQUESTS,
  4. SET_AUDIO_INPUT_DEVICE,
  5. SET_VIDEO_INPUT_DEVICE,
  6. UPDATE_DEVICE_LIST
  7. } from './actionTypes';
  8. import { groupDevicesByKind } from './functions';
  9. import { ReducerRegistry } from '../redux';
  10. const DEFAULT_STATE = {
  11. availableDevices: {
  12. audioInput: [],
  13. audioOutput: [],
  14. videoInput: []
  15. },
  16. pendingRequests: []
  17. };
  18. /**
  19. * Listen for actions which changes the state of known and used devices.
  20. *
  21. * @param {Object} state - The Redux state of the feature features/base/devices.
  22. * @param {Object} action - Action object.
  23. * @param {string} action.type - Type of action.
  24. * @param {Array<MediaDeviceInfo>} action.devices - All available audio and
  25. * video devices.
  26. * @returns {Object}
  27. */
  28. ReducerRegistry.register(
  29. 'features/base/devices',
  30. (state = DEFAULT_STATE, action) => {
  31. switch (action.type) {
  32. case UPDATE_DEVICE_LIST: {
  33. const deviceList = groupDevicesByKind(action.devices);
  34. return {
  35. ...state,
  36. availableDevices: deviceList
  37. };
  38. }
  39. case ADD_PENDING_DEVICE_REQUEST:
  40. return {
  41. ...state,
  42. pendingRequests: [
  43. ...state.pendingRequests,
  44. action.request
  45. ]
  46. };
  47. case REMOVE_PENDING_DEVICE_REQUESTS:
  48. return {
  49. ...state,
  50. pendingRequests: [ ]
  51. };
  52. // TODO: Changing of current audio and video device id is currently
  53. // handled outside of react/redux. Fall through to default logic for
  54. // now.
  55. case SET_AUDIO_INPUT_DEVICE:
  56. case SET_VIDEO_INPUT_DEVICE:
  57. default:
  58. return state;
  59. }
  60. });