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

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