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

actions.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. STORE_VIDEO_TRANSFORM,
  10. TOGGLE_CAMERA_FACING_MODE
  11. } from './actionTypes';
  12. import {
  13. CAMERA_FACING_MODE,
  14. MEDIA_TYPE,
  15. VIDEO_MUTISM_AUTHORITY
  16. } from './constants';
  17. /**
  18. * Action to adjust the availability of the local audio.
  19. *
  20. * @param {boolean} available - True if the local audio is to be marked as
  21. * available or false if the local audio is not available.
  22. * @returns {{
  23. * type: SET_AUDIO_AVAILABLE,
  24. * available: boolean
  25. * }}
  26. */
  27. export function setAudioAvailable(available: boolean) {
  28. return {
  29. type: SET_AUDIO_AVAILABLE,
  30. available
  31. };
  32. }
  33. /**
  34. * Action to set the muted state of the local audio.
  35. *
  36. * @param {boolean} muted - True if the local audio is to be muted or false if
  37. * the local audio is to be unmuted.
  38. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  39. * created if missing.
  40. * @returns {{
  41. * type: SET_AUDIO_MUTED,
  42. * ensureTrack: boolean,
  43. * muted: boolean
  44. * }}
  45. */
  46. export function setAudioMuted(muted: boolean, ensureTrack: boolean = false) {
  47. return {
  48. type: SET_AUDIO_MUTED,
  49. ensureTrack,
  50. muted
  51. };
  52. }
  53. /**
  54. * Action to set the facing mode of the local camera.
  55. *
  56. * @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
  57. * @returns {{
  58. * type: SET_CAMERA_FACING_MODE,
  59. * cameraFacingMode: CAMERA_FACING_MODE
  60. * }}
  61. */
  62. export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
  63. return {
  64. type: SET_CAMERA_FACING_MODE,
  65. cameraFacingMode
  66. };
  67. }
  68. /**
  69. * Action to adjust the availability of the local video.
  70. *
  71. * @param {boolean} available - True if the local video is to be marked as
  72. * available or false if the local video is not available.
  73. * @returns {{
  74. * type: SET_VIDEO_AVAILABLE,
  75. * available: boolean
  76. * }}
  77. */
  78. export function setVideoAvailable(available: boolean) {
  79. return {
  80. type: SET_VIDEO_AVAILABLE,
  81. available
  82. };
  83. }
  84. /**
  85. * Action to set the muted state of the local video.
  86. *
  87. * @param {boolean} muted - True if the local video is to be muted or false if
  88. * the local video is to be unmuted.
  89. * @param {MEDIA_TYPE} mediaType - The type of media.
  90. * @param {number} authority - The {@link VIDEO_MUTISM_AUTHORITY} which is
  91. * muting/unmuting the local video.
  92. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  93. * created if missing.
  94. * @returns {Function}
  95. */
  96. export function setVideoMuted(
  97. muted: boolean,
  98. mediaType: MEDIA_TYPE = MEDIA_TYPE.VIDEO,
  99. authority: number = VIDEO_MUTISM_AUTHORITY.USER,
  100. ensureTrack: boolean = false) {
  101. return (dispatch: Dispatch<any>, getState: Function) => {
  102. const oldValue = getState()['features/base/media'].video.muted;
  103. // eslint-disable-next-line no-bitwise
  104. const newValue = muted ? oldValue | authority : oldValue & ~authority;
  105. return dispatch({
  106. type: SET_VIDEO_MUTED,
  107. authority,
  108. mediaType,
  109. ensureTrack,
  110. muted: newValue
  111. });
  112. };
  113. }
  114. /**
  115. * Creates an action to store the last video {@link Transform} applied to a
  116. * stream.
  117. *
  118. * @param {string} streamId - The ID of the stream.
  119. * @param {Object} transform - The {@code Transform} to store.
  120. * @returns {{
  121. * type: STORE_VIDEO_TRANSFORM,
  122. * streamId: string,
  123. * transform: Object
  124. * }}
  125. */
  126. export function storeVideoTransform(streamId: string, transform: Object) {
  127. return {
  128. type: STORE_VIDEO_TRANSFORM,
  129. streamId,
  130. transform
  131. };
  132. }
  133. /**
  134. * Toggles the camera facing mode. Most commonly, for example, mobile devices
  135. * such as phones have a front/user-facing and a back/environment-facing
  136. * cameras. In contrast to setCameraFacingMode, allows the toggling to be
  137. * optimally and/or natively implemented without the overhead of separate reads
  138. * and writes of the current/effective camera facing mode.
  139. *
  140. * @returns {{
  141. * type: TOGGLE_CAMERA_FACING_MODE
  142. * }}
  143. */
  144. export function toggleCameraFacingMode() {
  145. return {
  146. type: TOGGLE_CAMERA_FACING_MODE
  147. };
  148. }