@@ -38,24 +38,9 @@ export default function UserPhoneInterface({
3838 const [ isEnding , setIsEnding ] = useState ( false ) ;
3939 const [ connectionError , setConnectionError ] = useState < string | null > ( null ) ;
4040
41- // ─── ON-SCREEN DEBUG LOG ───────────────────────────────────────────────────
42- const [ debugLogs , setDebugLogs ] = useState < string [ ] > ( [ ] ) ;
43- const [ showDebug , setShowDebug ] = useState ( false ) ;
44- const addLog = useCallback ( ( msg : string ) => {
45- const ts = new Date ( ) . toTimeString ( ) . slice ( 0 , 8 ) ;
46- const line = `[${ ts } ] ${ msg } ` ;
47- console . log ( '📞 [DIAG]' , line ) ;
48- setDebugLogs ( prev => [ ...prev . slice ( - 49 ) , line ] ) ; // keep last 50
49- } , [ ] ) ;
50- // ──────────────────────────────────────────────────────────────────────────
51-
5241 const timerRef = useRef < NodeJS . Timeout | null > ( null ) ;
5342
54- // Tracks when the WebSocket connected so we can log the live-to-dead delta.
55- const connectTimeRef = useRef < number | null > ( null ) ;
56-
5743 // Inline type that matches @elevenlabs /types DisconnectionDetails union.
58- // Defined here so diagnostics compile even before node_modules is installed.
5944 type DisconnectionDetails =
6045 | { reason : 'error' ; message : string ; context ?: Event ; closeCode ?: number ; closeReason ?: string }
6146 | { reason : 'agent' ; context ?: CloseEvent ; closeCode ?: number ; closeReason ?: string }
@@ -64,36 +49,18 @@ export default function UserPhoneInterface({
6449 // Memoized callbacks — stable references prevent useConversation from
6550 // re-initialising on every render, which can reset the active WebSocket.
6651 const onConnect = useCallback ( ( ) => {
67- connectTimeRef . current = Date . now ( ) ;
68- addLog ( '✅ CONNECTED' ) ;
6952 setConnectionError ( null ) ;
7053 setAgentStatus ( 'listening' ) ;
71- } , [ addLog ] ) ;
54+ } , [ ] ) ;
7255
7356 const onDisconnect = useCallback ( ( details ?: DisconnectionDetails ) => {
74- const uptime = connectTimeRef . current !== null
75- ? Date . now ( ) - connectTimeRef . current
76- : null ;
77- connectTimeRef . current = null ;
78-
79- const reason = details ?. reason ?? '(none)' ;
80- const closeCode = ( details as { closeCode ?: number } ) ?. closeCode ?? '' ;
81- const closeReason = ( details as { closeReason ?: string } ) ?. closeReason ?? '' ;
82- const errMsg = ( details as { message ?: string } ) ?. message ?? '' ;
83-
84- addLog ( `❌ DISCONNECTED reason=${ reason } uptimeMs=${ uptime ?? '?' } closeCode=${ closeCode } closeReason="${ closeReason } " errMsg="${ errMsg } "` ) ;
85-
8657 setAgentStatus ( 'idle' ) ;
87-
88- // If the agent or an error closed the socket (not the user pressing End Call),
89- // clean up the call session so the UI returns to the idle/start state.
9058 if ( details ?. reason !== 'user' ) {
9159 endCall ( ) ;
9260 }
93- } , [ endCall , addLog ] ) ;
61+ } , [ endCall ] ) ;
9462
9563 const onMessage = useCallback ( ( message : { source : string ; message : string } ) => {
96- addLog ( `💬 ${ message . source . toUpperCase ( ) } : "${ message . message } "` ) ;
9764 if ( message . source === 'user' ) {
9865 setCurrentTranscript ( message . message ) ;
9966 addMessage ( 'user' , message . message ) ;
@@ -104,24 +71,20 @@ export default function UserPhoneInterface({
10471 addMessage ( 'agent' , message . message ) ;
10572 onTranscript ?.( message . message , 'agent' ) ;
10673 }
107- } , [ addMessage , onTranscript , addLog ] ) ;
74+ } , [ addMessage , onTranscript ] ) ;
10875
109- const onError = useCallback ( ( message : string , context ?: unknown ) => {
110- let ctxStr = '' ;
111- try { ctxStr = JSON . stringify ( context ) ; } catch { ctxStr = String ( context ) ; }
112- addLog ( `🔴 ERROR: "${ message } " ctx=${ ctxStr } ` ) ;
76+ const onError = useCallback ( ( message : string ) => {
11377 setConnectionError ( message ?? 'Connection error' ) ;
114- } , [ addLog ] ) ;
78+ } , [ ] ) ;
11579
11680 const onModeChange = useCallback ( ( modeEvent : { mode : string } ) => {
117- addLog ( `🔄 MODE → ${ modeEvent . mode } ` ) ;
11881 if ( modeEvent . mode === 'speaking' ) {
11982 setAgentStatus ( 'speaking' ) ;
12083 setCurrentTranscript ( '' ) ;
12184 } else if ( modeEvent . mode === 'listening' ) {
12285 setAgentStatus ( 'listening' ) ;
12386 }
124- } , [ addLog ] ) ;
87+ } , [ ] ) ;
12588
12689 // ElevenLabs Conversational AI — handles STT + LLM + TTS in one WebSocket
12790 const conversation = useConversation ( {
@@ -193,22 +156,17 @@ export default function UserPhoneInterface({
193156 }
194157
195158 startCall ( 'voice' ) ;
196- addLog ( '🟡 Fetching signed URL…' ) ;
197159
198160 try {
199161 const signedUrl = await getSignedUrl ( ) ;
200- addLog ( `🟡 Got signed URL, starting session…` ) ;
201162 await conversation . startSession ( { signedUrl } ) ;
202163 } catch ( error ) {
203- const msg = error instanceof Error ? error . message : String ( error ) ;
204- addLog ( `🔴 startSession failed: ${ msg } ` ) ;
205- setConnectionError ( msg || 'Failed to connect' ) ;
164+ setConnectionError ( error instanceof Error ? error . message : 'Failed to connect' ) ;
206165 setAgentStatus ( 'idle' ) ;
207166 }
208- } , [ startCall , getSignedUrl , conversation , addLog ] ) ;
167+ } , [ startCall , getSignedUrl , conversation ] ) ;
209168
210169 const handleEndCall = useCallback ( async ( ) => {
211- console . log ( '🔴 End call button pressed' ) ;
212170 setIsEnding ( true ) ;
213171
214172 // Only close the socket if it's still open — the agent may have already
@@ -402,26 +360,6 @@ export default function UserPhoneInterface({
402360 </ div >
403361 </ div >
404362
405- { /* ── On-screen debug log ── */ }
406- < div className = "absolute top-4 right-4 z-30 text-left" >
407- < button
408- onClick = { ( ) => setShowDebug ( v => ! v ) }
409- className = "text-[10px] font-mono px-2 py-1 rounded bg-white/10 text-white/50 hover:bg-white/20"
410- >
411- { showDebug ? 'hide log' : 'show log' }
412- </ button >
413- { showDebug && (
414- < div className = "mt-1 w-80 max-h-52 overflow-y-auto rounded-xl bg-black/80 border border-white/10 p-2" >
415- { debugLogs . length === 0
416- ? < p className = "text-white/30 text-[10px] font-mono" > No events yet.</ p >
417- : debugLogs . map ( ( l , i ) => (
418- < p key = { i } className = "text-[10px] font-mono text-white/70 leading-relaxed break-all" > { l } </ p >
419- ) )
420- }
421- </ div >
422- ) }
423- </ div >
424-
425363 { /* Bottom Controls */ }
426364 < div className = "p-8 pb-[max(2rem,env(safe-area-inset-bottom))] w-full z-20 bg-gradient-to-t from-black via-black/80 to-transparent" >
427365 < div className = "flex items-center justify-center gap-6 max-w-lg mx-auto" >
@@ -482,26 +420,6 @@ export default function UserPhoneInterface({
482420 </ div >
483421 ) }
484422
485- { /* ── On-screen debug log ── */ }
486- < div className = "absolute top-4 right-4 z-30 text-left" >
487- < button
488- onClick = { ( ) => setShowDebug ( v => ! v ) }
489- className = "text-[10px] font-mono px-2 py-1 rounded bg-white/10 text-white/50 hover:bg-white/20"
490- >
491- { showDebug ? 'hide log' : 'show log' }
492- </ button >
493- { showDebug && (
494- < div className = "mt-1 w-80 max-h-52 overflow-y-auto rounded-xl bg-black/80 border border-white/10 p-2" >
495- { debugLogs . length === 0
496- ? < p className = "text-white/30 text-[10px] font-mono" > No events yet.</ p >
497- : debugLogs . map ( ( l , i ) => (
498- < p key = { i } className = "text-[10px] font-mono text-white/70 leading-relaxed break-all" > { l } </ p >
499- ) )
500- }
501- </ div >
502- ) }
503- </ div >
504-
505423 { /* Main Content Area */ }
506424 < div className = "flex-1 flex flex-col items-center justify-center relative px-6 z-10 w-full max-w-[92vw] sm:max-w-lg mx-auto" >
507425 { /* Avatar */ }
0 commit comments