2022-09-30 14:50:45 +00:00
|
|
|
import { ExcalidrawApp } from '@jitsi/excalidraw';
|
2022-10-11 10:47:54 +00:00
|
|
|
import clsx from 'clsx';
|
2022-09-30 14:50:45 +00:00
|
|
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
2022-10-19 08:42:54 +00:00
|
|
|
// @ts-expect-error
|
2022-09-30 14:50:45 +00:00
|
|
|
import Filmstrip from '../../../../../modules/UI/videolayout/Filmstrip';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { IReduxState } from '../../../app/types';
|
2023-02-28 14:52:06 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { getLocalParticipant } from '../../../base/participants/functions';
|
2022-09-30 14:50:45 +00:00
|
|
|
import { getVerticalViewMaxWidth } from '../../../filmstrip/functions.web';
|
|
|
|
import { getToolboxHeight } from '../../../toolbox/functions.web';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { shouldDisplayTileView } from '../../../video-layout/functions.any';
|
|
|
|
import { WHITEBOARD_UI_OPTIONS } from '../../constants';
|
2022-09-30 14:50:45 +00:00
|
|
|
import {
|
|
|
|
getCollabDetails,
|
|
|
|
getCollabServerUrl,
|
|
|
|
isWhiteboardOpen,
|
|
|
|
isWhiteboardVisible
|
|
|
|
} from '../../functions';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Space taken by meeting elements like the subject and the watermark.
|
|
|
|
*/
|
|
|
|
const HEIGHT_OFFSET = 80;
|
|
|
|
|
|
|
|
interface IDimensions {
|
|
|
|
|
|
|
|
/* The height of the component. */
|
|
|
|
height: string;
|
|
|
|
|
|
|
|
/* The width of the component. */
|
|
|
|
width: string;
|
|
|
|
}
|
|
|
|
|
2023-02-28 14:52:06 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@link Component} props of {@link Whiteboard}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function;
|
|
|
|
};
|
|
|
|
|
2022-09-30 14:50:45 +00:00
|
|
|
/**
|
|
|
|
* The Whiteboard component.
|
|
|
|
*
|
2023-02-28 14:52:06 +00:00
|
|
|
* @param {Props} props - The React props passed to this component.
|
2022-09-30 14:50:45 +00:00
|
|
|
* @returns {JSX.Element} - The React component.
|
|
|
|
*/
|
2023-02-28 14:52:06 +00:00
|
|
|
const Whiteboard = (props: Props): JSX.Element => {
|
2022-09-30 14:50:45 +00:00
|
|
|
const excalidrawRef = useRef<any>(null);
|
|
|
|
const collabAPIRef = useRef<any>(null);
|
|
|
|
|
|
|
|
const isOpen = useSelector(isWhiteboardOpen);
|
|
|
|
const isVisible = useSelector(isWhiteboardVisible);
|
|
|
|
const isInTileView = useSelector(shouldDisplayTileView);
|
2022-10-20 09:11:27 +00:00
|
|
|
const { clientHeight, clientWidth } = useSelector((state: IReduxState) => state['features/base/responsive-ui']);
|
|
|
|
const { visible: filmstripVisible, isResizing } = useSelector((state: IReduxState) => state['features/filmstrip']);
|
2022-09-30 14:50:45 +00:00
|
|
|
const filmstripWidth: number = useSelector(getVerticalViewMaxWidth);
|
|
|
|
const collabDetails = useSelector(getCollabDetails);
|
|
|
|
const collabServerUrl = useSelector(getCollabServerUrl);
|
2022-10-20 09:11:27 +00:00
|
|
|
const { defaultRemoteDisplayName } = useSelector((state: IReduxState) => state['features/base/config']);
|
2022-09-30 14:50:45 +00:00
|
|
|
const localParticipantName = useSelector(getLocalParticipant)?.name || defaultRemoteDisplayName || 'Fellow Jitster';
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!collabAPIRef.current) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
collabAPIRef.current.setUsername(localParticipantName);
|
|
|
|
}, [ localParticipantName ]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the width and the height of the component.
|
|
|
|
*
|
|
|
|
* @returns {IDimensions} - The dimensions of the component.
|
|
|
|
*/
|
|
|
|
const getDimensions = (): IDimensions => {
|
|
|
|
let width: number;
|
|
|
|
let height: number;
|
|
|
|
|
|
|
|
if (interfaceConfig.VERTICAL_FILMSTRIP) {
|
|
|
|
if (filmstripVisible) {
|
|
|
|
width = clientWidth - filmstripWidth;
|
|
|
|
} else {
|
|
|
|
width = clientWidth;
|
|
|
|
}
|
|
|
|
height = clientHeight - getToolboxHeight();
|
|
|
|
} else {
|
|
|
|
if (filmstripVisible) {
|
|
|
|
height = clientHeight - Filmstrip.getFilmstripHeight();
|
|
|
|
} else {
|
|
|
|
height = clientHeight;
|
|
|
|
}
|
|
|
|
width = clientWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
width: `${width}px`,
|
|
|
|
height: `${height - HEIGHT_OFFSET}px`
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const getCollabAPI = useCallback(collabAPI => {
|
|
|
|
if (collabAPIRef.current) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
collabAPIRef.current = collabAPI;
|
|
|
|
collabAPIRef.current.setUsername(localParticipantName);
|
|
|
|
}, [ localParticipantName ]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = { clsx(
|
|
|
|
isResizing && 'disable-pointer',
|
|
|
|
'whiteboard-container'
|
|
|
|
) }
|
|
|
|
style = {{
|
|
|
|
...getDimensions(),
|
|
|
|
marginTop: `${HEIGHT_OFFSET}px`,
|
|
|
|
display: `${isInTileView || !isVisible ? 'none' : 'block'}`
|
|
|
|
}}>
|
|
|
|
{
|
|
|
|
isOpen && (
|
|
|
|
<div className = 'excalidraw-wrapper'>
|
2023-02-28 14:52:06 +00:00
|
|
|
{/*
|
|
|
|
* Excalidraw renders a few lvl 2 headings. This is
|
|
|
|
* quite fortunate, because we actually use lvl 1
|
|
|
|
* headings to mark the big sections of our app. So make
|
|
|
|
* sure to mark the Excalidraw context with a lvl 1
|
|
|
|
* heading before showing the whiteboard.
|
|
|
|
*/
|
|
|
|
<span
|
|
|
|
aria-level = { 1 }
|
|
|
|
className = 'sr-only'
|
|
|
|
role = 'heading'>
|
|
|
|
{ props.t('whiteboard.accessibilityLabel.heading') }
|
|
|
|
</span>
|
|
|
|
}
|
2022-09-30 14:50:45 +00:00
|
|
|
<ExcalidrawApp
|
|
|
|
collabDetails = { collabDetails }
|
|
|
|
collabServerUrl = { collabServerUrl }
|
|
|
|
excalidraw = {{
|
|
|
|
isCollaborating: true,
|
2022-11-28 10:52:45 +00:00
|
|
|
|
2022-09-30 14:50:45 +00:00
|
|
|
// @ts-ignore
|
|
|
|
ref: excalidrawRef,
|
|
|
|
theme: 'light',
|
|
|
|
UIOptions: WHITEBOARD_UI_OPTIONS
|
|
|
|
}}
|
|
|
|
getCollabAPI = { getCollabAPI } />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-02-28 14:52:06 +00:00
|
|
|
export default translate(Whiteboard);
|