您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reducer.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { combineReducers } from 'redux';
  2. import { ReducerRegistry } from '../redux';
  3. import {
  4. SET_AUDIO_MUTED,
  5. SET_CAMERA_FACING_MODE,
  6. SET_VIDEO_MUTED
  7. } from './actionTypes';
  8. import { CAMERA_FACING_MODE } from './constants';
  9. /**
  10. * Media state object for local audio.
  11. *
  12. * @typedef {Object} AudioMediaState
  13. * @property {boolean} muted=false - Audio muted state.
  14. */
  15. /**
  16. * Initial state for local audio.
  17. *
  18. * @type {AudioMediaState}
  19. */
  20. const AUDIO_INITIAL_MEDIA_STATE = {
  21. muted: false
  22. };
  23. /**
  24. * Reducer for audio media state.
  25. *
  26. * @param {AudioMediaState} state - Media state of local audio.
  27. * @param {Object} action - Action object.
  28. * @param {string} action.type - Type of action.
  29. * @private
  30. * @returns {AudioMediaState}
  31. */
  32. function _audio(state = AUDIO_INITIAL_MEDIA_STATE, action) {
  33. switch (action.type) {
  34. case SET_AUDIO_MUTED:
  35. return {
  36. ...state,
  37. muted: action.muted
  38. };
  39. default:
  40. return state;
  41. }
  42. }
  43. /**
  44. * Media state object for local video.
  45. *
  46. * @typedef {Object} VideoMediaState
  47. * @property {CAMERA_FACING_MODE} facingMode='user' - Camera facing mode.
  48. * @property {boolean} muted=false - Video muted state.
  49. */
  50. /**
  51. * Initial state for video.
  52. *
  53. * @type {VideoMediaState}
  54. */
  55. const VIDEO_INITIAL_MEDIA_STATE = {
  56. facingMode: CAMERA_FACING_MODE.USER,
  57. muted: false
  58. };
  59. /**
  60. * Reducer for camera media state.
  61. *
  62. * @param {VideoMediaState} state - Media state of local video.
  63. * @param {Object} action - Action object.
  64. * @param {string} action.type - Type of action.
  65. * @private
  66. * @returns {VideoMediaState}
  67. */
  68. function _video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
  69. switch (action.type) {
  70. case SET_CAMERA_FACING_MODE:
  71. return {
  72. ...state,
  73. facingMode: action.cameraFacingMode
  74. };
  75. case SET_VIDEO_MUTED:
  76. return {
  77. ...state,
  78. muted: action.muted
  79. };
  80. default:
  81. return state;
  82. }
  83. }
  84. /**
  85. * Listen for various actions related to media devices.
  86. *
  87. * @param {Object} state - State of media devices.
  88. * @param {Object} action - Action object.
  89. * @param {string} action.type - Type of action.
  90. * @param {Object} action.media - Information about media devices to be
  91. * modified.
  92. * @returns {Object}
  93. */
  94. ReducerRegistry.register('features/base/media', combineReducers({
  95. audio: _audio,
  96. video: _video
  97. }));