import React, { type ComponentType, useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import { useCallStateHooks, useConnectedUser, useI18n, } from '@stream-io/video-react-bindings'; import { Avatar } from '../../utility/Avatar'; import type { StreamVideoParticipant } from '@stream-io/video-client'; import { LobbyControls as DefaultLobbyControls } from '../CallControls/LobbyControls'; import { LobbyCameraPreview } from './LobbyCameraPreview'; import { JoinCallButton as DefaultJoinCallButton, type JoinCallButtonProps, } from './JoinCallButton'; import { useTheme } from '../../../contexts/ThemeContext'; import { LobbyFooter as DefaultLobbyFooter, type LobbyFooterProps, } from './LobbyFooter'; /** * Props for the Lobby Component. */ export type LobbyProps = { /** * Handler to be called to join a call. */ onJoinCallHandler?: () => void; /** * Component to customize the LobbyControls component. */ LobbyControls?: ComponentType<{}> | null; /** * Component to customize the Join Call Button in the Lobby component. */ JoinCallButton?: ComponentType | null; /** * Check if device is in landscape mode. * This will apply the landscape mode styles to the component. */ landscape?: boolean; /** * Component to customize the Lobby Footer in the Lobby component. */ LobbyFooter?: ComponentType | null; }; /** * Components that acts as a pre-join view for the call. Where you can preview your video and audio. Check for call details and check for number of participants already in the call. */ export const Lobby = ({ onJoinCallHandler, LobbyControls = DefaultLobbyControls, JoinCallButton = DefaultJoinCallButton, landscape = false, LobbyFooter = DefaultLobbyFooter, }: LobbyProps) => { const { theme: { colors, lobby, typefaces }, } = useTheme(); const styles = useStyles(landscape); const connectedUser = useConnectedUser(); const { useCameraState, useCallSettings } = useCallStateHooks(); const callSettings = useCallSettings(); const isVideoEnabledInCall = callSettings?.video.enabled; const { optimisticIsMute: cameraIsMuted } = useCameraState(); const { t } = useI18n(); const connectedUserAsParticipant = useMemo( () => ({ userId: connectedUser?.id, image: connectedUser?.image, name: connectedUser?.name, }) as StreamVideoParticipant, [connectedUser?.id, connectedUser?.image, connectedUser?.name], ); return ( {connectedUser && ( <> {t('Before joining')} {t('Setup your audio and video')} {isVideoEnabledInCall && ( {!cameraIsMuted ? ( ) : ( )} )} )} {LobbyControls && } {LobbyFooter && ( )} ); }; const ParticipantStatus = () => { const { theme: { colors, typefaces, lobby }, } = useTheme(); const styles = useStyles(); const connectedUser = useConnectedUser(); const participantLabel = connectedUser?.name ?? connectedUser?.id; return ( {participantLabel} ); }; const useStyles = (landscape = false) => { const { theme } = useTheme(); return useMemo( () => StyleSheet.create({ heading: { textAlign: 'center', color: theme.colors.textPrimary, paddingBottom: theme.variants.spacingSizes.xs, }, subHeading: { textAlign: 'center', paddingBottom: theme.variants.spacingSizes.md, color: theme.colors.textSecondary, }, container: { flex: 1, justifyContent: 'center', backgroundColor: theme.colors.sheetPrimary, paddingRight: theme.variants.insets.right + theme.variants.spacingSizes.sm, paddingLeft: theme.variants.insets.left + theme.variants.spacingSizes.sm, paddingTop: theme.variants.insets.top, paddingBottom: theme.variants.insets.bottom, }, videoContainer: { height: landscape ? '40%' : '50%', borderRadius: theme.variants.borderRadiusSizes.md, justifyContent: 'space-between', alignItems: 'center', overflow: 'hidden', }, topView: {}, participantStatusContainer: { alignSelf: 'flex-start', flexDirection: 'row', alignItems: 'center', padding: theme.variants.spacingSizes.sm, borderTopRightRadius: theme.variants.borderRadiusSizes.sm, }, avatarContainer: { flex: 2, justifyContent: 'center', }, userNameLabel: { flexShrink: 1, }, }), [theme, landscape], ); };