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

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