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.

middleware.ts 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. import i18n from 'i18next';
  2. import { batch } from 'react-redux';
  3. import { AnyAction } from 'redux';
  4. import { IStore } from '../../app/types';
  5. import { approveParticipant } from '../../av-moderation/actions';
  6. import { UPDATE_BREAKOUT_ROOMS } from '../../breakout-rooms/actionTypes';
  7. import { getBreakoutRooms } from '../../breakout-rooms/functions';
  8. import { toggleE2EE } from '../../e2ee/actions';
  9. import { MAX_MODE } from '../../e2ee/constants';
  10. import { showNotification } from '../../notifications/actions';
  11. import {
  12. LOCAL_RECORDING_NOTIFICATION_ID,
  13. NOTIFICATION_TIMEOUT_TYPE,
  14. RAISE_HAND_NOTIFICATION_ID
  15. } from '../../notifications/constants';
  16. import { isForceMuted } from '../../participants-pane/functions';
  17. import { CALLING, INVITED } from '../../presence-status/constants';
  18. import { RAISE_HAND_SOUND_ID } from '../../reactions/constants';
  19. import { RECORDING_OFF_SOUND_ID, RECORDING_ON_SOUND_ID } from '../../recording/constants';
  20. import { changeLocalDisplayName } from '../../settings/actions';
  21. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app/actionTypes';
  22. import { CONFERENCE_WILL_JOIN } from '../conference/actionTypes';
  23. import { forEachConference, getCurrentConference } from '../conference/functions';
  24. import { IJitsiConference } from '../conference/reducer';
  25. import { SET_CONFIG } from '../config/actionTypes';
  26. import { getDisableRemoveRaisedHandOnFocus } from '../config/functions.any';
  27. import { JitsiConferenceEvents } from '../lib-jitsi-meet';
  28. import { MEDIA_TYPE } from '../media/constants';
  29. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  30. import StateListenerRegistry from '../redux/StateListenerRegistry';
  31. import { playSound, registerSound, unregisterSound } from '../sounds/actions';
  32. import {
  33. DOMINANT_SPEAKER_CHANGED,
  34. GRANT_MODERATOR,
  35. KICK_PARTICIPANT,
  36. LOCAL_PARTICIPANT_AUDIO_LEVEL_CHANGED,
  37. LOCAL_PARTICIPANT_RAISE_HAND,
  38. MUTE_REMOTE_PARTICIPANT,
  39. OVERWRITE_PARTICIPANTS_NAMES,
  40. OVERWRITE_PARTICIPANT_NAME,
  41. PARTICIPANT_DISPLAY_NAME_CHANGED,
  42. PARTICIPANT_JOINED,
  43. PARTICIPANT_LEFT,
  44. PARTICIPANT_UPDATED,
  45. RAISE_HAND_UPDATED,
  46. SET_LOCAL_PARTICIPANT_RECORDING_STATUS
  47. } from './actionTypes';
  48. import {
  49. localParticipantIdChanged,
  50. localParticipantJoined,
  51. localParticipantLeft,
  52. overwriteParticipantName,
  53. participantLeft,
  54. participantUpdated,
  55. raiseHand,
  56. raiseHandUpdateQueue,
  57. setLoadableAvatarUrl
  58. } from './actions';
  59. import {
  60. LOCAL_PARTICIPANT_DEFAULT_ID,
  61. LOWER_HAND_AUDIO_LEVEL,
  62. PARTICIPANT_JOINED_SOUND_ID,
  63. PARTICIPANT_LEFT_SOUND_ID
  64. } from './constants';
  65. import {
  66. getDominantSpeakerParticipant,
  67. getFirstLoadableAvatarUrl,
  68. getLocalParticipant,
  69. getParticipantById,
  70. getParticipantCount,
  71. getParticipantDisplayName,
  72. getRaiseHandsQueue,
  73. getRemoteParticipants,
  74. hasRaisedHand,
  75. isLocalParticipantModerator,
  76. isScreenShareParticipant,
  77. isWhiteboardParticipant
  78. } from './functions';
  79. import logger from './logger';
  80. import { PARTICIPANT_JOINED_FILE, PARTICIPANT_LEFT_FILE } from './sounds';
  81. import { IJitsiParticipant } from './types';
  82. import './subscriber';
  83. /**
  84. * Middleware that captures CONFERENCE_JOINED and CONFERENCE_LEFT actions and
  85. * updates respectively ID of local participant.
  86. *
  87. * @param {Store} store - The redux store.
  88. * @returns {Function}
  89. */
  90. MiddlewareRegistry.register(store => next => action => {
  91. switch (action.type) {
  92. case APP_WILL_MOUNT:
  93. _registerSounds(store);
  94. return _localParticipantJoined(store, next, action);
  95. case APP_WILL_UNMOUNT:
  96. _unregisterSounds(store);
  97. return _localParticipantLeft(store, next, action);
  98. case CONFERENCE_WILL_JOIN:
  99. store.dispatch(localParticipantIdChanged(action.conference.myUserId()));
  100. break;
  101. case DOMINANT_SPEAKER_CHANGED: {
  102. // Lower hand through xmpp when local participant becomes dominant speaker.
  103. const { id } = action.participant;
  104. const state = store.getState();
  105. const participant = getLocalParticipant(state);
  106. const dominantSpeaker = getDominantSpeakerParticipant(state);
  107. const isLocal = participant && participant.id === id;
  108. if (isLocal && dominantSpeaker?.id !== id
  109. && hasRaisedHand(participant)
  110. && !getDisableRemoveRaisedHandOnFocus(state)) {
  111. store.dispatch(raiseHand(false));
  112. }
  113. break;
  114. }
  115. case LOCAL_PARTICIPANT_AUDIO_LEVEL_CHANGED: {
  116. const state = store.getState();
  117. const participant = getDominantSpeakerParticipant(state);
  118. if (
  119. participant?.local
  120. && hasRaisedHand(participant)
  121. && action.level > LOWER_HAND_AUDIO_LEVEL
  122. && !getDisableRemoveRaisedHandOnFocus(state)
  123. ) {
  124. store.dispatch(raiseHand(false));
  125. }
  126. break;
  127. }
  128. case GRANT_MODERATOR: {
  129. const { conference } = store.getState()['features/base/conference'];
  130. conference?.grantOwner(action.id);
  131. break;
  132. }
  133. case KICK_PARTICIPANT: {
  134. const { conference } = store.getState()['features/base/conference'];
  135. conference?.kickParticipant(action.id);
  136. break;
  137. }
  138. case LOCAL_PARTICIPANT_RAISE_HAND: {
  139. const { raisedHandTimestamp } = action;
  140. const localId = getLocalParticipant(store.getState())?.id;
  141. store.dispatch(participantUpdated({
  142. // XXX Only the local participant is allowed to update without
  143. // stating the JitsiConference instance (i.e. participant property
  144. // `conference` for a remote participant) because the local
  145. // participant is uniquely identified by the very fact that there is
  146. // only one local participant.
  147. id: localId ?? '',
  148. local: true,
  149. raisedHandTimestamp
  150. }));
  151. store.dispatch(raiseHandUpdateQueue({
  152. id: localId ?? '',
  153. raisedHandTimestamp
  154. }));
  155. if (typeof APP !== 'undefined') {
  156. APP.API.notifyRaiseHandUpdated(localId, raisedHandTimestamp);
  157. }
  158. break;
  159. }
  160. case SET_CONFIG: {
  161. const result = next(action);
  162. const state = store.getState();
  163. const { deploymentInfo } = state['features/base/config'];
  164. // if there userRegion set let's use it for the local participant
  165. if (deploymentInfo?.userRegion) {
  166. const localId = getLocalParticipant(state)?.id;
  167. if (localId) {
  168. store.dispatch(participantUpdated({
  169. id: localId,
  170. local: true,
  171. region: deploymentInfo.userRegion
  172. }));
  173. }
  174. }
  175. return result;
  176. }
  177. case SET_LOCAL_PARTICIPANT_RECORDING_STATUS: {
  178. const state = store.getState();
  179. const { recording, onlySelf } = action;
  180. const localId = getLocalParticipant(state)?.id;
  181. const { localRecording } = state['features/base/config'];
  182. if (localRecording?.notifyAllParticipants && !onlySelf && localId) {
  183. store.dispatch(participantUpdated({
  184. // XXX Only the local participant is allowed to update without
  185. // stating the JitsiConference instance (i.e. participant property
  186. // `conference` for a remote participant) because the local
  187. // participant is uniquely identified by the very fact that there is
  188. // only one local participant.
  189. id: localId,
  190. local: true,
  191. localRecording: recording
  192. }));
  193. }
  194. break;
  195. }
  196. case MUTE_REMOTE_PARTICIPANT: {
  197. const { conference } = store.getState()['features/base/conference'];
  198. conference?.muteParticipant(action.id, action.mediaType);
  199. break;
  200. }
  201. // TODO Remove this middleware when the local display name update flow is
  202. // fully brought into redux.
  203. case PARTICIPANT_DISPLAY_NAME_CHANGED: {
  204. if (typeof APP !== 'undefined') {
  205. const participant = getLocalParticipant(store.getState());
  206. if (participant && participant.id === action.id) {
  207. store.dispatch(changeLocalDisplayName(action.name));
  208. }
  209. }
  210. break;
  211. }
  212. case RAISE_HAND_UPDATED: {
  213. const { participant } = action;
  214. let queue = getRaiseHandsQueue(store.getState());
  215. if (participant.raisedHandTimestamp) {
  216. queue.push({
  217. id: participant.id,
  218. raisedHandTimestamp: participant.raisedHandTimestamp
  219. });
  220. // sort the queue before adding to store.
  221. queue = queue.sort(({ raisedHandTimestamp: a }, { raisedHandTimestamp: b }) => a - b);
  222. } else {
  223. // no need to sort on remove value.
  224. queue = queue.filter(({ id }) => id !== participant.id);
  225. }
  226. action.queue = queue;
  227. break;
  228. }
  229. case PARTICIPANT_JOINED: {
  230. // Do not play sounds when a screenshare or whiteboard participant tile is created for screenshare.
  231. (!isScreenShareParticipant(action.participant)
  232. && !isWhiteboardParticipant(action.participant)
  233. ) && _maybePlaySounds(store, action);
  234. return _participantJoinedOrUpdated(store, next, action);
  235. }
  236. case PARTICIPANT_LEFT: {
  237. // Do not play sounds when a tile for screenshare or whiteboard is removed.
  238. (!isScreenShareParticipant(action.participant)
  239. && !isWhiteboardParticipant(action.participant)
  240. ) && _maybePlaySounds(store, action);
  241. break;
  242. }
  243. case PARTICIPANT_UPDATED:
  244. return _participantJoinedOrUpdated(store, next, action);
  245. case OVERWRITE_PARTICIPANTS_NAMES: {
  246. const { participantList } = action;
  247. if (!Array.isArray(participantList)) {
  248. logger.error('Overwrite names failed. Argument is not an array.');
  249. return;
  250. }
  251. batch(() => {
  252. participantList.forEach(p => {
  253. store.dispatch(overwriteParticipantName(p.id, p.name));
  254. });
  255. });
  256. break;
  257. }
  258. case OVERWRITE_PARTICIPANT_NAME: {
  259. const { dispatch, getState } = store;
  260. const state = getState();
  261. const { id, name } = action;
  262. let breakoutRoom = false, identifier = id;
  263. if (id.indexOf('@') !== -1) {
  264. identifier = id.slice(id.indexOf('/') + 1);
  265. breakoutRoom = true;
  266. action.id = identifier;
  267. }
  268. if (breakoutRoom) {
  269. const rooms = getBreakoutRooms(state);
  270. const roomCounter = state['features/breakout-rooms'].roomCounter;
  271. const newRooms: any = {};
  272. Object.entries(rooms).forEach(([ key, r ]) => {
  273. const participants = r?.participants || {};
  274. const jid = Object.keys(participants).find(p =>
  275. p.slice(p.indexOf('/') + 1) === identifier);
  276. if (jid) {
  277. newRooms[key] = {
  278. ...r,
  279. participants: {
  280. ...participants,
  281. [jid]: {
  282. ...participants[jid],
  283. displayName: name
  284. }
  285. }
  286. };
  287. } else {
  288. newRooms[key] = r;
  289. }
  290. });
  291. dispatch({
  292. type: UPDATE_BREAKOUT_ROOMS,
  293. rooms,
  294. roomCounter,
  295. updatedNames: true
  296. });
  297. } else {
  298. dispatch(participantUpdated({
  299. id: identifier,
  300. name
  301. }));
  302. }
  303. break;
  304. }
  305. }
  306. return next(action);
  307. });
  308. /**
  309. * Syncs the redux state features/base/participants up with the redux state
  310. * features/base/conference by ensuring that the former does not contain remote
  311. * participants no longer relevant to the latter. Introduced to address an issue
  312. * with multiplying thumbnails in the filmstrip.
  313. */
  314. StateListenerRegistry.register(
  315. /* selector */ state => getCurrentConference(state),
  316. /* listener */ (conference, { dispatch, getState }) => {
  317. batch(() => {
  318. for (const [ id, p ] of getRemoteParticipants(getState())) {
  319. (!conference || p.conference !== conference)
  320. && dispatch(participantLeft(id, p.conference, {
  321. isReplaced: p.isReplaced
  322. }));
  323. }
  324. });
  325. });
  326. /**
  327. * Reset the ID of the local participant to
  328. * {@link LOCAL_PARTICIPANT_DEFAULT_ID}. Such a reset is deemed possible only if
  329. * the local participant and, respectively, her ID is not involved in a
  330. * conference which is still of interest to the user and, consequently, the app.
  331. * For example, a conference which is in the process of leaving is no longer of
  332. * interest the user, is unrecoverable from the perspective of the user and,
  333. * consequently, the app.
  334. */
  335. StateListenerRegistry.register(
  336. /* selector */ state => state['features/base/conference'],
  337. /* listener */ ({ leaving }, { dispatch, getState }) => {
  338. const state = getState();
  339. const localParticipant = getLocalParticipant(state);
  340. let id: string;
  341. if (!localParticipant
  342. || (id = localParticipant.id)
  343. === LOCAL_PARTICIPANT_DEFAULT_ID) {
  344. // The ID of the local participant has been reset already.
  345. return;
  346. }
  347. // The ID of the local may be reset only if it is not in use.
  348. const dispatchLocalParticipantIdChanged
  349. = forEachConference(
  350. state,
  351. conference =>
  352. conference === leaving || conference.myUserId() !== id);
  353. dispatchLocalParticipantIdChanged
  354. && dispatch(
  355. localParticipantIdChanged(LOCAL_PARTICIPANT_DEFAULT_ID));
  356. });
  357. /**
  358. * Registers listeners for participant change events.
  359. */
  360. StateListenerRegistry.register(
  361. state => state['features/base/conference'].conference,
  362. (conference, store) => {
  363. if (conference) {
  364. const propertyHandlers: {
  365. [key: string]: Function;
  366. } = {
  367. 'e2ee.enabled': (participant: IJitsiParticipant, value: string) =>
  368. _e2eeUpdated(store, conference, participant.getId(), value),
  369. 'features_e2ee': (participant: IJitsiParticipant, value: boolean) =>
  370. getParticipantById(store.getState(), participant.getId())?.e2eeSupported !== value
  371. && store.dispatch(participantUpdated({
  372. conference,
  373. id: participant.getId(),
  374. e2eeSupported: value
  375. })),
  376. 'features_jigasi': (participant: IJitsiParticipant, value: boolean) =>
  377. store.dispatch(participantUpdated({
  378. conference,
  379. id: participant.getId(),
  380. isJigasi: value
  381. })),
  382. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  383. 'features_screen-sharing': (participant: IJitsiParticipant, value: string) =>
  384. store.dispatch(participantUpdated({
  385. conference,
  386. id: participant.getId(),
  387. features: { 'screen-sharing': true }
  388. })),
  389. 'localRecording': (participant: IJitsiParticipant, value: string) =>
  390. _localRecordingUpdated(store, conference, participant.getId(), value),
  391. 'raisedHand': (participant: IJitsiParticipant, value: string) =>
  392. _raiseHandUpdated(store, conference, participant.getId(), value),
  393. 'region': (participant: IJitsiParticipant, value: string) =>
  394. store.dispatch(participantUpdated({
  395. conference,
  396. id: participant.getId(),
  397. region: value
  398. })),
  399. 'remoteControlSessionStatus': (participant: IJitsiParticipant, value: boolean) =>
  400. store.dispatch(participantUpdated({
  401. conference,
  402. id: participant.getId(),
  403. remoteControlSessionStatus: value
  404. }))
  405. };
  406. // update properties for the participants that are already in the conference
  407. conference.getParticipants().forEach((participant: any) => {
  408. Object.keys(propertyHandlers).forEach(propertyName => {
  409. const value = participant.getProperty(propertyName);
  410. if (value !== undefined) {
  411. propertyHandlers[propertyName as keyof typeof propertyHandlers](participant, value);
  412. }
  413. });
  414. });
  415. // We joined a conference
  416. conference.on(
  417. JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
  418. (participant: IJitsiParticipant, propertyName: string, oldValue: string, newValue: string) => {
  419. if (propertyHandlers.hasOwnProperty(propertyName)) {
  420. propertyHandlers[propertyName](participant, newValue);
  421. }
  422. });
  423. } else {
  424. const localParticipantId = getLocalParticipant(store.getState)?.id;
  425. // We left the conference, the local participant must be updated.
  426. _e2eeUpdated(store, conference, localParticipantId ?? '', false);
  427. _raiseHandUpdated(store, conference, localParticipantId ?? '', 0);
  428. }
  429. }
  430. );
  431. /**
  432. * Handles a E2EE enabled status update.
  433. *
  434. * @param {Store} store - The redux store.
  435. * @param {Object} conference - The conference for which we got an update.
  436. * @param {string} participantId - The ID of the participant from which we got an update.
  437. * @param {boolean} newValue - The new value of the E2EE enabled status.
  438. * @returns {void}
  439. */
  440. function _e2eeUpdated({ getState, dispatch }: IStore, conference: IJitsiConference,
  441. participantId: string, newValue: string | boolean) {
  442. const e2eeEnabled = newValue === 'true';
  443. const state = getState();
  444. const { e2ee = {} } = state['features/base/config'];
  445. if (e2eeEnabled === getParticipantById(state, participantId)?.e2eeEnabled) {
  446. return;
  447. }
  448. dispatch(participantUpdated({
  449. conference,
  450. id: participantId,
  451. e2eeEnabled
  452. }));
  453. if (e2ee.externallyManagedKey) {
  454. return;
  455. }
  456. const { maxMode } = getState()['features/e2ee'] || {};
  457. if (maxMode !== MAX_MODE.THRESHOLD_EXCEEDED || !e2eeEnabled) {
  458. dispatch(toggleE2EE(e2eeEnabled));
  459. }
  460. }
  461. /**
  462. * Initializes the local participant and signals that it joined.
  463. *
  464. * @private
  465. * @param {Store} store - The redux store.
  466. * @param {Dispatch} next - The redux dispatch function to dispatch the
  467. * specified action to the specified store.
  468. * @param {Action} action - The redux action which is being dispatched
  469. * in the specified store.
  470. * @private
  471. * @returns {Object} The value returned by {@code next(action)}.
  472. */
  473. function _localParticipantJoined({ getState, dispatch }: IStore, next: Function, action: AnyAction) {
  474. const result = next(action);
  475. const settings = getState()['features/base/settings'];
  476. dispatch(localParticipantJoined({
  477. avatarURL: settings.avatarURL,
  478. email: settings.email,
  479. name: settings.displayName,
  480. id: ''
  481. }));
  482. return result;
  483. }
  484. /**
  485. * Signals that the local participant has left.
  486. *
  487. * @param {Store} store - The redux store.
  488. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  489. * specified {@code action} into the specified {@code store}.
  490. * @param {Action} action - The redux action which is being dispatched in the
  491. * specified {@code store}.
  492. * @private
  493. * @returns {Object} The value returned by {@code next(action)}.
  494. */
  495. function _localParticipantLeft({ dispatch }: IStore, next: Function, action: AnyAction) {
  496. const result = next(action);
  497. dispatch(localParticipantLeft());
  498. return result;
  499. }
  500. /**
  501. * Plays sounds when participants join/leave conference.
  502. *
  503. * @param {Store} store - The redux store.
  504. * @param {Action} action - The redux action. Should be either
  505. * {@link PARTICIPANT_JOINED} or {@link PARTICIPANT_LEFT}.
  506. * @private
  507. * @returns {void}
  508. */
  509. function _maybePlaySounds({ getState, dispatch }: IStore, action: AnyAction) {
  510. const state = getState();
  511. const { startAudioMuted } = state['features/base/config'];
  512. const { soundsParticipantJoined: joinSound, soundsParticipantLeft: leftSound } = state['features/base/settings'];
  513. // We're not playing sounds for local participant
  514. // nor when the user is joining past the "startAudioMuted" limit.
  515. // The intention there was to not play user joined notification in big
  516. // conferences where 100th person is joining.
  517. if (!action.participant.local
  518. && (!startAudioMuted
  519. || getParticipantCount(state) < startAudioMuted)) {
  520. const { isReplacing, isReplaced } = action.participant;
  521. if (action.type === PARTICIPANT_JOINED) {
  522. if (!joinSound) {
  523. return;
  524. }
  525. const { presence } = action.participant;
  526. // The sounds for the poltergeist are handled by features/invite.
  527. if (presence !== INVITED && presence !== CALLING && !isReplacing) {
  528. dispatch(playSound(PARTICIPANT_JOINED_SOUND_ID));
  529. }
  530. } else if (action.type === PARTICIPANT_LEFT && !isReplaced && leftSound) {
  531. dispatch(playSound(PARTICIPANT_LEFT_SOUND_ID));
  532. }
  533. }
  534. }
  535. /**
  536. * Notifies the feature base/participants that the action
  537. * {@code PARTICIPANT_JOINED} or {@code PARTICIPANT_UPDATED} is being dispatched
  538. * within a specific redux store.
  539. *
  540. * @param {Store} store - The redux store in which the specified {@code action}
  541. * is being dispatched.
  542. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  543. * specified {@code action} in the specified {@code store}.
  544. * @param {Action} action - The redux action {@code PARTICIPANT_JOINED} or
  545. * {@code PARTICIPANT_UPDATED} which is being dispatched in the specified
  546. * {@code store}.
  547. * @private
  548. * @returns {Object} The value returned by {@code next(action)}.
  549. */
  550. function _participantJoinedOrUpdated(store: IStore, next: Function, action: AnyAction) {
  551. const { dispatch, getState } = store;
  552. const { overwrittenNameList } = store.getState()['features/base/participants'];
  553. const { participant: {
  554. avatarURL,
  555. email,
  556. id,
  557. local,
  558. localRecording,
  559. name,
  560. raisedHandTimestamp
  561. } } = action;
  562. // Send an external update of the local participant's raised hand state
  563. // if a new raised hand state is defined in the action.
  564. if (typeof raisedHandTimestamp !== 'undefined') {
  565. if (local) {
  566. const { conference } = getState()['features/base/conference'];
  567. const rHand = parseInt(raisedHandTimestamp, 10);
  568. // Send raisedHand signalling only if there is a change
  569. if (conference && rHand !== getLocalParticipant(getState())?.raisedHandTimestamp) {
  570. conference.setLocalParticipantProperty('raisedHand', rHand);
  571. }
  572. }
  573. }
  574. if (overwrittenNameList[id]) {
  575. action.participant.name = overwrittenNameList[id];
  576. }
  577. // Send an external update of the local participant's local recording state
  578. // if a new local recording state is defined in the action.
  579. if (typeof localRecording !== 'undefined') {
  580. if (local) {
  581. const conference = getCurrentConference(getState);
  582. // Send localRecording signalling only if there is a change
  583. if (conference
  584. && localRecording !== getLocalParticipant(getState())?.localRecording) {
  585. conference.setLocalParticipantProperty('localRecording', localRecording);
  586. }
  587. }
  588. }
  589. // Allow the redux update to go through and compare the old avatar
  590. // to the new avatar and emit out change events if necessary.
  591. const result = next(action);
  592. // Only run this if the config is populated, otherwise we preload external resources
  593. // even if disableThirdPartyRequests is set to true in config
  594. if (getState()['features/base/config']?.hosts) {
  595. const { disableThirdPartyRequests } = getState()['features/base/config'];
  596. if (!disableThirdPartyRequests && (avatarURL || email || id || name)) {
  597. const participantId = !id && local ? getLocalParticipant(getState())?.id : id;
  598. const updatedParticipant = getParticipantById(getState(), participantId);
  599. getFirstLoadableAvatarUrl(updatedParticipant ?? { id: '' }, store)
  600. .then((urlData?: { isUsingCORS: boolean; src: string; }) => {
  601. dispatch(setLoadableAvatarUrl(participantId, urlData?.src ?? '', Boolean(urlData?.isUsingCORS)));
  602. });
  603. }
  604. }
  605. return result;
  606. }
  607. /**
  608. * Handles a local recording status update.
  609. *
  610. * @param {Function} dispatch - The Redux dispatch function.
  611. * @param {Object} conference - The conference for which we got an update.
  612. * @param {string} participantId - The ID of the participant from which we got an update.
  613. * @param {boolean} newValue - The new value of the local recording status.
  614. * @returns {void}
  615. */
  616. function _localRecordingUpdated({ dispatch, getState }: IStore, conference: IJitsiConference,
  617. participantId: string, newValue: string) {
  618. const state = getState();
  619. dispatch(participantUpdated({
  620. conference,
  621. id: participantId,
  622. localRecording: newValue
  623. }));
  624. const participantName = getParticipantDisplayName(state, participantId);
  625. dispatch(showNotification({
  626. titleKey: 'notify.somebody',
  627. title: participantName,
  628. descriptionKey: newValue ? 'notify.localRecordingStarted' : 'notify.localRecordingStopped',
  629. uid: LOCAL_RECORDING_NOTIFICATION_ID
  630. }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
  631. dispatch(playSound(newValue ? RECORDING_ON_SOUND_ID : RECORDING_OFF_SOUND_ID));
  632. }
  633. /**
  634. * Handles a raise hand status update.
  635. *
  636. * @param {Function} dispatch - The Redux dispatch function.
  637. * @param {Object} conference - The conference for which we got an update.
  638. * @param {string} participantId - The ID of the participant from which we got an update.
  639. * @param {boolean} newValue - The new value of the raise hand status.
  640. * @returns {void}
  641. */
  642. function _raiseHandUpdated({ dispatch, getState }: IStore, conference: IJitsiConference,
  643. participantId: string, newValue: string | number) {
  644. let raisedHandTimestamp;
  645. switch (newValue) {
  646. case undefined:
  647. case 'false':
  648. raisedHandTimestamp = 0;
  649. break;
  650. case 'true':
  651. raisedHandTimestamp = Date.now();
  652. break;
  653. default:
  654. raisedHandTimestamp = parseInt(`${newValue}`, 10);
  655. }
  656. const state = getState();
  657. dispatch(participantUpdated({
  658. conference,
  659. id: participantId,
  660. raisedHandTimestamp
  661. }));
  662. dispatch(raiseHandUpdateQueue({
  663. id: participantId,
  664. raisedHandTimestamp
  665. }));
  666. if (typeof APP !== 'undefined') {
  667. APP.API.notifyRaiseHandUpdated(participantId, raisedHandTimestamp);
  668. }
  669. const isModerator = isLocalParticipantModerator(state);
  670. const participant = getParticipantById(state, participantId);
  671. let shouldDisplayAllowAction = false;
  672. if (isModerator) {
  673. shouldDisplayAllowAction = isForceMuted(participant, MEDIA_TYPE.AUDIO, state)
  674. || isForceMuted(participant, MEDIA_TYPE.VIDEO, state);
  675. }
  676. const action = shouldDisplayAllowAction ? {
  677. customActionNameKey: [ 'notify.allowAction' ],
  678. customActionHandler: [ () => dispatch(approveParticipant(participantId)) ]
  679. } : {};
  680. if (raisedHandTimestamp) {
  681. let notificationTitle;
  682. const participantName = getParticipantDisplayName(state, participantId);
  683. const { raisedHandsQueue } = state['features/base/participants'];
  684. if (raisedHandsQueue.length > 1) {
  685. const raisedHands = raisedHandsQueue.length - 1;
  686. notificationTitle = i18n.t('notify.raisedHands', {
  687. participantName,
  688. raisedHands
  689. });
  690. } else {
  691. notificationTitle = participantName;
  692. }
  693. dispatch(showNotification({
  694. titleKey: 'notify.somebody',
  695. title: notificationTitle,
  696. descriptionKey: 'notify.raisedHand',
  697. concatText: true,
  698. uid: RAISE_HAND_NOTIFICATION_ID,
  699. ...action
  700. }, shouldDisplayAllowAction ? NOTIFICATION_TIMEOUT_TYPE.MEDIUM : NOTIFICATION_TIMEOUT_TYPE.SHORT));
  701. dispatch(playSound(RAISE_HAND_SOUND_ID));
  702. }
  703. }
  704. /**
  705. * Registers sounds related with the participants feature.
  706. *
  707. * @param {Store} store - The redux store.
  708. * @private
  709. * @returns {void}
  710. */
  711. function _registerSounds({ dispatch }: IStore) {
  712. dispatch(
  713. registerSound(PARTICIPANT_JOINED_SOUND_ID, PARTICIPANT_JOINED_FILE));
  714. dispatch(registerSound(PARTICIPANT_LEFT_SOUND_ID, PARTICIPANT_LEFT_FILE));
  715. }
  716. /**
  717. * Unregisters sounds related with the participants feature.
  718. *
  719. * @param {Store} store - The redux store.
  720. * @private
  721. * @returns {void}
  722. */
  723. function _unregisterSounds({ dispatch }: IStore) {
  724. dispatch(unregisterSound(PARTICIPANT_JOINED_SOUND_ID));
  725. dispatch(unregisterSound(PARTICIPANT_LEFT_SOUND_ID));
  726. }