|
2 | 2 |
|
3 | 3 | import { createContext, useContext, useMemo, useState } from 'react'; |
4 | 4 | import { TokenSource } from 'livekit-client'; |
5 | | -import { SessionProvider, type UseSessionReturn, useSession } from '@livekit/components-react'; |
| 5 | +import { SessionProvider, useSession } from '@livekit/components-react'; |
6 | 6 | import type { AppConfig } from '@/app-config'; |
7 | 7 |
|
8 | 8 | interface ConnectionContextType { |
9 | | - session?: UseSessionReturn; |
10 | 9 | isConnectionActive: boolean; |
11 | 10 | connect: (startSession?: boolean) => void; |
12 | | - disconnect: (endSession?: boolean) => void; |
| 11 | + startDisconnectTransition: () => void; |
| 12 | + onDisconnectTransitionComplete: () => void; |
13 | 13 | } |
14 | 14 |
|
15 | 15 | const ConnectionContext = createContext<ConnectionContextType>({ |
16 | | - session: undefined, |
17 | 16 | isConnectionActive: false, |
18 | 17 | connect: () => {}, |
19 | | - disconnect: () => {}, |
| 18 | + startDisconnectTransition: () => {}, |
| 19 | + onDisconnectTransitionComplete: () => {}, |
20 | 20 | }); |
21 | 21 |
|
22 | 22 | export function useConnection() { |
@@ -76,29 +76,15 @@ export function ConnectionProvider({ appConfig, children }: ConnectionProviderPr |
76 | 76 | const value = useMemo( |
77 | 77 | () => ({ |
78 | 78 | isConnectionActive, |
79 | | - /** |
80 | | - * Start the application session and optionally start the agent session. |
81 | | - * |
82 | | - * @param startSession - Whether to start the agent session automatically. Default is true. |
83 | | - * If startSession is passed in asfalse, you are opting to manually start the session. |
84 | | - */ |
85 | | - connect: (startSession = true) => { |
| 79 | + connect: () => { |
86 | 80 | setIsConnectionActive(true); |
87 | | - if (startSession) { |
88 | | - session.start(); |
89 | | - } |
| 81 | + session.start(); |
90 | 82 | }, |
91 | | - /** |
92 | | - * End the application session and optionally end the agent session. |
93 | | - * |
94 | | - * @param endSession - Whether to end the agent session automatically. Default is true. |
95 | | - * If endSession is passed in as false, you are opting to manually end the session. |
96 | | - */ |
97 | | - disconnect: (endSession = true) => { |
| 83 | + startDisconnectTransition: () => { |
98 | 84 | setIsConnectionActive(false); |
99 | | - if (endSession) { |
100 | | - session.end(); |
101 | | - } |
| 85 | + }, |
| 86 | + onDisconnectTransitionComplete: () => { |
| 87 | + session.end(); |
102 | 88 | }, |
103 | 89 | }), |
104 | 90 | // session object is not a stable reference |
|
0 commit comments