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.

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