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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. // @flow
  2. import { reloadNow } from '../../app';
  3. import {
  4. ACTION_PINNED,
  5. ACTION_UNPINNED,
  6. createAudioOnlyChangedEvent,
  7. createConnectionEvent,
  8. createPinnedEvent,
  9. sendAnalytics
  10. } from '../../analytics';
  11. import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../connection';
  12. import { setVideoMuted, VIDEO_MUTISM_AUTHORITY } from '../media';
  13. import {
  14. getLocalParticipant,
  15. getParticipantById,
  16. getPinnedParticipant,
  17. PARTICIPANT_UPDATED,
  18. PIN_PARTICIPANT
  19. } from '../participants';
  20. import { MiddlewareRegistry, StateListenerRegistry } from '../redux';
  21. import UIEvents from '../../../../service/UI/UIEvents';
  22. import { TRACK_ADDED, TRACK_REMOVED } from '../tracks';
  23. import {
  24. conferenceFailed,
  25. conferenceWillLeave,
  26. createConference,
  27. setLastN,
  28. setSubject
  29. } from './actions';
  30. import {
  31. CONFERENCE_FAILED,
  32. CONFERENCE_JOINED,
  33. CONFERENCE_SUBJECT_CHANGED,
  34. CONFERENCE_WILL_LEAVE,
  35. DATA_CHANNEL_OPENED,
  36. SET_AUDIO_ONLY,
  37. SET_LASTN
  38. } from './actionTypes';
  39. import {
  40. _addLocalTracksToConference,
  41. forEachConference,
  42. getCurrentConference,
  43. _handleParticipantError,
  44. _removeLocalTracksFromConference
  45. } from './functions';
  46. const logger = require('jitsi-meet-logger').getLogger(__filename);
  47. declare var APP: Object;
  48. /**
  49. * Handler for before unload event.
  50. */
  51. let beforeUnloadHandler;
  52. /**
  53. * Implements the middleware of the feature base/conference.
  54. *
  55. * @param {Store} store - The redux store.
  56. * @returns {Function}
  57. */
  58. MiddlewareRegistry.register(store => next => action => {
  59. switch (action.type) {
  60. case CONFERENCE_FAILED:
  61. return _conferenceFailed(store, next, action);
  62. case CONFERENCE_JOINED:
  63. return _conferenceJoined(store, next, action);
  64. case CONNECTION_ESTABLISHED:
  65. return _connectionEstablished(store, next, action);
  66. case CONNECTION_FAILED:
  67. return _connectionFailed(store, next, action);
  68. case CONFERENCE_SUBJECT_CHANGED:
  69. return _conferenceSubjectChanged(store, next, action);
  70. case CONFERENCE_WILL_LEAVE:
  71. _conferenceWillLeave();
  72. break;
  73. case DATA_CHANNEL_OPENED:
  74. return _syncReceiveVideoQuality(store, next, action);
  75. case PARTICIPANT_UPDATED:
  76. return _updateLocalParticipantInConference(store, next, action);
  77. case PIN_PARTICIPANT:
  78. return _pinParticipant(store, next, action);
  79. case SET_AUDIO_ONLY:
  80. return _setAudioOnly(store, next, action);
  81. case SET_LASTN:
  82. return _setLastN(store, next, action);
  83. case TRACK_ADDED:
  84. case TRACK_REMOVED:
  85. return _trackAddedOrRemoved(store, next, action);
  86. }
  87. return next(action);
  88. });
  89. /**
  90. * Registers a change handler for state['features/base/conference'] to update
  91. * the preferred video quality levels based on user preferred and internal
  92. * settings.
  93. */
  94. StateListenerRegistry.register(
  95. /* selector */ state => state['features/base/conference'],
  96. /* listener */ (currentState, store, previousState = {}) => {
  97. const {
  98. conference,
  99. maxReceiverVideoQuality,
  100. preferredReceiverVideoQuality
  101. } = currentState;
  102. const changedPreferredVideoQuality = preferredReceiverVideoQuality
  103. !== previousState.preferredReceiverVideoQuality;
  104. const changedMaxVideoQuality = maxReceiverVideoQuality
  105. !== previousState.maxReceiverVideoQuality;
  106. if (changedPreferredVideoQuality || changedMaxVideoQuality) {
  107. _setReceiverVideoConstraint(
  108. conference,
  109. preferredReceiverVideoQuality,
  110. maxReceiverVideoQuality);
  111. }
  112. });
  113. /**
  114. * Makes sure to leave a failed conference in order to release any allocated
  115. * resources like peer connections, emit participant left events, etc.
  116. *
  117. * @param {Store} store - The redux store in which the specified {@code action}
  118. * is being dispatched.
  119. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  120. * specified {@code action} to the specified {@code store}.
  121. * @param {Action} action - The redux action {@code CONFERENCE_FAILED} which is
  122. * being dispatched in the specified {@code store}.
  123. * @private
  124. * @returns {Object} The value returned by {@code next(action)}.
  125. */
  126. function _conferenceFailed(store, next, action) {
  127. const result = next(action);
  128. // FIXME: Workaround for the web version. Currently, the creation of the
  129. // conference is handled by /conference.js and appropriate failure handlers
  130. // are set there.
  131. if (typeof APP !== 'undefined') {
  132. if (typeof beforeUnloadHandler !== 'undefined') {
  133. window.removeEventListener('beforeunload', beforeUnloadHandler);
  134. beforeUnloadHandler = undefined;
  135. }
  136. return result;
  137. }
  138. // XXX After next(action), it is clear whether the error is recoverable.
  139. const { conference, error } = action;
  140. !error.recoverable
  141. && conference
  142. && conference.leave().catch(reason => {
  143. // Even though we don't care too much about the failure, it may be
  144. // good to know that it happen, so log it (on the info level).
  145. logger.info('JitsiConference.leave() rejected with:', reason);
  146. });
  147. return result;
  148. }
  149. /**
  150. * Does extra sync up on properties that may need to be updated after the
  151. * conference was joined.
  152. *
  153. * @param {Store} store - The redux store in which the specified {@code action}
  154. * is being dispatched.
  155. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  156. * specified {@code action} to the specified {@code store}.
  157. * @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is
  158. * being dispatched in the specified {@code store}.
  159. * @private
  160. * @returns {Object} The value returned by {@code next(action)}.
  161. */
  162. function _conferenceJoined({ dispatch, getState }, next, action) {
  163. const result = next(action);
  164. const {
  165. audioOnly,
  166. conference,
  167. pendingSubjectChange
  168. } = getState()['features/base/conference'];
  169. if (pendingSubjectChange) {
  170. dispatch(setSubject(pendingSubjectChange));
  171. }
  172. // FIXME On Web the audio only mode for "start audio only" is toggled before
  173. // conference is added to the redux store ("on conference joined" action)
  174. // and the LastN value needs to be synchronized here.
  175. audioOnly && conference.getLastN() !== 0 && dispatch(setLastN(0));
  176. // FIXME: Very dirty solution. This will work on web only.
  177. // When the user closes the window or quits the browser, lib-jitsi-meet
  178. // handles the process of leaving the conference. This is temporary solution
  179. // that should cover the described use case as part of the effort to
  180. // implement the conferenceWillLeave action for web.
  181. beforeUnloadHandler = () => {
  182. dispatch(conferenceWillLeave(conference));
  183. };
  184. window.addEventListener('beforeunload', beforeUnloadHandler);
  185. return result;
  186. }
  187. /**
  188. * Notifies the feature base/conference that the action
  189. * {@code CONNECTION_ESTABLISHED} is being dispatched within a specific redux
  190. * store.
  191. *
  192. * @param {Store} store - The redux store in which the specified {@code action}
  193. * is being dispatched.
  194. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  195. * specified {@code action} to the specified {@code store}.
  196. * @param {Action} action - The redux action {@code CONNECTION_ESTABLISHED}
  197. * which is being dispatched in the specified {@code store}.
  198. * @private
  199. * @returns {Object} The value returned by {@code next(action)}.
  200. */
  201. function _connectionEstablished({ dispatch }, next, action) {
  202. const result = next(action);
  203. // FIXME: Workaround for the web version. Currently, the creation of the
  204. // conference is handled by /conference.js.
  205. typeof APP === 'undefined' && dispatch(createConference());
  206. return result;
  207. }
  208. /**
  209. * Notifies the feature base/conference that the action
  210. * {@code CONNECTION_FAILED} is being dispatched within a specific redux
  211. * store.
  212. *
  213. * @param {Store} store - The redux store in which the specified {@code action}
  214. * is being dispatched.
  215. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  216. * specified {@code action} to the specified {@code store}.
  217. * @param {Action} action - The redux action {@code CONNECTION_FAILED} which is
  218. * being dispatched in the specified {@code store}.
  219. * @private
  220. * @returns {Object} The value returned by {@code next(action)}.
  221. */
  222. function _connectionFailed({ dispatch, getState }, next, action) {
  223. // In the case of a split-brain error, reload early and prevent further
  224. // handling of the action.
  225. if (_isMaybeSplitBrainError(getState, action)) {
  226. dispatch(reloadNow());
  227. return;
  228. }
  229. const result = next(action);
  230. if (typeof beforeUnloadHandler !== 'undefined') {
  231. window.removeEventListener('beforeunload', beforeUnloadHandler);
  232. beforeUnloadHandler = undefined;
  233. }
  234. // FIXME: Workaround for the web version. Currently, the creation of the
  235. // conference is handled by /conference.js and appropriate failure handlers
  236. // are set there.
  237. if (typeof APP === 'undefined') {
  238. const { connection } = action;
  239. const { error } = action;
  240. forEachConference(getState, conference => {
  241. // It feels that it would make things easier if JitsiConference
  242. // in lib-jitsi-meet would monitor it's connection and emit
  243. // CONFERENCE_FAILED when it's dropped. It has more knowledge on
  244. // whether it can recover or not. But because the reload screen
  245. // and the retry logic is implemented in the app maybe it can be
  246. // left this way for now.
  247. if (conference.getConnection() === connection) {
  248. // XXX Note that on mobile the error type passed to
  249. // connectionFailed is always an object with .name property.
  250. // This fact needs to be checked prior to enabling this logic on
  251. // web.
  252. const conferenceAction
  253. = conferenceFailed(conference, error.name);
  254. // Copy the recoverable flag if set on the CONNECTION_FAILED
  255. // action to not emit recoverable action caused by
  256. // a non-recoverable one.
  257. if (typeof error.recoverable !== 'undefined') {
  258. conferenceAction.error.recoverable = error.recoverable;
  259. }
  260. dispatch(conferenceAction);
  261. }
  262. return true;
  263. });
  264. }
  265. return result;
  266. }
  267. /**
  268. * Notifies the feature base/conference that the action
  269. * {@code CONFERENCE_SUBJECT_CHANGED} is being dispatched within a specific
  270. * redux store.
  271. *
  272. * @param {Store} store - The redux store in which the specified {@code action}
  273. * is being dispatched.
  274. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  275. * specified {@code action} to the specified {@code store}.
  276. * @param {Action} action - The redux action {@code CONFERENCE_SUBJECT_CHANGED}
  277. * which is being dispatched in the specified {@code store}.
  278. * @private
  279. * @returns {Object} The value returned by {@code next(action)}.
  280. */
  281. function _conferenceSubjectChanged({ getState }, next, action) {
  282. const result = next(action);
  283. const { subject } = getState()['features/base/conference'];
  284. typeof APP === 'object' && APP.API.notifySubjectChanged(subject);
  285. return result;
  286. }
  287. /**
  288. * Notifies the feature base/conference that the action
  289. * {@code CONFERENCE_WILL_LEAVE} is being dispatched within a specific redux
  290. * store.
  291. *
  292. * @private
  293. * @returns {void}
  294. */
  295. function _conferenceWillLeave() {
  296. if (typeof beforeUnloadHandler !== 'undefined') {
  297. window.removeEventListener('beforeunload', beforeUnloadHandler);
  298. beforeUnloadHandler = undefined;
  299. }
  300. }
  301. /**
  302. * Returns whether or not a CONNECTION_FAILED action is for a possible split
  303. * brain error. A split brain error occurs when at least two users join a
  304. * conference on different bridges. It is assumed the split brain scenario
  305. * occurs very early on in the call.
  306. *
  307. * @param {Function} getState - The redux function for fetching the current
  308. * state.
  309. * @param {Action} action - The redux action {@code CONNECTION_FAILED} which is
  310. * being dispatched in the specified {@code store}.
  311. * @private
  312. * @returns {boolean}
  313. */
  314. function _isMaybeSplitBrainError(getState, action) {
  315. const { error } = action;
  316. const isShardChangedError = error
  317. && error.message === 'item-not-found'
  318. && error.details
  319. && error.details.shard_changed;
  320. if (isShardChangedError) {
  321. const state = getState();
  322. const { timeEstablished } = state['features/base/connection'];
  323. const { _immediateReloadThreshold } = state['features/base/config'];
  324. const timeSinceConnectionEstablished
  325. = timeEstablished && Date.now() - timeEstablished;
  326. const reloadThreshold = typeof _immediateReloadThreshold === 'number'
  327. ? _immediateReloadThreshold : 1500;
  328. const isWithinSplitBrainThreshold = !timeEstablished
  329. || timeSinceConnectionEstablished <= reloadThreshold;
  330. sendAnalytics(createConnectionEvent('failed', {
  331. ...error,
  332. connectionEstablished: timeEstablished,
  333. splitBrain: isWithinSplitBrainThreshold,
  334. timeSinceConnectionEstablished
  335. }));
  336. return isWithinSplitBrainThreshold;
  337. }
  338. return false;
  339. }
  340. /**
  341. * Notifies the feature base/conference that the action {@code PIN_PARTICIPANT}
  342. * is being dispatched within a specific redux store. Pins the specified remote
  343. * participant in the associated conference, ignores the local participant.
  344. *
  345. * @param {Store} store - The redux store in which the specified {@code action}
  346. * is being dispatched.
  347. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  348. * specified {@code action} to the specified {@code store}.
  349. * @param {Action} action - The redux action {@code PIN_PARTICIPANT} which is
  350. * being dispatched in the specified {@code store}.
  351. * @private
  352. * @returns {Object} The value returned by {@code next(action)}.
  353. */
  354. function _pinParticipant({ getState }, next, action) {
  355. const state = getState();
  356. const { conference } = state['features/base/conference'];
  357. if (!conference) {
  358. return next(action);
  359. }
  360. const participants = state['features/base/participants'];
  361. const id = action.participant.id;
  362. const participantById = getParticipantById(participants, id);
  363. if (typeof APP !== 'undefined') {
  364. const pinnedParticipant = getPinnedParticipant(participants);
  365. const actionName = id ? ACTION_PINNED : ACTION_UNPINNED;
  366. const local
  367. = (participantById && participantById.local)
  368. || (!id && pinnedParticipant && pinnedParticipant.local);
  369. let participantIdForEvent;
  370. if (local) {
  371. participantIdForEvent = local;
  372. } else {
  373. participantIdForEvent = actionName === ACTION_PINNED
  374. ? id : pinnedParticipant && pinnedParticipant.id;
  375. }
  376. sendAnalytics(createPinnedEvent(
  377. actionName,
  378. participantIdForEvent,
  379. {
  380. local,
  381. 'participant_count': conference.getParticipantCount()
  382. }));
  383. }
  384. // The following condition prevents signaling to pin local participant and
  385. // shared videos. The logic is:
  386. // - If we have an ID, we check if the participant identified by that ID is
  387. // local or a bot/fake participant (such as with shared video).
  388. // - If we don't have an ID (i.e. no participant identified by an ID), we
  389. // check for local participant. If she's currently pinned, then this
  390. // action will unpin her and that's why we won't signal here too.
  391. let pin;
  392. if (participantById) {
  393. pin = !participantById.local && !participantById.isFakeParticipant;
  394. } else {
  395. const localParticipant = getLocalParticipant(participants);
  396. pin = !localParticipant || !localParticipant.pinned;
  397. }
  398. if (pin) {
  399. try {
  400. conference.pinParticipant(id);
  401. } catch (err) {
  402. _handleParticipantError(err);
  403. }
  404. }
  405. return next(action);
  406. }
  407. /**
  408. * Sets the audio-only flag for the current conference. When audio-only is set,
  409. * local video is muted and last N is set to 0 to avoid receiving remote video.
  410. *
  411. * @param {Store} store - The redux store in which the specified {@code action}
  412. * is being dispatched.
  413. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  414. * specified {@code action} to the specified {@code store}.
  415. * @param {Action} action - The redux action {@code SET_AUDIO_ONLY} which is
  416. * being dispatched in the specified {@code store}.
  417. * @private
  418. * @returns {Object} The value returned by {@code next(action)}.
  419. */
  420. function _setAudioOnly({ dispatch, getState }, next, action) {
  421. const { audioOnly: oldValue } = getState()['features/base/conference'];
  422. const result = next(action);
  423. const { audioOnly: newValue } = getState()['features/base/conference'];
  424. // Send analytics. We could've done it in the action creator setAudioOnly.
  425. // I don't know why it has to happen as early as possible but the analytics
  426. // were originally sent before the SET_AUDIO_ONLY action was even dispatched
  427. // in the redux store so I'm now sending the analytics as early as possible.
  428. if (oldValue !== newValue) {
  429. sendAnalytics(createAudioOnlyChangedEvent(newValue));
  430. logger.log(`Audio-only ${newValue ? 'enabled' : 'disabled'}`);
  431. }
  432. // Set lastN to 0 in case audio-only is desired; leave it as undefined,
  433. // otherwise, and the default lastN value will be chosen automatically.
  434. dispatch(setLastN(newValue ? 0 : undefined));
  435. // Mute/unmute the local video.
  436. dispatch(
  437. setVideoMuted(
  438. newValue,
  439. VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY,
  440. action.ensureVideoTrack));
  441. if (typeof APP !== 'undefined') {
  442. // TODO This should be a temporary solution that lasts only until video
  443. // tracks and all ui is moved into react/redux on the web.
  444. APP.UI.emitEvent(UIEvents.TOGGLE_AUDIO_ONLY, newValue);
  445. }
  446. return result;
  447. }
  448. /**
  449. * Sets the last N (value) of the video channel in the conference.
  450. *
  451. * @param {Store} store - The redux store in which the specified {@code action}
  452. * is being dispatched.
  453. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  454. * specified {@code action} to the specified {@code store}.
  455. * @param {Action} action - The redux action {@code SET_LASTN} which is being
  456. * dispatched in the specified {@code store}.
  457. * @private
  458. * @returns {Object} The value returned by {@code next(action)}.
  459. */
  460. function _setLastN({ getState }, next, action) {
  461. const { conference } = getState()['features/base/conference'];
  462. if (conference) {
  463. try {
  464. conference.setLastN(action.lastN);
  465. } catch (err) {
  466. logger.error(`Failed to set lastN: ${err}`);
  467. }
  468. }
  469. return next(action);
  470. }
  471. /**
  472. * Helper function for updating the preferred receiver video constraint, based
  473. * on the user preference and the internal maximum.
  474. *
  475. * @param {JitsiConference} conference - The JitsiConference instance for the
  476. * current call.
  477. * @param {number} preferred - The user preferred max frame height.
  478. * @param {number} max - The maximum frame height the application should
  479. * receive.
  480. * @returns {void}
  481. */
  482. function _setReceiverVideoConstraint(conference, preferred, max) {
  483. if (conference) {
  484. conference.setReceiverVideoConstraint(Math.min(preferred, max));
  485. }
  486. }
  487. /**
  488. * Synchronizes local tracks from state with local tracks in JitsiConference
  489. * instance.
  490. *
  491. * @param {Store} store - The redux store.
  492. * @param {Object} action - Action object.
  493. * @private
  494. * @returns {Promise}
  495. */
  496. function _syncConferenceLocalTracksWithState({ getState }, action) {
  497. const conference = getCurrentConference(getState);
  498. let promise;
  499. if (conference) {
  500. const track = action.track.jitsiTrack;
  501. if (action.type === TRACK_ADDED) {
  502. promise = _addLocalTracksToConference(conference, [ track ]);
  503. } else {
  504. promise = _removeLocalTracksFromConference(conference, [ track ]);
  505. }
  506. }
  507. return promise || Promise.resolve();
  508. }
  509. /**
  510. * Sets the maximum receive video quality.
  511. *
  512. * @param {Store} store - The redux store in which the specified {@code action}
  513. * is being dispatched.
  514. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  515. * specified {@code action} to the specified {@code store}.
  516. * @param {Action} action - The redux action {@code DATA_CHANNEL_STATUS_CHANGED}
  517. * which is being dispatched in the specified {@code store}.
  518. * @private
  519. * @returns {Object} The value returned by {@code next(action)}.
  520. */
  521. function _syncReceiveVideoQuality({ getState }, next, action) {
  522. const {
  523. conference,
  524. maxReceiverVideoQuality,
  525. preferredReceiverVideoQuality
  526. } = getState()['features/base/conference'];
  527. _setReceiverVideoConstraint(
  528. conference,
  529. preferredReceiverVideoQuality,
  530. maxReceiverVideoQuality);
  531. return next(action);
  532. }
  533. /**
  534. * Notifies the feature base/conference that the action {@code TRACK_ADDED}
  535. * or {@code TRACK_REMOVED} is being dispatched within a specific redux store.
  536. *
  537. * @param {Store} store - The redux store in which the specified {@code action}
  538. * is being dispatched.
  539. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  540. * specified {@code action} to the specified {@code store}.
  541. * @param {Action} action - The redux action {@code TRACK_ADDED} or
  542. * {@code TRACK_REMOVED} which is being dispatched in the specified
  543. * {@code store}.
  544. * @private
  545. * @returns {Object} The value returned by {@code next(action)}.
  546. */
  547. function _trackAddedOrRemoved(store, next, action) {
  548. const track = action.track;
  549. if (track && track.local) {
  550. return (
  551. _syncConferenceLocalTracksWithState(store, action)
  552. .then(() => next(action)));
  553. }
  554. return next(action);
  555. }
  556. /**
  557. * Updates the conference object when the local participant is updated.
  558. *
  559. * @param {Store} store - The redux store in which the specified {@code action}
  560. * is being dispatched.
  561. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  562. * specified {@code action} to the specified {@code store}.
  563. * @param {Action} action - The redux action which is being dispatched in the
  564. * specified {@code store}.
  565. * @private
  566. * @returns {Object} The value returned by {@code next(action)}.
  567. */
  568. function _updateLocalParticipantInConference({ getState }, next, action) {
  569. const { conference } = getState()['features/base/conference'];
  570. const { participant } = action;
  571. const result = next(action);
  572. if (conference && participant.local && 'name' in participant) {
  573. conference.setDisplayName(participant.name);
  574. }
  575. return result;
  576. }