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 2.0KB

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