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

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