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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // @flow
  2. import { getConferenceState } from '../base/conference';
  3. import { MEDIA_TYPE, type MediaType } from '../base/media/constants';
  4. import { getParticipantById, isParticipantModerator } from '../base/participants';
  5. import { isForceMuted } from '../participants-pane/functions';
  6. import {
  7. DISMISS_PENDING_PARTICIPANT,
  8. DISABLE_MODERATION,
  9. ENABLE_MODERATION,
  10. LOCAL_PARTICIPANT_APPROVED,
  11. LOCAL_PARTICIPANT_MODERATION_NOTIFICATION,
  12. PARTICIPANT_APPROVED,
  13. PARTICIPANT_PENDING_AUDIO,
  14. REQUEST_DISABLE_AUDIO_MODERATION,
  15. REQUEST_ENABLE_AUDIO_MODERATION,
  16. REQUEST_DISABLE_VIDEO_MODERATION,
  17. REQUEST_ENABLE_VIDEO_MODERATION,
  18. LOCAL_PARTICIPANT_REJECTED,
  19. PARTICIPANT_REJECTED
  20. } from './actionTypes';
  21. import { isEnabledFromState } from './functions';
  22. /**
  23. * Action used by moderator to approve audio and video for a participant.
  24. *
  25. * @param {staring} id - The id of the participant to be approved.
  26. * @returns {void}
  27. */
  28. export const approveParticipant = (id: string) => (dispatch: Function, getState: Function) => {
  29. const state = getState();
  30. const { conference } = getConferenceState(state);
  31. const participant = getParticipantById(state, id);
  32. const isAudioForceMuted = isForceMuted(participant, MEDIA_TYPE.AUDIO, state);
  33. const isVideoForceMuted = isForceMuted(participant, MEDIA_TYPE.VIDEO, state);
  34. const isAudioModerationOn = isEnabledFromState(MEDIA_TYPE.AUDIO, state);
  35. const isVideoModerationOn = isEnabledFromState(MEDIA_TYPE.VIDEO, state);
  36. if (!(isAudioModerationOn || isVideoModerationOn) || (isAudioModerationOn && isAudioForceMuted)) {
  37. conference.avModerationApprove(MEDIA_TYPE.AUDIO, id);
  38. }
  39. if (isVideoModerationOn && isVideoForceMuted) {
  40. conference.avModerationApprove(MEDIA_TYPE.VIDEO, id);
  41. }
  42. };
  43. /**
  44. * Action used by moderator to reject audio for a participant.
  45. *
  46. * @param {staring} id - The id of the participant to be rejected.
  47. * @returns {void}
  48. */
  49. export const rejectParticipantAudio = (id: string) => (dispatch: Function, getState: Function) => {
  50. const state = getState();
  51. const { conference } = getConferenceState(state);
  52. const audioModeration = isEnabledFromState(MEDIA_TYPE.AUDIO, state);
  53. const participant = getParticipantById(state, id);
  54. const isAudioForceMuted = isForceMuted(participant, MEDIA_TYPE.AUDIO, state);
  55. const isModerator = isParticipantModerator(participant);
  56. if (audioModeration && !isAudioForceMuted && !isModerator) {
  57. conference.avModerationReject(MEDIA_TYPE.AUDIO, id);
  58. }
  59. };
  60. /**
  61. * Action used by moderator to reject video for a participant.
  62. *
  63. * @param {staring} id - The id of the participant to be rejected.
  64. * @returns {void}
  65. */
  66. export const rejectParticipantVideo = (id: string) => (dispatch: Function, getState: Function) => {
  67. const state = getState();
  68. const { conference } = getConferenceState(state);
  69. const videoModeration = isEnabledFromState(MEDIA_TYPE.VIDEO, state);
  70. const participant = getParticipantById(state, id);
  71. const isVideoForceMuted = isForceMuted(participant, MEDIA_TYPE.VIDEO, state);
  72. const isModerator = isParticipantModerator(participant);
  73. if (videoModeration && !isVideoForceMuted && !isModerator) {
  74. conference.avModerationReject(MEDIA_TYPE.VIDEO, id);
  75. }
  76. };
  77. /**
  78. * Audio or video moderation is disabled.
  79. *
  80. * @param {MediaType} mediaType - The media type that was disabled.
  81. * @param {JitsiParticipant} actor - The actor disabling.
  82. * @returns {{
  83. * type: REQUEST_DISABLE_MODERATED_AUDIO
  84. * }}
  85. */
  86. export const disableModeration = (mediaType: MediaType, actor: Object) => {
  87. return {
  88. type: DISABLE_MODERATION,
  89. mediaType,
  90. actor
  91. };
  92. };
  93. /**
  94. * Hides the notification with the participant that asked to unmute audio.
  95. *
  96. * @param {Object} participant - The participant for which the notification to be hidden.
  97. * @returns {Object}
  98. */
  99. export function dismissPendingAudioParticipant(participant: Object) {
  100. return dismissPendingParticipant(participant.id, MEDIA_TYPE.AUDIO);
  101. }
  102. /**
  103. * Hides the notification with the participant that asked to unmute.
  104. *
  105. * @param {string} id - The participant id for which the notification to be hidden.
  106. * @param {MediaType} mediaType - The media type.
  107. * @returns {Object}
  108. */
  109. export function dismissPendingParticipant(id: string, mediaType: MediaType) {
  110. return {
  111. type: DISMISS_PENDING_PARTICIPANT,
  112. id,
  113. mediaType
  114. };
  115. }
  116. /**
  117. * Audio or video moderation is enabled.
  118. *
  119. * @param {MediaType} mediaType - The media type that was enabled.
  120. * @param {JitsiParticipant} actor - The actor enabling.
  121. * @returns {{
  122. * type: REQUEST_ENABLE_MODERATED_AUDIO
  123. * }}
  124. */
  125. export const enableModeration = (mediaType: MediaType, actor: Object) => {
  126. return {
  127. type: ENABLE_MODERATION,
  128. mediaType,
  129. actor
  130. };
  131. };
  132. /**
  133. * Requests disable of audio moderation.
  134. *
  135. * @returns {{
  136. * type: REQUEST_DISABLE_AUDIO_MODERATION
  137. * }}
  138. */
  139. export const requestDisableAudioModeration = () => {
  140. return {
  141. type: REQUEST_DISABLE_AUDIO_MODERATION
  142. };
  143. };
  144. /**
  145. * Requests disable of video moderation.
  146. *
  147. * @returns {{
  148. * type: REQUEST_DISABLE_VIDEO_MODERATION
  149. * }}
  150. */
  151. export const requestDisableVideoModeration = () => {
  152. return {
  153. type: REQUEST_DISABLE_VIDEO_MODERATION
  154. };
  155. };
  156. /**
  157. * Requests enable of audio moderation.
  158. *
  159. * @returns {{
  160. * type: REQUEST_ENABLE_AUDIO_MODERATION
  161. * }}
  162. */
  163. export const requestEnableAudioModeration = () => {
  164. return {
  165. type: REQUEST_ENABLE_AUDIO_MODERATION
  166. };
  167. };
  168. /**
  169. * Requests enable of video moderation.
  170. *
  171. * @returns {{
  172. * type: REQUEST_ENABLE_VIDEO_MODERATION
  173. * }}
  174. */
  175. export const requestEnableVideoModeration = () => {
  176. return {
  177. type: REQUEST_ENABLE_VIDEO_MODERATION
  178. };
  179. };
  180. /**
  181. * Local participant was approved to be able to unmute audio and video.
  182. *
  183. * @param {MediaType} mediaType - The media type to disable.
  184. * @returns {{
  185. * type: LOCAL_PARTICIPANT_APPROVED
  186. * }}
  187. */
  188. export const localParticipantApproved = (mediaType: MediaType) => {
  189. return {
  190. type: LOCAL_PARTICIPANT_APPROVED,
  191. mediaType
  192. };
  193. };
  194. /**
  195. * Local participant was blocked to be able to unmute audio and video.
  196. *
  197. * @param {MediaType} mediaType - The media type to disable.
  198. * @returns {{
  199. * type: LOCAL_PARTICIPANT_REJECTED
  200. * }}
  201. */
  202. export const localParticipantRejected = (mediaType: MediaType) => {
  203. return {
  204. type: LOCAL_PARTICIPANT_REJECTED,
  205. mediaType
  206. };
  207. };
  208. /**
  209. * Shows notification when A/V moderation is enabled and local participant is still not approved.
  210. *
  211. * @param {MediaType} mediaType - Audio or video media type.
  212. * @returns {Object}
  213. */
  214. export function showModeratedNotification(mediaType: MediaType) {
  215. return {
  216. type: LOCAL_PARTICIPANT_MODERATION_NOTIFICATION,
  217. mediaType
  218. };
  219. }
  220. /**
  221. * Shows a notification with the participant that asked to audio unmute.
  222. *
  223. * @param {Object} participant - The participant for which is the notification.
  224. * @returns {Object}
  225. */
  226. export function participantPendingAudio(participant: Object) {
  227. return {
  228. type: PARTICIPANT_PENDING_AUDIO,
  229. participant
  230. };
  231. }
  232. /**
  233. * A participant was approved to unmute for a mediaType.
  234. *
  235. * @param {string} id - The id of the approved participant.
  236. * @param {MediaType} mediaType - The media type which was approved.
  237. * @returns {{
  238. * type: PARTICIPANT_APPROVED,
  239. * }}
  240. */
  241. export function participantApproved(id: string, mediaType: MediaType) {
  242. return {
  243. type: PARTICIPANT_APPROVED,
  244. id,
  245. mediaType
  246. };
  247. }
  248. /**
  249. * A participant was blocked to unmute for a mediaType.
  250. *
  251. * @param {string} id - The id of the approved participant.
  252. * @param {MediaType} mediaType - The media type which was approved.
  253. * @returns {{
  254. * type: PARTICIPANT_REJECTED,
  255. * }}
  256. */
  257. export function participantRejected(id: string, mediaType: MediaType) {
  258. return {
  259. type: PARTICIPANT_REJECTED,
  260. id,
  261. mediaType
  262. };
  263. }