Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

reducer.ts 2.6KB

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