Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

actions.js 8.5KB

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