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

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