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

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