Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.ts 7.3KB

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