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.

functions.ts 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import md5 from 'js-md5';
  2. import { getPinnedParticipant } from '../../features/base/participants/functions';
  3. import { IReduxState } from '../app/types';
  4. import { getCurrentConference } from '../base/conference/functions';
  5. import { getRemoteParticipants, isLocalParticipantModerator } from '../base/participants/functions';
  6. import { appendURLParam } from '../base/util/uri';
  7. import { getCurrentRoomId, isInBreakoutRoom } from '../breakout-rooms/functions';
  8. import { WHITEBOARD_ID } from './constants';
  9. import { IWhiteboardState } from './reducer';
  10. const getWhiteboardState = (state: IReduxState): IWhiteboardState => state['features/whiteboard'];
  11. /**
  12. * Indicates whether the whiteboard is enabled in the config.
  13. *
  14. * @param {IReduxState} state - The state from the Redux store.
  15. * @returns {boolean}
  16. */
  17. export const isWhiteboardEnabled = (state: IReduxState): boolean =>
  18. state['features/base/config'].whiteboard?.enabled
  19. && state['features/base/config'].whiteboard?.collabServerBaseUrl
  20. && getCurrentConference(state)?.getMetadataHandler()
  21. ?.isSupported();
  22. /**
  23. * Indicates whether the whiteboard is open.
  24. *
  25. * @param {IReduxState} state - The state from the Redux store.
  26. * @returns {boolean}
  27. */
  28. export const isWhiteboardOpen = (state: IReduxState): boolean => getWhiteboardState(state).isOpen;
  29. /**
  30. * Indicates whether the whiteboard button is visible.
  31. *
  32. * @param {IReduxState} state - The state from the Redux store.
  33. * @returns {boolean}
  34. */
  35. export const isWhiteboardButtonVisible = (state: IReduxState): boolean =>
  36. isWhiteboardEnabled(state) && (isLocalParticipantModerator(state) || isWhiteboardOpen(state));
  37. /**
  38. * Indicates whether the whiteboard is present as a meeting participant.
  39. *
  40. * @param {IReduxState} state - The state from the Redux store.
  41. * @returns {boolean}
  42. */
  43. export const isWhiteboardPresent = (state: IReduxState): boolean => getRemoteParticipants(state).has(WHITEBOARD_ID);
  44. /**
  45. * Returns the whiteboard collaboration details.
  46. *
  47. * @param {IReduxState} state - The state from the Redux store.
  48. * @returns {{ roomId: string, roomKey: string}|undefined}
  49. */
  50. export const getCollabDetails = (state: IReduxState): {
  51. roomId: string; roomKey: string;
  52. } | undefined => getWhiteboardState(state).collabDetails;
  53. /**
  54. * Returns the whiteboard collaboration server url.
  55. *
  56. * @param {IReduxState} state - The state from the Redux store.
  57. * @returns {string}
  58. */
  59. export const getCollabServerUrl = (state: IReduxState): string | undefined => {
  60. const collabServerBaseUrl = state['features/base/config'].whiteboard?.collabServerBaseUrl;
  61. if (!collabServerBaseUrl) {
  62. return;
  63. }
  64. const { locationURL } = state['features/base/connection'];
  65. const inBreakoutRoom = isInBreakoutRoom(state);
  66. const roomId = getCurrentRoomId(state);
  67. const room = md5.hex(`${locationURL?.href}${inBreakoutRoom ? `|${roomId}` : ''}`);
  68. return appendURLParam(collabServerBaseUrl, 'room', room);
  69. };
  70. /**
  71. * Whether the whiteboard is visible on stage.
  72. *
  73. * @param {IReduxState} state - The state from the Redux store.
  74. * @returns {boolean}
  75. */
  76. export const isWhiteboardVisible = (state: IReduxState): boolean =>
  77. getPinnedParticipant(state)?.id === WHITEBOARD_ID
  78. || state['features/large-video'].participantId === WHITEBOARD_ID;