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

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