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.8KB

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