Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

middleware.js 25KB

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