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.

subscriber.web.ts 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { throttle } from 'lodash';
  2. import { IReduxState, IStore } from '../app/types';
  3. import { getParticipantCount } from '../base/participants/functions';
  4. import StateListenerRegistry from '../base/redux/StateListenerRegistry';
  5. import { DEFAULT_MAX_COLUMNS } from '../filmstrip/constants';
  6. import { isLayoutTileView } from '../video-layout/functions.any';
  7. import { setShiftUp } from './actions.any';
  8. import { isAudioMuteButtonDisabled } from './functions.any';
  9. /**
  10. * Notifies when audio availability changes.
  11. */
  12. StateListenerRegistry.register(
  13. /* selector */ (state: IReduxState) => isAudioMuteButtonDisabled(state),
  14. /* listener */ (disabled: boolean, store: IStore, previousDisabled: boolean) => {
  15. if (disabled !== previousDisabled) {
  16. APP.API.notifyAudioAvailabilityChanged(!disabled);
  17. }
  18. }
  19. );
  20. const checkToolboxOverlap = (clientHeight: number, store: IStore) => {
  21. let toolboxRect = document.querySelector('.toolbox-content-items')?.getBoundingClientRect();
  22. if (!toolboxRect) {
  23. return;
  24. }
  25. const tiles = document.querySelectorAll('span.videocontainer');
  26. if (!tiles.length) {
  27. return;
  28. }
  29. const toolboxHeight = 48 + 12; // height + padding
  30. const bottomMargin = 16;
  31. // Set top and bottom manually to avoid wrong coordinates
  32. // caused by the hiding/ showing of the toolbox.
  33. toolboxRect = {
  34. ...toolboxRect,
  35. top: clientHeight - toolboxHeight - bottomMargin,
  36. bottom: clientHeight - bottomMargin,
  37. left: toolboxRect.left,
  38. right: toolboxRect.right
  39. };
  40. let isIntersecting = false;
  41. const rows = store.getState()['features/filmstrip'].tileViewDimensions?.gridDimensions?.rows;
  42. const noOfTilesToCheck = rows === 1 ? tiles.length : DEFAULT_MAX_COLUMNS - 1;
  43. for (let i = 1; i < Math.max(noOfTilesToCheck, tiles.length); i++) {
  44. const tile = tiles[tiles.length - i];
  45. const indicatorsRect = tile?.querySelector('.bottom-indicators')?.getBoundingClientRect();
  46. if (!indicatorsRect) {
  47. // eslint-disable-next-line no-continue
  48. continue;
  49. }
  50. if (indicatorsRect.top <= toolboxRect.bottom
  51. && indicatorsRect.right >= toolboxRect.left
  52. && indicatorsRect.bottom >= toolboxRect.top
  53. && indicatorsRect.left <= toolboxRect.right
  54. ) {
  55. isIntersecting = true;
  56. break;
  57. }
  58. }
  59. store.dispatch(setShiftUp(isIntersecting));
  60. };
  61. const throttledCheckOverlap = throttle(checkToolboxOverlap, 100, {
  62. leading: false,
  63. trailing: true
  64. });
  65. /**
  66. * Listens for changes in the selected layout to calculate the dimensions of the tile view grid and horizontal view.
  67. */
  68. StateListenerRegistry.register(
  69. /* selector */ state => {
  70. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  71. return {
  72. participantCount: getParticipantCount(state),
  73. clientHeight,
  74. clientWidth,
  75. isTileView: isLayoutTileView(state)
  76. };
  77. },
  78. /* listener */({ clientHeight, isTileView }, store, previousState) => {
  79. if (!isTileView) {
  80. if (previousState?.isTileView) {
  81. store.dispatch(setShiftUp(false));
  82. }
  83. return;
  84. }
  85. throttledCheckOverlap(clientHeight, store);
  86. }, {
  87. deepEquals: true
  88. });