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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. import {
  3. CONFERENCE_JOINED,
  4. VIDEO_QUALITY_LEVELS,
  5. setMaxReceiverVideoQuality,
  6. setPreferredVideoQuality
  7. } from '../base/conference';
  8. import { getParticipantCount } from '../base/participants';
  9. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  10. import { shouldDisplayTileView } from '../video-layout';
  11. import { getReceiverVideoQualityLevel } from './functions';
  12. import logger from './logger';
  13. import { getMinHeightForQualityLvlMap } from './selector';
  14. /**
  15. * Implements the middleware of the feature video-quality.
  16. *
  17. * @param {Store} store - The redux store.
  18. * @returns {Function}
  19. */
  20. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  21. const result = next(action);
  22. switch (action.type) {
  23. case CONFERENCE_JOINED: {
  24. if (navigator.product === 'ReactNative') {
  25. const { resolution } = getState()['features/base/config'];
  26. if (typeof resolution !== 'undefined') {
  27. dispatch(setPreferredVideoQuality(Number.parseInt(resolution, 10)));
  28. logger.info(`Configured preferred receiver video frame height to: ${resolution}`);
  29. }
  30. }
  31. break;
  32. }
  33. }
  34. return result;
  35. });
  36. /**
  37. * Implements a state listener in order to calculate max receiver video quality.
  38. */
  39. StateListenerRegistry.register(
  40. /* selector */ state => {
  41. const { reducedUI } = state['features/base/responsive-ui'];
  42. const _shouldDisplayTileView = shouldDisplayTileView(state);
  43. const thumbnailSize = state['features/filmstrip']?.tileViewDimensions?.thumbnailSize;
  44. const participantCount = getParticipantCount(state);
  45. return {
  46. displayTileView: _shouldDisplayTileView,
  47. participantCount,
  48. reducedUI,
  49. thumbnailHeight: thumbnailSize?.height
  50. };
  51. },
  52. /* listener */ ({ displayTileView, participantCount, reducedUI, thumbnailHeight }, { dispatch, getState }) => {
  53. const state = getState();
  54. const { maxReceiverVideoQuality } = state['features/base/conference'];
  55. const { maxFullResolutionParticipants = 2 } = state['features/base/config'];
  56. let newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.HIGH;
  57. if (reducedUI) {
  58. newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.LOW;
  59. } else if (displayTileView && !Number.isNaN(thumbnailHeight)) {
  60. newMaxRecvVideoQuality = getReceiverVideoQualityLevel(thumbnailHeight, getMinHeightForQualityLvlMap(state));
  61. // Override HD level calculated for the thumbnail height when # of participants threshold is exceeded
  62. if (maxReceiverVideoQuality !== newMaxRecvVideoQuality && maxFullResolutionParticipants !== -1) {
  63. const override
  64. = participantCount > maxFullResolutionParticipants
  65. && newMaxRecvVideoQuality > VIDEO_QUALITY_LEVELS.STANDARD;
  66. logger.info(`Video quality level for thumbnail height: ${thumbnailHeight}, `
  67. + `is: ${newMaxRecvVideoQuality}, `
  68. + `override: ${String(override)}, `
  69. + `max full res N: ${maxFullResolutionParticipants}`);
  70. if (override) {
  71. newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.STANDARD;
  72. }
  73. }
  74. }
  75. if (maxReceiverVideoQuality !== newMaxRecvVideoQuality) {
  76. dispatch(setMaxReceiverVideoQuality(newMaxRecvVideoQuality));
  77. }
  78. }, {
  79. deepEquals: true
  80. });