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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { combineReducers } from 'redux';
  2. import { ReducerRegistry } from '../redux';
  3. import {
  4. AUDIO_MUTED_CHANGED,
  5. CAMERA_FACING_MODE_CHANGED,
  6. VIDEO_MUTED_CHANGED
  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. * @returns {AudioMediaState}
  30. */
  31. function audio(state = AUDIO_INITIAL_MEDIA_STATE, action) {
  32. switch (action.type) {
  33. case AUDIO_MUTED_CHANGED:
  34. return {
  35. ...state,
  36. muted: action.muted
  37. };
  38. default:
  39. return state;
  40. }
  41. }
  42. /**
  43. * Media state object for local video.
  44. *
  45. * @typedef {Object} VideoMediaState
  46. * @property {CAMERA_FACING_MODE} facingMode='user' - Camera facing mode.
  47. * @property {boolean} muted=false - Video muted state.
  48. */
  49. /**
  50. * Initial state for video.
  51. *
  52. * @type {VideoMediaState}
  53. */
  54. const VIDEO_INITIAL_MEDIA_STATE = {
  55. facingMode: CAMERA_FACING_MODE.USER,
  56. muted: false
  57. };
  58. /**
  59. * Reducer for camera media state.
  60. *
  61. * @param {VideoMediaState} state - Media state of local video.
  62. * @param {Object} action - Action object.
  63. * @param {string} action.type - Type of action.
  64. * @returns {VideoMediaState}
  65. */
  66. function video(state = VIDEO_INITIAL_MEDIA_STATE, action) {
  67. switch (action.type) {
  68. case CAMERA_FACING_MODE_CHANGED:
  69. return {
  70. ...state,
  71. facingMode: action.cameraFacingMode
  72. };
  73. case VIDEO_MUTED_CHANGED:
  74. return {
  75. ...state,
  76. muted: action.muted
  77. };
  78. default:
  79. return state;
  80. }
  81. }
  82. /**
  83. * Listen for various actions related to media devices.
  84. *
  85. * @param {Object} state - State of media devices.
  86. * @param {Object} action - Action object.
  87. * @param {string} action.type - Type of action.
  88. * @param {Object} action.media - Information about media devices to be
  89. * modified.
  90. * @returns {Object}
  91. */
  92. ReducerRegistry.register('features/base/media', combineReducers({
  93. audio,
  94. video
  95. }));