Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.js 2.5KB

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