diff --git a/app/providers/CallProvider/CallProvider.tsx b/app/providers/CallProvider/CallProvider.tsx index f109cf3..572a122 100644 --- a/app/providers/CallProvider/CallProvider.tsx +++ b/app/providers/CallProvider/CallProvider.tsx @@ -84,6 +84,7 @@ export function CallProvider(props : CallProviderProps) { const mutedRef = useRef(false); const soundRef = useRef(true); const {sendMessage} = useDeattachedSender(); + const hasRemoteTrackRef = useRef(false); const {playSound, stopSound, stopLoopSound} = useSound(); const {setWindowPriority} = useWindow(); @@ -350,10 +351,7 @@ export function CallProvider(props : CallProviderProps) { * WebRTC соединение установлено, звонок активен, останавливаем все остальные звуки * системы */ - stopLoopSound(); - stopSound(); - - setCallState(CallState.ACTIVE); + tryActivateCall(); info("WebRTC connection established, call is active"); } } @@ -368,7 +366,8 @@ export function CallProvider(props : CallProviderProps) { * При получении медиа-трека с другой стороны */ if(remoteAudioRef.current && event.streams[0]){ - console.info(event.streams); + hasRemoteTrackRef.current = true; + tryActivateCall(); remoteAudioRef.current.srcObject = event.streams[0]; remoteAudioRef.current.muted = !soundRef.current; void remoteAudioRef.current.play().catch((e) => { @@ -405,6 +404,15 @@ export function CallProvider(props : CallProviderProps) { } }, [activeCall, sessionKeys, duration]); + const tryActivateCall = () => { + if(hasRemoteTrackRef.current && peerConnectionRef.current?.connectionState == "connected"){ + stopLoopSound(); + stopSound(); + setCallState(CallState.ACTIVE); + info("Call is now active"); + } + } + const openCallsModal = (text : string) => { modals.open({ centered: true,