import { useCall, useCallStateHooks, useI18n, } from '@stream-io/video-react-bindings'; import React, { useEffect, useMemo, useState } from 'react'; import { ActivityIndicator, Button, StyleSheet, Text, View, } from 'react-native'; import { useTheme } from '../../../contexts'; import { CallingState, videoLoggerSystem } from '@stream-io/video-client'; type LobbyProps = { isLive: boolean; handleJoinCall?: () => void; }; export const ViewerLobby = ({ isLive }: LobbyProps) => { const styles = useStyles(); const { theme } = useTheme(); const { t } = useI18n(); const { useCallStartsAt, useParticipants, useCallCallingState } = useCallStateHooks(); const callingState = useCallCallingState(); const call = useCall(); const startsAt = useCallStartsAt(); const [error, setError] = useState(undefined); const [countdown, setCountdown] = React.useState(getCountdown(startsAt)); const participants = useParticipants(); useEffect(() => { if (!startsAt || isLive) return; const updateCountdown = () => { const timeRemaining = Math.max(0, startsAt.getTime() - Date.now()); if (timeRemaining <= 0) { setCountdown('0:00'); clearInterval(intervalId); return; } setCountdown(getCountdown(startsAt)); }; updateCountdown(); const intervalId = setInterval(updateCountdown, 1000); return () => clearInterval(intervalId); }, [startsAt, isLive]); /** * Getting the call details is done through `call.get()`. * It is essential so that the call is watched and any changes in the call is intercepted. */ useEffect(() => { const getCall = async () => { if (!call) { return; } try { await call.get(); } catch (err) { if (err instanceof Error) { const logger = videoLoggerSystem.getLogger('ViewerLobby'); logger.error('Error getting call:', err); setError(err); } } }; getCall(); }, [call]); if (error) { return ( Error joining the livestream. Please try again later. ); } const isJoiningLiveCall = callingState === CallingState.JOINING; if (isJoiningLiveCall) { return ( ); } return ( {isLive ? t('Livestream is still in progress') : startsAt ? t('Livestream will start in:') : t('Livestream will start soon')} {startsAt && !isLive && ( {countdown} )} {!isLive && participants.length > 0 && ( <> {`${participants.length} ${t('participants have joined early')}`} )} {isLive && (