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.2KB

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