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