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

actions.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import {
  4. SET_AUDIO_MUTED,
  5. SET_AUDIO_AVAILABLE,
  6. SET_CAMERA_FACING_MODE,
  7. SET_VIDEO_AVAILABLE,
  8. SET_VIDEO_MUTED,
  9. TOGGLE_CAMERA_FACING_MODE
  10. } from './actionTypes';
  11. import { CAMERA_FACING_MODE, VIDEO_MUTISM_AUTHORITY } from './constants';
  12. /**
  13. * Action to adjust the availability of the local audio.
  14. *
  15. * @param {boolean} available - True if the local audio is to be marked as
  16. * available or false if the local audio is not available.
  17. * @returns {{
  18. * type: SET_AUDIO_AVAILABLE,
  19. * available: boolean
  20. * }}
  21. */
  22. export function setAudioAvailable(available: boolean) {
  23. return {
  24. type: SET_AUDIO_AVAILABLE,
  25. available
  26. };
  27. }
  28. /**
  29. * Action to set the muted state of the local audio.
  30. *
  31. * @param {boolean} muted - True if the local audio is to be muted or false if
  32. * the local audio is to be unmuted.
  33. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  34. * created if missing.
  35. * @returns {{
  36. * type: SET_AUDIO_MUTED,
  37. * ensureTrack: boolean,
  38. * muted: boolean
  39. * }}
  40. */
  41. export function setAudioMuted(muted: boolean, ensureTrack: boolean = false) {
  42. return {
  43. type: SET_AUDIO_MUTED,
  44. ensureTrack,
  45. muted
  46. };
  47. }
  48. /**
  49. * Action to set the facing mode of the local camera.
  50. *
  51. * @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
  52. * @returns {{
  53. * type: SET_CAMERA_FACING_MODE,
  54. * cameraFacingMode: CAMERA_FACING_MODE
  55. * }}
  56. */
  57. export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
  58. return {
  59. type: SET_CAMERA_FACING_MODE,
  60. cameraFacingMode
  61. };
  62. }
  63. /**
  64. * Action to adjust the availability of the local video.
  65. *
  66. * @param {boolean} available - True if the local video is to be marked as
  67. * available or false if the local video is not available.
  68. * @returns {{
  69. * type: SET_VIDEO_AVAILABLE,
  70. * available: boolean
  71. * }}
  72. */
  73. export function setVideoAvailable(available: boolean) {
  74. return {
  75. type: SET_VIDEO_AVAILABLE,
  76. available
  77. };
  78. }
  79. /**
  80. * Action to set the muted state of the local video.
  81. *
  82. * @param {boolean} muted - True if the local video is to be muted or false if
  83. * the local video is to be unmuted.
  84. * @param {number} authority - The {@link VIDEO_MUTISM_AUTHORITY} which is
  85. * muting/unmuting the local video.
  86. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  87. * created if missing.
  88. * @returns {Function}
  89. */
  90. export function setVideoMuted(
  91. muted: boolean,
  92. authority: number = VIDEO_MUTISM_AUTHORITY.USER,
  93. ensureTrack: boolean = false) {
  94. return (dispatch: Dispatch<*>, getState: Function) => {
  95. const oldValue = getState()['features/base/media'].video.muted;
  96. // eslint-disable-next-line no-bitwise
  97. const newValue = muted ? oldValue | authority : oldValue & ~authority;
  98. return dispatch({
  99. type: SET_VIDEO_MUTED,
  100. ensureTrack,
  101. muted: newValue
  102. });
  103. };
  104. }
  105. /**
  106. * Toggles the camera facing mode. Most commonly, for example, mobile devices
  107. * such as phones have a front/user-facing and a back/environment-facing
  108. * cameras. In contrast to setCameraFacingMode, allows the toggling to be
  109. * optimally and/or natively implemented without the overhead of separate reads
  110. * and writes of the current/effective camera facing mode.
  111. *
  112. * @returns {{
  113. * type: TOGGLE_CAMERA_FACING_MODE
  114. * }}
  115. */
  116. export function toggleCameraFacingMode() {
  117. return {
  118. type: TOGGLE_CAMERA_FACING_MODE
  119. };
  120. }