@@ -3,7 +3,7 @@ import { Room, RoomEvent, ConnectionState, TrackPublishOptions, Track, LocalPart
33import { EventEmitter } from 'events' ;
44import { useCallback , useEffect , useMemo , useState } from 'react' ;
55
6- import { ConnectionCredentials } from '../utils/ConnectionCredentialsProvider' ;
6+ import { ConnectionCredentials as TokenSource } from '../utils/ConnectionCredentialsProvider' ;
77import { useMaybeRoomContext } from '../context' ;
88import { RoomAgentDispatch , RoomConfiguration } from '@livekit/protocol' ;
99import { useAgent } from './useAgent' ;
@@ -25,7 +25,7 @@ export type ConversationCallbacks = {
2525} ;
2626
2727export type ConversationOptions = {
28- credentials : ConnectionCredentials ;
28+ tokenSource : TokenSource ;
2929 room ?: Room ;
3030
3131 dispatch ?: {
@@ -67,7 +67,7 @@ type ConversationStateCommon = {
6767 subtle : {
6868 emitter : TypedEventEmitter < ConversationCallbacks > ;
6969 room : Room ;
70- credentials : ConnectionCredentials ,
70+ credentials : TokenSource ,
7171 agentConnectTimeoutMilliseconds : NonNullable < ConversationOptions [ "dispatch" ] > [ "agentConnectTimeoutMilliseconds" ] ,
7272 } ;
7373} ;
@@ -142,12 +142,12 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
142142 agents : [ roomAgentDispatch ] ,
143143 } )
144144 ) : undefined ;
145- options . credentials . setRequest ( { roomConfig } ) ;
145+ options . tokenSource . setRequest ( { roomConfig } ) ;
146146
147147 return ( ) => {
148- options . credentials . clearRequest ( ) ;
148+ options . tokenSource . clearRequest ( ) ;
149149 } ;
150- } , [ options . credentials ] ) ;
150+ } , [ options . tokenSource ] ) ;
151151
152152 const generateDerivedConnectionStateValues = < ConnectionState extends ConversationInstance [ "connectionState" ] > ( connectionState : ConnectionState ) => ( {
153153 isConnected : (
@@ -204,7 +204,7 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
204204 subtle : {
205205 room,
206206 emitter,
207- credentials : options . credentials ,
207+ credentials : options . tokenSource ,
208208 agentConnectTimeoutMilliseconds : options . dispatch ?. agentConnectTimeoutMilliseconds ,
209209 } ,
210210 } ;
@@ -251,7 +251,7 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
251251 } ,
252252 } ;
253253 }
254- } , [ options . credentials , room , emitter , roomConnectionState , localParticipant , localCamera , localMicrophone ] ) ;
254+ } , [ options . tokenSource , room , emitter , roomConnectionState , localParticipant , localCamera , localMicrophone ] ) ;
255255 useEffect ( ( ) => {
256256 emitter . emit ( ConversationEvent . ConnectionStateChanged , conversationState . connectionState ) ;
257257 } , [ emitter , conversationState . connectionState ] ) ;
@@ -303,10 +303,10 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
303303 subtle : {
304304 emitter,
305305 room,
306- credentials : options . credentials ,
306+ credentials : options . tokenSource ,
307307 agentConnectTimeoutMilliseconds : options . dispatch ?. agentConnectTimeoutMilliseconds ,
308308 } ,
309- } ) , [ conversationState , emitter , room , options . credentials , options . dispatch ?. agentConnectTimeoutMilliseconds ] ) , agentName ) ;
309+ } ) , [ conversationState , emitter , room , options . tokenSource , options . dispatch ?. agentConnectTimeoutMilliseconds ] ) , agentName ) ;
310310
311311 const start = useCallback ( async ( connectOptions : AgentSessionConnectOptions = { } ) => {
312312 const {
@@ -324,7 +324,7 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
324324 await Promise . all ( [
325325 // FIXME: swap the below line in once the new `livekit-client` changes are published
326326 // room.connect(options.credentials),
327- options . credentials . generate ( ) . then ( ( { serverUrl, participantToken } ) => (
327+ options . tokenSource . generate ( ) . then ( ( { serverUrl, participantToken } ) => (
328328 room . connect ( serverUrl , participantToken )
329329 ) ) ,
330330
@@ -338,16 +338,16 @@ export function useConversationWith(agentToDispatch: string | RoomAgentDispatch
338338 await agent . waitUntilAvailable ( signal ) ;
339339
340340 signal ?. removeEventListener ( 'abort' , onSignalAbort ) ;
341- } , [ room , waitUntilDisconnected , options . credentials , waitUntilConnected , agent . waitUntilAvailable ] ) ;
341+ } , [ room , waitUntilDisconnected , options . tokenSource , waitUntilConnected , agent . waitUntilAvailable ] ) ;
342342
343343 const end = useCallback ( async ( ) => {
344344 await room . disconnect ( ) ;
345345 } , [ room ] ) ;
346346
347347 const prepareConnection = useCallback ( async ( ) => {
348- const credentials = await options . credentials . generate ( ) ;
348+ const credentials = await options . tokenSource . generate ( ) ;
349349 await room . prepareConnection ( credentials . serverUrl , credentials . participantToken ) ;
350- } , [ options . credentials , room ] ) ;
350+ } , [ options . tokenSource , room ] ) ;
351351 useEffect ( ( ) => {
352352 prepareConnection ( ) . catch ( err => {
353353 // FIXME: figure out a better logging solution?
0 commit comments