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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // @flow
  2. import {
  3. CONFERENCE_JOINED,
  4. VIDEO_QUALITY_LEVELS,
  5. getNearestReceiverVideoQualityLevel,
  6. setMaxReceiverVideoQuality,
  7. setPreferredVideoQuality
  8. } from '../base/conference';
  9. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  10. import { shouldDisplayTileView } from '../video-layout';
  11. import logger from './logger';
  12. /**
  13. * Implements the middleware of the feature video-quality.
  14. *
  15. * @param {Store} store - The redux store.
  16. * @returns {Function}
  17. */
  18. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  19. const result = next(action);
  20. switch (action.type) {
  21. case CONFERENCE_JOINED: {
  22. if (navigator.product === 'ReactNative') {
  23. const { resolution } = getState()['features/base/config'];
  24. if (typeof resolution !== 'undefined') {
  25. dispatch(setPreferredVideoQuality(Number.parseInt(resolution, 10)));
  26. logger.info(`Configured preferred receiver video frame height to: ${resolution}`);
  27. }
  28. }
  29. break;
  30. }
  31. }
  32. return result;
  33. });
  34. /**
  35. * Implements a state listener in order to calculate max receiver video quality.
  36. */
  37. StateListenerRegistry.register(
  38. /* selector */ state => {
  39. const { reducedUI } = state['features/base/responsive-ui'];
  40. const _shouldDisplayTileView = shouldDisplayTileView(state);
  41. const thumbnailSize = state['features/filmstrip']?.tileViewDimensions?.thumbnailSize;
  42. return {
  43. displayTileView: _shouldDisplayTileView,
  44. reducedUI,
  45. thumbnailHeight: thumbnailSize?.height
  46. };
  47. },
  48. /* listener */ ({ displayTileView, reducedUI, thumbnailHeight }, { dispatch, getState }) => {
  49. const { maxReceiverVideoQuality } = getState()['features/base/conference'];
  50. let newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.HIGH;
  51. if (reducedUI) {
  52. newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.LOW;
  53. } else if (displayTileView && !Number.isNaN(thumbnailHeight)) {
  54. newMaxRecvVideoQuality = getNearestReceiverVideoQualityLevel(thumbnailHeight);
  55. }
  56. if (maxReceiverVideoQuality !== newMaxRecvVideoQuality) {
  57. dispatch(setMaxReceiverVideoQuality(newMaxRecvVideoQuality));
  58. }
  59. }, {
  60. deepEquals: true
  61. });