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.

actions.js 4.6KB

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