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.ts 8.9KB

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