Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.web.ts 2.3KB

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