Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.js 23KB

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