Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

actions.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {
  2. SET_AUDIO_MUTED,
  3. SET_CAMERA_FACING_MODE,
  4. SET_VIDEO_MUTED
  5. } from './actionTypes';
  6. import { CAMERA_FACING_MODE } from './constants';
  7. import './middleware';
  8. import './reducer';
  9. /**
  10. * Action to set the muted state of the local audio.
  11. *
  12. * @param {boolean} muted - True if the local audio is to be muted or false if
  13. * the local audio is to be unmuted.
  14. * @returns {{
  15. * type: SET_AUDIO_MUTED,
  16. * muted: boolean
  17. * }}
  18. */
  19. export function setAudioMuted(muted) {
  20. return {
  21. type: SET_AUDIO_MUTED,
  22. muted
  23. };
  24. }
  25. /**
  26. * Action to set the facing mode of the local camera.
  27. *
  28. * @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
  29. * @returns {{
  30. * type: SET_CAMERA_FACING_MODE,
  31. * cameraFacingMode: CAMERA_FACING_MODE
  32. * }}
  33. */
  34. export function setCameraFacingMode(cameraFacingMode) {
  35. return {
  36. type: SET_CAMERA_FACING_MODE,
  37. cameraFacingMode
  38. };
  39. }
  40. /**
  41. * Action to set the muted state of the local video.
  42. *
  43. * @param {boolean} muted - True if the local video is to be muted or false if
  44. * the local video is to be unmuted.
  45. * @returns {{
  46. * type: SET_VIDEO_MUTED,
  47. * muted: boolean
  48. * }}
  49. */
  50. export function setVideoMuted(muted) {
  51. return {
  52. type: SET_VIDEO_MUTED,
  53. muted
  54. };
  55. }
  56. /**
  57. * Toggles the mute state of the local audio track(s).
  58. *
  59. * @returns {Function}
  60. */
  61. export function toggleAudioMuted() {
  62. return (dispatch, getState) => {
  63. const muted = getState()['features/base/media'].audio.muted;
  64. return dispatch(setAudioMuted(!muted));
  65. };
  66. }
  67. /**
  68. * Toggles the camera between front and rear (user and environment).
  69. *
  70. * @returns {Function}
  71. */
  72. export function toggleCameraFacingMode() {
  73. return (dispatch, getState) => {
  74. let cameraFacingMode
  75. = getState()['features/base/media'].video.facingMode;
  76. cameraFacingMode
  77. = cameraFacingMode === CAMERA_FACING_MODE.USER
  78. ? CAMERA_FACING_MODE.ENVIRONMENT
  79. : CAMERA_FACING_MODE.USER;
  80. return dispatch(setCameraFacingMode(cameraFacingMode));
  81. };
  82. }
  83. /**
  84. * Toggles the mute state of the local video track(s).
  85. *
  86. * @returns {Function}
  87. */
  88. export function toggleVideoMuted() {
  89. return (dispatch, getState) => {
  90. const muted = getState()['features/base/media'].video.muted;
  91. return dispatch(setVideoMuted(!muted));
  92. };
  93. }