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.ts 7.0KB

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