Skip to content

Commit

Permalink
fix: disable whiteboard toggle during remote screenshare
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn committed Mar 18, 2024
1 parent 4703903 commit f4c6253
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useWhiteboard } from '@100mslive/react-sdk';
import { useScreenShare, useWhiteboard } from '@100mslive/react-sdk';
import { PencilDrawIcon } from '@100mslive/react-icons';
import { Tooltip } from '../../..';
// @ts-ignore: No implicit Any
Expand All @@ -9,22 +9,36 @@ import { ToastManager } from '../Toast/ToastManager';

export const WhiteboardToggle = () => {
const { toggle, open, isOwner } = useWhiteboard();
const { screenSharingPeerId, amIScreenSharing } = useScreenShare();
const remoteScreenShare = screenSharingPeerId && !amIScreenSharing;
const disabled = remoteScreenShare || (open && !isOwner);

if (!toggle) {
return null;
}

return (
<Tooltip key="whiteboard" title={`${open ? 'Close' : 'Open'} Whiteboard`}>
<Tooltip
key="whiteboard"
title={
remoteScreenShare
? 'Cannot open whiteboard when viewing a shared screen'
: `${open ? 'Close' : 'Open'} Whiteboard`
}
>
<IconButton
onClick={async () => {
if (disabled) {
return;
}
try {
await toggle();
} catch (error) {
ToastManager.addToast({ title: (error as Error).message, variant: 'error' });
}
}}
active={!open}
disabled={open && !isOwner}
disabled={disabled}
data-testid="whiteboard_btn"
>
<PencilDrawIcon />
Expand Down

0 comments on commit f4c6253

Please sign in to comment.