Skip to content

Commit

Permalink
fix: close whiteboard on starting screenshare
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn committed Mar 18, 2024
1 parent f4c6253 commit bb01559
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ import { useScreenShare, useWhiteboard } from '@100mslive/react-sdk';
* close existing screenshare or whiteboard when the other is started
*/
export const useCloseScreenshareWhiteboard = () => {
const { amIScreenSharing, toggleScreenShare } = useScreenShare();
const { amIScreenSharing, screenSharingPeerId, toggleScreenShare } = useScreenShare();
const { isOwner: isWhiteboardOwner, toggle: toggleWhiteboard } = useWhiteboard();
const prevScreenSharer = usePrevious(amIScreenSharing);
const prevScreenSharer = usePrevious(screenSharingPeerId);
const prevWhiteboardOwner = usePrevious(isWhiteboardOwner);

// if both screenshare and whiteboard are open, close the one that was open earlier
useEffect(() => {
if (isWhiteboardOwner && amIScreenSharing) {
if (prevScreenSharer && !prevWhiteboardOwner) {
if (isWhiteboardOwner && screenSharingPeerId) {
if (prevScreenSharer && amIScreenSharing && !prevWhiteboardOwner) {
toggleScreenShare?.();
} else if (prevWhiteboardOwner && !prevScreenSharer) {
toggleWhiteboard?.();
}
}
}, [isWhiteboardOwner, amIScreenSharing, prevScreenSharer, prevWhiteboardOwner, toggleScreenShare, toggleWhiteboard]);
}, [
isWhiteboardOwner,
screenSharingPeerId,
amIScreenSharing,
prevScreenSharer,
prevWhiteboardOwner,
toggleScreenShare,
toggleWhiteboard,
]);
};

0 comments on commit bb01559

Please sign in to comment.