Skip to content

Commit 7d0f187

Browse files
remove useConnectionTimeout
1 parent 70d9de0 commit 7d0f187

File tree

7 files changed

+54
-55
lines changed

7 files changed

+54
-55
lines changed

components/app/session-view.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ import {
1212
type ControlBarControls,
1313
} from '@/components/livekit/agent-control-bar/agent-control-bar';
1414
import { useAppSession } from '@/hooks/useAppSession';
15-
import { useConnectionTimeout } from '@/hooks/useConnectionTimout';
16-
import { useDebugMode } from '@/hooks/useDebug';
1715
import { cn } from '@/lib/utils';
1816
import { ScrollArea } from '../livekit/scroll-area/scroll-area';
1917

2018
const MotionBottom = motion.create('div');
2119

22-
const IN_DEVELOPMENT = process.env.NODE_ENV !== 'production';
2320
const BOTTOM_VIEW_MOTION_PROPS = {
2421
variants: {
2522
visible: {
@@ -68,9 +65,6 @@ export const SessionView = ({
6865
appConfig,
6966
...props
7067
}: React.ComponentProps<'section'> & SessionViewProps) => {
71-
useConnectionTimeout(20_000);
72-
useDebugMode({ enabled: IN_DEVELOPMENT });
73-
7468
const { session, isSessionActive, endSession } = useAppSession();
7569
const { messages } = useSessionMessages(session);
7670
const [chatOpen, setChatOpen] = useState(false);

components/app/view-controller.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { useSessionContext } from '@livekit/components-react';
66
import { AppConfig } from '@/app-config';
77
import { SessionView } from '@/components/app/session-view';
88
import { WelcomeView } from '@/components/app/welcome-view';
9+
import { useAgentErrors } from '@/hooks/useAgentErrors';
910
import { useAppSession } from '@/hooks/useAppSession';
11+
import { useDebugMode } from '@/hooks/useDebug';
12+
13+
const IN_DEVELOPMENT = process.env.NODE_ENV !== 'production';
1014

1115
const MotionWelcomeView = motion.create(WelcomeView);
1216
const MotionSessionView = motion.create(SessionView);
@@ -37,6 +41,9 @@ export function ViewController({ appConfig }: ViewControllerProps) {
3741
const session = useSessionContext();
3842
const { isSessionActive, startSession } = useAppSession();
3943

44+
useDebugMode({ enabled: IN_DEVELOPMENT });
45+
useAgentErrors();
46+
4047
const handleAnimationComplete = useCallback(
4148
(definition: AnimationDefinition) => {
4249
// manually end the session when the exit animation completes

components/livekit/alert-toast.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function AlertToast(props: ToastProps) {
2222
const { title, description, id } = props;
2323

2424
return (
25-
<Alert onClick={() => sonnerToast.dismiss(id)} className="bg-accent">
25+
<Alert onClick={() => sonnerToast.dismiss(id)} className="bg-accent w-full md:w-[364px]">
2626
<WarningIcon weight="bold" />
2727
<AlertTitle>{title}</AlertTitle>
2828
{description && <AlertDescription>{description}</AlertDescription>}

hooks/useAgentErrors.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { useEffect } from 'react';
2+
import { useAgent } from '@livekit/components-react';
3+
import { toastAlert } from '@/components/livekit/alert-toast';
4+
import { useAppSession } from './useAppSession';
5+
6+
export function useAgentErrors() {
7+
const agent = useAgent();
8+
const { isSessionActive, endSession } = useAppSession();
9+
10+
useEffect(() => {
11+
if (isSessionActive && agent.state === 'failed') {
12+
const reasons = agent.failureReasons;
13+
14+
toastAlert({
15+
title: 'Session ended',
16+
description: (
17+
<>
18+
{reasons.length > 1 && (
19+
<ul className="list-inside list-disc">
20+
{reasons.map((reason) => (
21+
<li key={reason}>{reason}</li>
22+
))}
23+
</ul>
24+
)}
25+
{reasons.length === 1 && <p className="w-full">{reasons[0]}</p>}
26+
<p className="w-full">
27+
<a
28+
target="_blank"
29+
rel="noopener noreferrer"
30+
href="https://docs.livekit.io/agents/start/voice-ai/"
31+
className="whitespace-nowrap underline"
32+
>
33+
See quickstart guide
34+
</a>
35+
.
36+
</p>
37+
</>
38+
),
39+
});
40+
41+
endSession();
42+
}
43+
}, [agent, isSessionActive, endSession]);
44+
}

hooks/useConnectionTimout.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"next-themes": "^0.4.6",
3030
"react": "^19.0.0",
3131
"react-dom": "^19.0.0",
32-
"sonner": "^2.0.3",
32+
"sonner": "^2.0.7",
3333
"tailwind-merge": "^3.3.0"
3434
},
3535
"devDependencies": {

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)