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

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