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.js 27KB

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