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.

Whiteboard.tsx 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* eslint-disable lines-around-comment */
  2. import { ExcalidrawApp } from '@jitsi/excalidraw';
  3. import clsx from 'clsx';
  4. import React, { useCallback, useEffect, useRef } from 'react';
  5. import { useSelector } from 'react-redux';
  6. // @ts-expect-error
  7. import Filmstrip from '../../../../../modules/UI/videolayout/Filmstrip';
  8. import { IReduxState } from '../../../app/types';
  9. import { getLocalParticipant } from '../../../base/participants/functions';
  10. // @ts-ignore
  11. import { getVerticalViewMaxWidth } from '../../../filmstrip/functions.web';
  12. import { getToolboxHeight } from '../../../toolbox/functions.web';
  13. // @ts-ignore
  14. import { shouldDisplayTileView } from '../../../video-layout/functions.any';
  15. import { WHITEBOARD_UI_OPTIONS } from '../../constants';
  16. import {
  17. getCollabDetails,
  18. getCollabServerUrl,
  19. isWhiteboardOpen,
  20. isWhiteboardVisible
  21. } from '../../functions';
  22. /**
  23. * Space taken by meeting elements like the subject and the watermark.
  24. */
  25. const HEIGHT_OFFSET = 80;
  26. declare const interfaceConfig: any;
  27. interface IDimensions {
  28. /* The height of the component. */
  29. height: string;
  30. /* The width of the component. */
  31. width: string;
  32. }
  33. /**
  34. * The Whiteboard component.
  35. *
  36. * @returns {JSX.Element} - The React component.
  37. */
  38. const Whiteboard: () => JSX.Element = () => {
  39. const excalidrawRef = useRef<any>(null);
  40. const collabAPIRef = useRef<any>(null);
  41. const isOpen = useSelector(isWhiteboardOpen);
  42. const isVisible = useSelector(isWhiteboardVisible);
  43. const isInTileView = useSelector(shouldDisplayTileView);
  44. const { clientHeight, clientWidth } = useSelector((state: IReduxState) => state['features/base/responsive-ui']);
  45. const { visible: filmstripVisible, isResizing } = useSelector((state: IReduxState) => state['features/filmstrip']);
  46. const filmstripWidth: number = useSelector(getVerticalViewMaxWidth);
  47. const collabDetails = useSelector(getCollabDetails);
  48. const collabServerUrl = useSelector(getCollabServerUrl);
  49. const { defaultRemoteDisplayName } = useSelector((state: IReduxState) => state['features/base/config']);
  50. const localParticipantName = useSelector(getLocalParticipant)?.name || defaultRemoteDisplayName || 'Fellow Jitster';
  51. useEffect(() => {
  52. if (!collabAPIRef.current) {
  53. return;
  54. }
  55. collabAPIRef.current.setUsername(localParticipantName);
  56. }, [ localParticipantName ]);
  57. /**
  58. * Computes the width and the height of the component.
  59. *
  60. * @returns {IDimensions} - The dimensions of the component.
  61. */
  62. const getDimensions = (): IDimensions => {
  63. let width: number;
  64. let height: number;
  65. if (interfaceConfig.VERTICAL_FILMSTRIP) {
  66. if (filmstripVisible) {
  67. width = clientWidth - filmstripWidth;
  68. } else {
  69. width = clientWidth;
  70. }
  71. height = clientHeight - getToolboxHeight();
  72. } else {
  73. if (filmstripVisible) {
  74. height = clientHeight - Filmstrip.getFilmstripHeight();
  75. } else {
  76. height = clientHeight;
  77. }
  78. width = clientWidth;
  79. }
  80. return {
  81. width: `${width}px`,
  82. height: `${height - HEIGHT_OFFSET}px`
  83. };
  84. };
  85. const getCollabAPI = useCallback(collabAPI => {
  86. if (collabAPIRef.current) {
  87. return;
  88. }
  89. collabAPIRef.current = collabAPI;
  90. collabAPIRef.current.setUsername(localParticipantName);
  91. }, [ localParticipantName ]);
  92. return (
  93. <div
  94. className = { clsx(
  95. isResizing && 'disable-pointer',
  96. 'whiteboard-container'
  97. ) }
  98. style = {{
  99. ...getDimensions(),
  100. marginTop: `${HEIGHT_OFFSET}px`,
  101. display: `${isInTileView || !isVisible ? 'none' : 'block'}`
  102. }}>
  103. {
  104. isOpen && (
  105. <div className = 'excalidraw-wrapper'>
  106. <ExcalidrawApp
  107. collabDetails = { collabDetails }
  108. collabServerUrl = { collabServerUrl }
  109. excalidraw = {{
  110. isCollaborating: true,
  111. // @ts-ignore
  112. ref: excalidrawRef,
  113. theme: 'light',
  114. UIOptions: WHITEBOARD_UI_OPTIONS
  115. }}
  116. getCollabAPI = { getCollabAPI } />
  117. </div>
  118. )
  119. }
  120. </div>
  121. );
  122. };
  123. export default Whiteboard;