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

reducer.js 2.9KB

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