Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.ts 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import md5 from 'js-md5';
  2. import { getParticipantCount, getPinnedParticipant } from '../../features/base/participants/functions';
  3. import { IReduxState } from '../app/types';
  4. import { getCurrentConference } from '../base/conference/functions';
  5. import { IWhiteboardConfig } from '../base/config/configType';
  6. import { getRemoteParticipants, isLocalParticipantModerator } from '../base/participants/functions';
  7. import { appendURLParam } from '../base/util/uri';
  8. import { getCurrentRoomId, isInBreakoutRoom } from '../breakout-rooms/functions';
  9. import { MIN_USER_LIMIT, USER_LIMIT_THRESHOLD, WHITEBOARD_ID } from './constants';
  10. import { IWhiteboardState } from './reducer';
  11. const getWhiteboardState = (state: IReduxState): IWhiteboardState => state['features/whiteboard'];
  12. export const getWhiteboardConfig = (state: IReduxState): IWhiteboardConfig =>
  13. state['features/base/config'].whiteboard || {};
  14. const getWhiteboardUserLimit = (state: IReduxState): number => {
  15. const userLimit = getWhiteboardConfig(state).userLimit || Infinity;
  16. return userLimit === Infinity
  17. ? userLimit
  18. : Math.max(Number(getWhiteboardConfig(state).userLimit || 1), MIN_USER_LIMIT);
  19. };
  20. /**
  21. * Returns the whiteboard collaboration details.
  22. *
  23. * @param {IReduxState} state - The state from the Redux store.
  24. * @returns {{ roomId: string, roomKey: string}|undefined}
  25. */
  26. export const getCollabDetails = (state: IReduxState): {
  27. roomId: string; roomKey: string;
  28. } | undefined => getWhiteboardState(state).collabDetails;
  29. /**
  30. * Indicates whether the whiteboard is enabled in the config.
  31. *
  32. * @param {IReduxState} state - The state from the Redux store.
  33. * @returns {boolean}
  34. */
  35. export const isWhiteboardEnabled = (state: IReduxState): boolean =>
  36. getWhiteboardConfig(state).enabled
  37. && getWhiteboardConfig(state).collabServerBaseUrl
  38. && getCurrentConference(state)?.getMetadataHandler()
  39. ?.isSupported();
  40. /**
  41. * Indicates whether the whiteboard has the collaboration
  42. * details and is ready to be used.
  43. *
  44. * @param {IReduxState} state - The state from the Redux store.
  45. * @returns {boolean}
  46. */
  47. export const isWhiteboardReady = (state: IReduxState): boolean =>
  48. isWhiteboardEnabled(state) && Boolean(getCollabDetails(state));
  49. /**
  50. * Indicates whether the whiteboard is open.
  51. *
  52. * @param {IReduxState} state - The state from the Redux store.
  53. * @returns {boolean}
  54. */
  55. export const isWhiteboardOpen = (state: IReduxState): boolean => getWhiteboardState(state).isOpen;
  56. /**
  57. * Indicates whether the whiteboard button is visible.
  58. *
  59. * @param {IReduxState} state - The state from the Redux store.
  60. * @returns {boolean}
  61. */
  62. export const isWhiteboardButtonVisible = (state: IReduxState): boolean =>
  63. isWhiteboardEnabled(state) && (isLocalParticipantModerator(state) || isWhiteboardOpen(state));
  64. /**
  65. * Indicates whether the whiteboard is present as a meeting participant.
  66. *
  67. * @param {IReduxState} state - The state from the Redux store.
  68. * @returns {boolean}
  69. */
  70. export const isWhiteboardPresent = (state: IReduxState): boolean => getRemoteParticipants(state).has(WHITEBOARD_ID);
  71. /**
  72. * Returns the whiteboard collaboration server url.
  73. *
  74. * @param {IReduxState} state - The state from the Redux store.
  75. * @returns {string}
  76. */
  77. export const getCollabServerUrl = (state: IReduxState): string | undefined => {
  78. const collabServerBaseUrl = getWhiteboardConfig(state).collabServerBaseUrl;
  79. if (!collabServerBaseUrl) {
  80. return;
  81. }
  82. const { locationURL } = state['features/base/connection'];
  83. const inBreakoutRoom = isInBreakoutRoom(state);
  84. const roomId = getCurrentRoomId(state);
  85. const room = md5.hex(`${locationURL?.origin}${locationURL?.pathname}${inBreakoutRoom ? `|${roomId}` : ''}`);
  86. return appendURLParam(collabServerBaseUrl, 'room', room);
  87. };
  88. /**
  89. * Whether the whiteboard is visible on stage.
  90. *
  91. * @param {IReduxState} state - The state from the Redux store.
  92. * @returns {boolean}
  93. */
  94. export const isWhiteboardVisible = (state: IReduxState): boolean =>
  95. getPinnedParticipant(state)?.id === WHITEBOARD_ID
  96. || state['features/large-video'].participantId === WHITEBOARD_ID;
  97. /**
  98. * Indicates whether the whiteboard is accessible to a participant that has a moderator role.
  99. *
  100. * @param {IReduxState} state - The state from the Redux store.
  101. * @returns {boolean}
  102. */
  103. export const isWhiteboardAllowed = (state: IReduxState): boolean =>
  104. isWhiteboardEnabled(state) && isLocalParticipantModerator(state);
  105. /**
  106. * Whether to enforce the whiteboard user limit.
  107. *
  108. * @param {IReduxState} state - The state from the Redux store.
  109. * @returns {boolean}
  110. */
  111. export const shouldEnforceUserLimit = (state: IReduxState): boolean => {
  112. const userLimit = getWhiteboardUserLimit(state);
  113. if (userLimit === Infinity) {
  114. return false;
  115. }
  116. const participantCount = getParticipantCount(state);
  117. return participantCount > userLimit;
  118. };
  119. /**
  120. * Whether to show a warning about the whiteboard user limit.
  121. *
  122. * @param {IReduxState} state - The state from the Redux store.
  123. * @returns {boolean}
  124. */
  125. export const shouldNotifyUserLimit = (state: IReduxState): boolean => {
  126. const userLimit = getWhiteboardUserLimit(state);
  127. if (userLimit === Infinity) {
  128. return false;
  129. }
  130. const participantCount = getParticipantCount(state);
  131. return participantCount + USER_LIMIT_THRESHOLD > userLimit;
  132. };