diff --git a/src/views/ErrorScreen.tsx b/src/views/ErrorScreen.tsx index 6dc02e3..5acec77 100644 --- a/src/views/ErrorScreen.tsx +++ b/src/views/ErrorScreen.tsx @@ -7,6 +7,8 @@ type ErrorScreenProps = { errorType: 'socket_error' | 'audio_error' | 'mic_error' | 'unknown'; errorReason: string; onConnect: () => void; + onClose: () => void; + ableToReconnect: boolean; isConnecting: boolean; }; @@ -14,7 +16,9 @@ export const ErrorScreen: FC = ({ errorType, errorReason, onConnect, + onClose, isConnecting, + ableToReconnect, }) => { return (
@@ -71,13 +75,17 @@ export const ErrorScreen: FC = ({ })}
- + {ableToReconnect ? ( + + ) : ( + + )}
); diff --git a/src/views/Views.tsx b/src/views/Views.tsx index 17e8ab4..172b2b8 100644 --- a/src/views/Views.tsx +++ b/src/views/Views.tsx @@ -5,7 +5,7 @@ import { ConversationScreen } from '@/views/ConversationScreen'; import { ErrorScreen } from '@/views/ErrorScreen'; import { IntroScreen } from '@/views/IntroScreen'; import { useVoice } from '@humeai/voice-react'; -import { FC } from 'react'; +import { FC, useState } from 'react'; import { match } from 'ts-pattern'; export type ViewsProps = Record; @@ -17,6 +17,8 @@ export const Views: FC = () => { const { connect, disconnect, status, error } = useVoice(); + const [reconnectError, setReconnectError] = useState(null); + if (layoutState === LayoutState.CLOSED) { return ( <> @@ -31,10 +33,14 @@ export const Views: FC = () => { } const onConnect = () => { - void connect() - .then(() => {}) + setReconnectError(null); + return connect() + .then(() => { + return { success: true } as const; + }) .catch((e) => { console.error(e); + return {success: false} as const; }); }; @@ -51,8 +57,19 @@ export const Views: FC = () => { { + onConnect() + .then(res => { + if(res.success === false){ + setReconnectError('Failed to reconnect') + } + }) + }} + onClose={() => { + close(); + }} isConnecting={status.value === 'connecting'} + ableToReconnect={reconnectError !== null} /> ); })