Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.ts 7.6KB

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