From ab349b42c7bba2768676665b35290fb76c4a8fb3 Mon Sep 17 00:00:00 2001 From: "Eswar Prasad Clinton. A" <64120992+eswarclynn@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:11:20 +0530 Subject: [PATCH] fix: whiteboard layout, toggle with screenshare --- .../src/IconButton/IconButton.tsx | 9 +- .../roomkit-react/src/Prebuilt/IconButton.tsx | 16 ++-- .../components/Footer/WhiteboardToggle.tsx | 20 +++- .../IconButtonWithOptions.tsx | 14 +-- .../components/VideoLayouts/GridLayout.tsx | 31 +++++- .../VideoLayouts/WhiteboardLayout.tsx | 95 +++++++++++++++++++ .../hooks/useCloseScreenshareWhiteboard.tsx | 18 +++- .../layouts/VideoStreamingSection.tsx | 18 +--- .../src/Prebuilt/layouts/WhiteboardView.tsx | 69 -------------- 9 files changed, 168 insertions(+), 122 deletions(-) create mode 100644 packages/roomkit-react/src/Prebuilt/components/VideoLayouts/WhiteboardLayout.tsx delete mode 100644 packages/roomkit-react/src/Prebuilt/layouts/WhiteboardView.tsx diff --git a/packages/roomkit-react/src/IconButton/IconButton.tsx b/packages/roomkit-react/src/IconButton/IconButton.tsx index c66cc5b0a8..297137cfb6 100644 --- a/packages/roomkit-react/src/IconButton/IconButton.tsx +++ b/packages/roomkit-react/src/IconButton/IconButton.tsx @@ -25,19 +25,14 @@ export const IconButton = styled('button', { '&[disabled]': { opacity: 0.5, cursor: 'not-allowed', + backgroundColor: '$secondary_dim', + color: '$on_primary_high', }, '&:focus': { outline: 'none', }, variants: { active: { - false: { - backgroundColor: '$secondary_dim', - color: '$on_primary_high', - '&:not([disabled]):hover': { - backgroundColor: '$secondary_default', - }, - }, true: { '&:not([disabled]):hover': { backgroundColor: '$on_surface_low', diff --git a/packages/roomkit-react/src/Prebuilt/IconButton.tsx b/packages/roomkit-react/src/Prebuilt/IconButton.tsx index 3694779ad8..e66d9a6330 100644 --- a/packages/roomkit-react/src/Prebuilt/IconButton.tsx +++ b/packages/roomkit-react/src/Prebuilt/IconButton.tsx @@ -7,22 +7,18 @@ const IconButton = styled(BaseIconButton, { border: '1px solid $border_bright', bg: '$background_dim', r: '$1', + '&[disabled]': { + opacity: 0.5, + cursor: 'not-allowed', + backgroundColor: '$secondary_dim', + color: '$on_primary_high', + }, variants: { active: { true: { color: '$on_surface_high', backgroundColor: 'transparent', }, - false: { - border: '1px solid transparent', - color: '$on_primary_high', - }, - }, - disabled: { - true: { - backgroundColor: '$surface_brighter', - color: '$on_surface_low', - }, }, }, }); diff --git a/packages/roomkit-react/src/Prebuilt/components/Footer/WhiteboardToggle.tsx b/packages/roomkit-react/src/Prebuilt/components/Footer/WhiteboardToggle.tsx index a6abde09c3..0cb9efd262 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Footer/WhiteboardToggle.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Footer/WhiteboardToggle.tsx @@ -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 @@ -9,14 +9,28 @@ 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 ( - + { + if (disabled) { + return; + } try { await toggle(); } catch (error) { @@ -24,7 +38,7 @@ export const WhiteboardToggle = () => { } }} active={!open} - disabled={open && !isOwner} + disabled={disabled} data-testid="whiteboard_btn" > diff --git a/packages/roomkit-react/src/Prebuilt/components/IconButtonWithOptions/IconButtonWithOptions.tsx b/packages/roomkit-react/src/Prebuilt/components/IconButtonWithOptions/IconButtonWithOptions.tsx index e6e9be3b62..cf36bc6c3f 100644 --- a/packages/roomkit-react/src/Prebuilt/components/IconButtonWithOptions/IconButtonWithOptions.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/IconButtonWithOptions/IconButtonWithOptions.tsx @@ -25,9 +25,9 @@ const IconSection = styled(IconButton, { p: '$4', r: '$1', bg: 'transparent', - borderTopRightRadius: 0, + borderTopRightRadius: '0 !important', borderColor: '$border_bright', - borderBottomRightRadius: 0, + borderBottomRightRadius: '0 !important', position: 'relative', '&:not([disabled]):focus-visible': { zIndex: 1, @@ -41,8 +41,8 @@ const IconSection = styled(IconButton, { ...variants, hideOptions: { true: { - borderTopRightRadius: '$1', - borderBottomRightRadius: '$1', + borderTopRightRadius: '$1 !important', + borderBottomRightRadius: '$1 !important', }, }, }, @@ -53,10 +53,10 @@ const OptionsSection = styled(IconButton, { h: '$14', p: '$4 $2', r: '$1', - borderTopLeftRadius: 0, + borderTopLeftRadius: '0 !important', borderColor: '$border_bright', - borderBottomLeftRadius: 0, - borderLeftWidth: 0, + borderBottomLeftRadius: '0 !important', + borderLeftWidth: '0 !important', position: 'relative', '&:not([disabled]):focus-visible': { zIndex: 1, diff --git a/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/GridLayout.tsx b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/GridLayout.tsx index 6d64429aea..82b1d47186 100644 --- a/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/GridLayout.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/GridLayout.tsx @@ -5,12 +5,14 @@ import { selectLocalPeerRoleName, selectPeers, selectPeerScreenSharing, + selectWhiteboard, useHMSStore, useHMSVanillaStore, } from '@100mslive/react-sdk'; import { EqualProminence } from './EqualProminence'; import { RoleProminence } from './RoleProminence'; import { ScreenshareLayout } from './ScreenshareLayout'; +import { WhiteboardLayout } from './WhiteboardLayout'; // @ts-ignore: No implicit Any import { usePinnedTrack, useSetAppDataByKey } from '../AppData/useUISettings'; import { VideoTileContext } from '../hooks/useVideoTileLayout'; @@ -40,6 +42,7 @@ export const GridLayout = ({ hide_metadata_on_tile = false, }: GridLayoutProps) => { const peerSharing = useHMSStore(selectPeerScreenSharing); + const whiteboard = useHMSStore(selectWhiteboard); const pinnedTrack = usePinnedTrack(); const peers = useHMSStore(selectPeers); const localPeerRole = useHMSStore(selectLocalPeerRoleName); @@ -53,9 +56,9 @@ export const GridLayout = ({ )) || pinnedTrack; const updatedPeers = useMemo(() => { - // remove screenshare peer from active speaker sorting - if (activeScreensharePeerId) { - return peers.filter(peer => peer.id !== activeScreensharePeerId); + // remove screenshare/whiteboard peer from active speaker sorting + if (activeScreensharePeerId || whiteboard?.open) { + return peers.filter(peer => peer.id !== activeScreensharePeerId || peer.customerUserId !== whiteboard?.owner); } if (isInsetEnabled) { const isLocalPeerPinned = localPeerID === pinnedTrack?.peerId; @@ -67,7 +70,16 @@ export const GridLayout = ({ } } return peers; - }, [isInsetEnabled, activeScreensharePeerId, localPeerRole, localPeerID, prominentRoles, peers, pinnedTrack]); + }, [ + isInsetEnabled, + whiteboard, + activeScreensharePeerId, + localPeerRole, + localPeerID, + prominentRoles, + peers, + pinnedTrack, + ]); const vanillaStore = useHMSVanillaStore(); const [sortedPeers, setSortedPeers] = useState(updatedPeers); const peersSorter = useMemo(() => new PeersSorter(vanillaStore), [vanillaStore]); @@ -104,6 +116,17 @@ export const GridLayout = ({ /> ); + } else if (whiteboard?.open) { + return ( + + + + ); } else if (isRoleProminence) { return ( diff --git a/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/WhiteboardLayout.tsx b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/WhiteboardLayout.tsx new file mode 100644 index 0000000000..56155fec88 --- /dev/null +++ b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/WhiteboardLayout.tsx @@ -0,0 +1,95 @@ +import React, { useEffect, useMemo } from 'react'; +import { useMedia } from 'react-use'; +import { selectPeerByCondition, selectWhiteboard, useHMSStore, useWhiteboard } from '@100mslive/react-sdk'; +import { Box } from '../../../Layout'; +import { config as cssConfig } from '../../../Theme'; +import { InsetTile } from '../InsetTile'; +import { SecondaryTiles } from '../SecondaryTiles'; +import { LayoutMode } from '../Settings/LayoutSettings'; +import { LayoutProps } from './interface'; +import { ProminenceLayout } from './ProminenceLayout'; +// @ts-ignore: No implicit Any +import { useSetUiSettings } from '../AppData/useUISettings'; +import { UI_SETTINGS } from '../../common/constants'; + +const WhiteboardEmbed = () => { + const isMobile = useMedia(cssConfig.media.md); + const { iframeRef } = useWhiteboard(isMobile); + + return ( + +