Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use attributebox for audioindicator #1952

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/roomkit-react/src/Prebuilt/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ export const formatTime = timeInSeconds => {
const hour = hours !== 0 ? `${hours < 10 ? '0' : ''}${hours}:` : '';
return `${hour}${minutes < 10 ? '0' : ''}${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
};

export const getAttributeBoxSize = (width, height) => {
if (!width || !height) {
return '';
}
return width < 180 || height < 180 ? 'small' : 'medium';
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const MwebLandscapePrompt = () => {
setShowMwebLandscapePrompt(window.screen.orientation.type.includes('landscape') && isMobile);
window.screen.orientation.addEventListener('change', handleOrientationChange);
}
return () => window.screen.orientation.removeEventListener(handleOrientationChange);
return () => window.screen.orientation.removeEventListener('change', handleOrientationChange);
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ export const PreviewTile = ({ name, error }: { name: string; error?: boolean })
<FullPageProgress />
) : null}
{showMuteIcon ? (
<StyledVideoTile.AudioIndicator size="medium">
<StyledVideoTile.AttributeBox size="medium" position="right">
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
<MicOffIcon />
</StyledVideoTile.AudioIndicator>
</StyledVideoTile.AttributeBox>
) : (
<AudioLevel trackId={localPeer?.audioTrack} />
)}
Expand Down
22 changes: 11 additions & 11 deletions packages/roomkit-react/src/Prebuilt/components/VideoTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Video } from '../../Video';
import { StyledVideoTile } from '../../VideoTile';
import { getVideoTileLabel } from './peerTileUtils';
import { useSetAppDataByKey, useUISettings } from './AppData/useUISettings';
import { getAttributeBoxSize } from '../common/utils';
import { APP_DATA, SESSION_STORE_KEY, UI_SETTINGS } from '../common/constants';

const Tile = ({
Expand Down Expand Up @@ -131,12 +132,13 @@ const Tile = ({

{!hideAudioMuteOnTile ? (
isAudioMuted ? (
<StyledVideoTile.AudioIndicator
<StyledVideoTile.AttributeBox
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
data-testid="participant_audio_mute_icon"
size={width && height && (width < 180 || height < 180) ? 'small' : 'medium'}
size={getAttributeBoxSize(width, height)}
position="right"
>
<MicOffIcon />
</StyledVideoTile.AudioIndicator>
</StyledVideoTile.AttributeBox>
) : (
<AudioLevel trackId={audioTrack?.id} />
)
Expand All @@ -150,7 +152,7 @@ const Tile = ({
enableSpotlightingPeer={enableSpotlightingPeer}
/>
) : null}
{!hideMetadataOnTile && <PeerMetadata peerId={peerId} />}
{!hideMetadataOnTile && <PeerMetadata peerId={peerId} height={height} width={width} />}
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved

<TileConnection
hideLabel={hideParticipantNameOnTile}
Expand All @@ -167,8 +169,6 @@ const Tile = ({
);
};

const metaStyles = { top: '$4', left: '$4', width: '$13', height: '$13' };

const heightAnimation = value =>
keyframes({
'50%': {
Expand Down Expand Up @@ -208,30 +208,30 @@ const AudioLevelIndicator = ({ trackId, value, delay }) => {

export const AudioLevel = ({ trackId }) => {
return (
<StyledVideoTile.AudioIndicator>
<StyledVideoTile.AttributeBox position="right">
<Flex align="center" justify="center" css={{ gap: '$2' }}>
{[3, 2, 3].map((v, i) => (
<AudioLevelIndicator trackId={trackId} value={v} delay={i * 0.15} key={i} />
))}
</Flex>
</StyledVideoTile.AudioIndicator>
</StyledVideoTile.AttributeBox>
);
};

const PeerMetadata = ({ peerId }) => {
const PeerMetadata = ({ peerId, height, width }) => {
const metaData = useHMSStore(selectPeerMetadata(peerId));
const isBRB = metaData?.isBRBOn || false;
const isHandRaised = useHMSStore(selectHasPeerHandRaised(peerId));

return (
<Fragment>
{isHandRaised ? (
<StyledVideoTile.AttributeBox css={metaStyles} data-testid="raiseHand_icon_onTile">
<StyledVideoTile.AttributeBox size={getAttributeBoxSize(width, height)} data-testid="raiseHand_icon_onTile">
<HandIcon width={24} height={24} />
</StyledVideoTile.AttributeBox>
) : null}
{isBRB ? (
<StyledVideoTile.AttributeBox css={metaStyles} data-testid="brb_icon_onTile">
<StyledVideoTile.AttributeBox size={getAttributeBoxSize(width, height)} data-testid="brb_icon_onTile">
<BrbTileIcon width={22} height={22} />
</StyledVideoTile.AttributeBox>
) : null}
Expand Down
4 changes: 2 additions & 2 deletions packages/roomkit-react/src/VideoList/VideoList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const VideoTile: React.FC<{ width: number; height: number; trackId: string; name
<StyledVideoTile.Container>
<Video trackId={trackId} />
<StyledVideoTile.Info>{name}</StyledVideoTile.Info>
<StyledVideoTile.AudioIndicator>
<StyledVideoTile.AttributeBox position="right">
<MicOffIcon />
</StyledVideoTile.AudioIndicator>
</StyledVideoTile.AttributeBox>
</StyledVideoTile.Container>
</StyledVideoTile.Root>
);
Expand Down
22 changes: 9 additions & 13 deletions packages/roomkit-react/src/VideoTile/StyledVideoTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,8 @@ const Info = styled('div', {
});

const AttributeBox = styled('div', {
position: 'absolute',
color: '$on_primary_high',
w: '$12',
h: '$12',
bg: '$secondary_dim',
r: '$round',
...flexCenter,
});

const AudioIndicator = styled('div', {
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
position: 'absolute',
top: '$4',
right: '$4',
color: '$on_primary_high',
bg: '$secondary_dim',
borderRadius: '$round',
Expand All @@ -91,12 +80,19 @@ const AudioIndicator = styled('div', {
height: '$13',
},
},
position: {
left: { left: '$4' },
right: { right: '$4' },
},
},
defaultVariants: {
size: 'medium',
position: 'left',
},
});

const AudioIndicator = AttributeBox;
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved

const FullScreenButton = styled('button', {
width: '2.25rem',
height: '2.25rem',
Expand Down Expand Up @@ -136,9 +132,9 @@ interface VideoTileType {
Container: typeof Container;
Overlay: typeof Overlay;
Info: typeof Info;
AudioIndicator: typeof AudioIndicator;
AvatarContainer: typeof AvatarContainer;
AttributeBox: typeof AttributeBox;
AudioIndicator: typeof AudioIndicator;
FullScreenButton: typeof FullScreenButton;
}

Expand All @@ -147,8 +143,8 @@ export const StyledVideoTile: VideoTileType = {
Container,
Overlay,
Info,
AudioIndicator,
AvatarContainer,
AttributeBox,
AudioIndicator,
FullScreenButton,
};
4 changes: 2 additions & 2 deletions packages/roomkit-react/src/VideoTile/VideoTile.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const VideoTileStory = () => {
<Video trackId="1" />
{/* Meta info */}
<StyledVideoTile.Info>Deepankar</StyledVideoTile.Info>
<StyledVideoTile.AudioIndicator>
<StyledVideoTile.AttributeBox position="right">
<MicOffIcon />
</StyledVideoTile.AudioIndicator>
</StyledVideoTile.AttributeBox>
</StyledVideoTile.Container>
</StyledVideoTile.Root>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/roomkit-react/src/VideoTile/VideoTile.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const VideoTileStory = () => {
<StyledVideoTile.Container>
<Video trackId="1" />
<StyledVideoTile.Info>Deepankar</StyledVideoTile.Info>
<StyledVideoTile.AudioIndicator>
<StyledVideoTile.AttributeBox position="right">
<MicOffIcon />
</StyledVideoTile.AudioIndicator>
</StyledVideoTile.AttributeBox>
</StyledVideoTile.Container>
</StyledVideoTile.Root>
);
Expand Down
Loading