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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. 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_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({ getState }, next, action) {
  286. const result = next(action);
  287. const { subject } = getState()['features/base/conference'];
  288. typeof APP === 'object' && APP.API.notifySubjectChanged(subject);
  289. return result;
  290. }
  291. /**
  292. * Notifies the feature base/conference that the action
  293. * {@code CONFERENCE_WILL_LEAVE} is being dispatched within a specific redux
  294. * store.
  295. *
  296. * @private
  297. * @returns {void}
  298. */
  299. function _conferenceWillLeave() {
  300. if (typeof beforeUnloadHandler !== 'undefined') {
  301. window.removeEventListener('beforeunload', beforeUnloadHandler);
  302. beforeUnloadHandler = undefined;
  303. }
  304. }
  305. /**
  306. * Returns whether or not a CONNECTION_FAILED action is for a possible split
  307. * brain error. A split brain error occurs when at least two users join a
  308. * conference on different bridges. It is assumed the split brain scenario
  309. * occurs very early on in the call.
  310. *
  311. * @param {Function} getState - The redux function for fetching the current
  312. * state.
  313. * @param {Action} action - The redux action {@code CONNECTION_FAILED} which is
  314. * being dispatched in the specified {@code store}.
  315. * @private
  316. * @returns {boolean}
  317. */
  318. function _isMaybeSplitBrainError(getState, action) {
  319. const { error } = action;
  320. const isShardChangedError = error
  321. && error.message === 'item-not-found'
  322. && error.details
  323. && error.details.shard_changed;
  324. if (isShardChangedError) {
  325. const state = getState();
  326. const { timeEstablished } = state['features/base/connection'];
  327. const { _immediateReloadThreshold } = state['features/base/config'];
  328. const timeSinceConnectionEstablished
  329. = timeEstablished && Date.now() - timeEstablished;
  330. const reloadThreshold = typeof _immediateReloadThreshold === 'number'
  331. ? _immediateReloadThreshold : 1500;
  332. const isWithinSplitBrainThreshold = !timeEstablished
  333. || timeSinceConnectionEstablished <= reloadThreshold;
  334. sendAnalytics(createConnectionEvent('failed', {
  335. ...error,
  336. connectionEstablished: timeEstablished,
  337. splitBrain: isWithinSplitBrainThreshold,
  338. timeSinceConnectionEstablished
  339. }));
  340. return isWithinSplitBrainThreshold;
  341. }
  342. return false;
  343. }
  344. /**
  345. * Notifies the feature base/conference that the action {@code PIN_PARTICIPANT}
  346. * is being dispatched within a specific redux store. Pins the specified remote
  347. * participant in the associated conference, ignores the local participant.
  348. *
  349. * @param {Store} store - The redux store in which the specified {@code action}
  350. * is being dispatched.
  351. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  352. * specified {@code action} to the specified {@code store}.
  353. * @param {Action} action - The redux action {@code PIN_PARTICIPANT} which is
  354. * being dispatched in the specified {@code store}.
  355. * @private
  356. * @returns {Object} The value returned by {@code next(action)}.
  357. */
  358. function _pinParticipant({ getState }, next, action) {
  359. const state = getState();
  360. const { conference } = state['features/base/conference'];
  361. if (!conference) {
  362. return next(action);
  363. }
  364. const participants = state['features/base/participants'];
  365. const id = action.participant.id;
  366. const participantById = getParticipantById(participants, id);
  367. if (typeof APP !== 'undefined') {
  368. const pinnedParticipant = getPinnedParticipant(participants);
  369. const actionName = id ? ACTION_PINNED : ACTION_UNPINNED;
  370. const local
  371. = (participantById && participantById.local)
  372. || (!id && pinnedParticipant && pinnedParticipant.local);
  373. let participantIdForEvent;
  374. if (local) {
  375. participantIdForEvent = local;
  376. } else {
  377. participantIdForEvent = actionName === ACTION_PINNED
  378. ? id : pinnedParticipant && pinnedParticipant.id;
  379. }
  380. sendAnalytics(createPinnedEvent(
  381. actionName,
  382. participantIdForEvent,
  383. {
  384. local,
  385. 'participant_count': conference.getParticipantCount()
  386. }));
  387. }
  388. // The following condition prevents signaling to pin local participant and
  389. // shared videos. The logic is:
  390. // - If we have an ID, we check if the participant identified by that ID is
  391. // local or a bot/fake participant (such as with shared video).
  392. // - If we don't have an ID (i.e. no participant identified by an ID), we
  393. // check for local participant. If she's currently pinned, then this
  394. // action will unpin her and that's why we won't signal here too.
  395. let pin;
  396. if (participantById) {
  397. pin = !participantById.local && !participantById.isFakeParticipant;
  398. } else {
  399. const localParticipant = getLocalParticipant(participants);
  400. pin = !localParticipant || !localParticipant.pinned;
  401. }
  402. if (pin) {
  403. try {
  404. conference.pinParticipant(id);
  405. } catch (err) {
  406. _handleParticipantError(err);
  407. }
  408. }
  409. return next(action);
  410. }
  411. /**
  412. * Sets the audio-only flag for the current conference. When audio-only is set,
  413. * local video is muted and last N is set to 0 to avoid receiving remote video.
  414. *
  415. * @param {Store} store - The redux store in which the specified {@code action}
  416. * is being dispatched.
  417. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  418. * specified {@code action} to the specified {@code store}.
  419. * @param {Action} action - The redux action {@code SET_AUDIO_ONLY} which is
  420. * being dispatched in the specified {@code store}.
  421. * @private
  422. * @returns {Object} The value returned by {@code next(action)}.
  423. */
  424. function _setAudioOnly({ dispatch, getState }, next, action) {
  425. const { audioOnly: oldValue } = getState()['features/base/conference'];
  426. const result = next(action);
  427. const { audioOnly: newValue } = getState()['features/base/conference'];
  428. // Send analytics. We could've done it in the action creator setAudioOnly.
  429. // I don't know why it has to happen as early as possible but the analytics
  430. // were originally sent before the SET_AUDIO_ONLY action was even dispatched
  431. // in the redux store so I'm now sending the analytics as early as possible.
  432. if (oldValue !== newValue) {
  433. sendAnalytics(createAudioOnlyChangedEvent(newValue));
  434. logger.log(`Audio-only ${newValue ? 'enabled' : 'disabled'}`);
  435. }
  436. // Set lastN to 0 in case audio-only is desired; leave it as undefined,
  437. // otherwise, and the default lastN value will be chosen automatically.
  438. dispatch(setLastN(newValue ? 0 : undefined));
  439. // Mute/unmute the local video.
  440. dispatch(
  441. setVideoMuted(
  442. newValue,
  443. VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY,
  444. action.ensureVideoTrack));
  445. if (typeof APP !== 'undefined') {
  446. // TODO This should be a temporary solution that lasts only until video
  447. // tracks and all ui is moved into react/redux on the web.
  448. APP.UI.emitEvent(UIEvents.TOGGLE_AUDIO_ONLY, newValue);
  449. }
  450. return result;
  451. }
  452. /**
  453. * Sets the last N (value) of the video channel in the conference.
  454. *
  455. * @param {Store} store - The redux store in which the specified {@code action}
  456. * is being dispatched.
  457. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  458. * specified {@code action} to the specified {@code store}.
  459. * @param {Action} action - The redux action {@code SET_LASTN} which is being
  460. * dispatched in the specified {@code store}.
  461. * @private
  462. * @returns {Object} The value returned by {@code next(action)}.
  463. */
  464. function _setLastN({ getState }, next, action) {
  465. const { conference } = getState()['features/base/conference'];
  466. if (conference) {
  467. try {
  468. conference.setLastN(action.lastN);
  469. } catch (err) {
  470. logger.error(`Failed to set lastN: ${err}`);
  471. }
  472. }
  473. return next(action);
  474. }
  475. /**
  476. * Helper function for updating the preferred receiver video constraint, based
  477. * on the user preference and the internal maximum.
  478. *
  479. * @param {JitsiConference} conference - The JitsiConference instance for the
  480. * current call.
  481. * @param {number} preferred - The user preferred max frame height.
  482. * @param {number} max - The maximum frame height the application should
  483. * receive.
  484. * @returns {void}
  485. */
  486. function _setReceiverVideoConstraint(conference, preferred, max) {
  487. if (conference) {
  488. conference.setReceiverVideoConstraint(Math.min(preferred, max));
  489. }
  490. }
  491. /**
  492. * Notifies the feature {@code base/conference} that the redix action
  493. * {@link SET_ROOM} is being dispatched within a specific redux store.
  494. *
  495. * @param {Store} store - The redux store in which the specified {@code action}
  496. * is being dispatched.
  497. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  498. * specified {@code action} to the specified {@code store}.
  499. * @param {Action} action - The redux action {@code SET_ROOM} which is being
  500. * dispatched in the specified {@code store}.
  501. * @private
  502. * @returns {Object} The value returned by {@code next(action)}.
  503. */
  504. function _setRoom({ dispatch, getState }, next, action) {
  505. const result = next(action);
  506. // By the time SET_ROOM is dispatched, base/connection's locationURL and
  507. // base/conference's leaving should be the only conference-related sources
  508. // of truth.
  509. const state = getState();
  510. const { leaving } = state['features/base/conference'];
  511. const { locationURL } = state['features/base/connection'];
  512. const dispatchConferenceLeft = new Set();
  513. // Figure out which of the JitsiConferences referenced by base/conference
  514. // have not dispatched or are not likely to dispatch CONFERENCE_FAILED and
  515. // CONFERENCE_LEFT.
  516. forEachConference(state, (conference, url) => {
  517. if (conference !== leaving && url && url !== locationURL) {
  518. dispatchConferenceLeft.add(conference);
  519. }
  520. return true; // All JitsiConference instances are to be examined.
  521. });
  522. // Dispatch CONFERENCE_LEFT for the JitsiConferences referenced by
  523. // base/conference which have not dispatched or are not likely to dispatch
  524. // CONFERENCE_FAILED or CONFERENCE_LEFT.
  525. for (const conference of dispatchConferenceLeft) {
  526. dispatch(conferenceLeft(conference));
  527. }
  528. return result;
  529. }
  530. /**
  531. * Synchronizes local tracks from state with local tracks in JitsiConference
  532. * instance.
  533. *
  534. * @param {Store} store - The redux store.
  535. * @param {Object} action - Action object.
  536. * @private
  537. * @returns {Promise}
  538. */
  539. function _syncConferenceLocalTracksWithState({ getState }, action) {
  540. const conference = getCurrentConference(getState);
  541. let promise;
  542. if (conference) {
  543. const track = action.track.jitsiTrack;
  544. if (action.type === TRACK_ADDED) {
  545. promise = _addLocalTracksToConference(conference, [ track ]);
  546. } else {
  547. promise = _removeLocalTracksFromConference(conference, [ track ]);
  548. }
  549. }
  550. return promise || Promise.resolve();
  551. }
  552. /**
  553. * Sets the maximum receive video quality.
  554. *
  555. * @param {Store} store - The redux store in which the specified {@code action}
  556. * is being dispatched.
  557. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  558. * specified {@code action} to the specified {@code store}.
  559. * @param {Action} action - The redux action {@code DATA_CHANNEL_STATUS_CHANGED}
  560. * which is being dispatched in the specified {@code store}.
  561. * @private
  562. * @returns {Object} The value returned by {@code next(action)}.
  563. */
  564. function _syncReceiveVideoQuality({ getState }, next, action) {
  565. const {
  566. conference,
  567. maxReceiverVideoQuality,
  568. preferredReceiverVideoQuality
  569. } = getState()['features/base/conference'];
  570. _setReceiverVideoConstraint(
  571. conference,
  572. preferredReceiverVideoQuality,
  573. maxReceiverVideoQuality);
  574. return next(action);
  575. }
  576. /**
  577. * Notifies the feature base/conference that the action {@code TRACK_ADDED}
  578. * or {@code TRACK_REMOVED} is being dispatched within a specific redux store.
  579. *
  580. * @param {Store} store - The redux store in which the specified {@code action}
  581. * is being dispatched.
  582. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  583. * specified {@code action} to the specified {@code store}.
  584. * @param {Action} action - The redux action {@code TRACK_ADDED} or
  585. * {@code TRACK_REMOVED} which is being dispatched in the specified
  586. * {@code store}.
  587. * @private
  588. * @returns {Object} The value returned by {@code next(action)}.
  589. */
  590. function _trackAddedOrRemoved(store, next, action) {
  591. const track = action.track;
  592. if (track && track.local) {
  593. return (
  594. _syncConferenceLocalTracksWithState(store, action)
  595. .then(() => next(action)));
  596. }
  597. return next(action);
  598. }
  599. /**
  600. * Updates the conference object when the local participant is updated.
  601. *
  602. * @param {Store} store - The redux store in which the specified {@code action}
  603. * is being dispatched.
  604. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  605. * specified {@code action} to the specified {@code store}.
  606. * @param {Action} action - The redux action which is being dispatched in the
  607. * specified {@code store}.
  608. * @private
  609. * @returns {Object} The value returned by {@code next(action)}.
  610. */
  611. function _updateLocalParticipantInConference({ getState }, next, action) {
  612. const { conference } = getState()['features/base/conference'];
  613. const { participant } = action;
  614. const result = next(action);
  615. if (conference && participant.local && 'name' in participant) {
  616. conference.setDisplayName(participant.name);
  617. }
  618. return result;
  619. }