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 5.4KB

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