diff --git a/src/SimliClient.ts b/src/SimliClient.ts index 79cf16f..7e921b8 100644 --- a/src/SimliClient.ts +++ b/src/SimliClient.ts @@ -119,6 +119,11 @@ export class SimliClient extends EventEmitter { this.dc.addEventListener('message', (evt) => { console.log('Received message: ', evt.data) + + if (evt.data.includes('START')) { + this.emit('started') + } + if (evt.data === 'Session Intialization not done, Ignoring audio') { this.emit('failed') } diff --git a/src/main.tsx b/src/main.tsx index a9e473f..211ef76 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -20,6 +20,7 @@ const simliClient = new SimliClient() const App = () => { const [inputText, setInputText] = useState('') const [isLoading, setIsLoading] = useState(false) + const [isConnecting, setIsConnecting] = useState(false) const [error, setError] = useState('') const [_, setChatgptText] = useState('') const [startWebRTC, setStartWebRTC] = useState(false) @@ -52,7 +53,6 @@ const App = () => { initializeSimliClient() const handleConnected = () => { - setIsLoading(false) console.log('SimliClient is now connected!') } @@ -65,14 +65,22 @@ const App = () => { setError('Failed to connect to Simli. Please try again.') } + const handleStarted = () => { + console.log('SimliClient has started!') + setIsLoading(false) + setIsConnecting(false) + } + simliClient.on('connected', handleConnected) simliClient.on('disconnected', handleDisconnected) simliClient.on('failed', handleFailed) + simliClient.on('started', handleStarted) return () => { simliClient.off('connected', handleConnected) simliClient.off('disconnected', handleDisconnected) simliClient.off('failed', handleFailed) + simliClient.off('started', handleStarted) simliClient.close() } }, [initializeSimliClient]) @@ -81,6 +89,7 @@ const App = () => { simliClient.start() setStartWebRTC(true) setIsLoading(true) + setIsConnecting(true) setTimeout(() => { const audioData = new Uint8Array(6000).fill(0) @@ -275,7 +284,7 @@ const App = () => { > - {startWebRTC ? ( + {startWebRTC && !isConnecting ? ( <> {/* {chatgptText &&

{chatgptText}

} */}
{
) : ( - + <> + {isConnecting && ( +

+ Connecting... +

+ )} + {!isConnecting && ( + + )} + )} {error &&

{error}

}