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