Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Whiteboard.tsx 4.5KB

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