@@ -8,12 +8,11 @@ import {
88 TokenSourceConfigurable ,
99 TokenSourceFixed ,
1010 TokenSourceFetchOptions ,
11- RoomOptions ,
11+ RoomConnectOptions ,
1212} from 'livekit-client' ;
1313import { EventEmitter } from 'events' ;
1414import { useCallback , useEffect , useMemo , useState } from 'react' ;
1515
16- import { TokenSourceConfigurable , TokenSourceFixed , TokenSourceOptions } from '../TokenSource' ;
1716import { useMaybeRoomContext } from '../context' ;
1817import { useAgent } from './useAgent' ;
1918import { TrackReference } from '@livekit/components-core' ;
@@ -45,6 +44,9 @@ export type SessionConnectOptions = {
4544 publishOptions ?: TrackPublishOptions ;
4645 } ;
4746 } ;
47+
48+ /** Options for Room.connect(.., .., opts) */
49+ roomConnectOptions ?: RoomConnectOptions ;
4850} ;
4951
5052/** @public */
@@ -134,7 +136,7 @@ type UseSessionCommonOptions = {
134136 agentConnectTimeoutMilliseconds ?: number ;
135137} ;
136138
137- type UseSessionConfigurableOptions = UseSessionCommonOptions & TokenSourceOptions ;
139+ type UseSessionConfigurableOptions = UseSessionCommonOptions & { tokenFetchOptions : TokenSourceFetchOptions } ;
138140type UseSessionFixedOptions = UseSessionCommonOptions ;
139141
140142/**
@@ -153,7 +155,11 @@ export function useSession(
153155 tokenSource : TokenSourceConfigurable | TokenSourceFixed ,
154156 options : UseSessionConfigurableOptions | UseSessionFixedOptions = { } ,
155157) : UseSessionReturn {
156- const { room : optionsRoom , agentConnectTimeoutMilliseconds, ...tokenSourceOptions } = options ;
158+ const {
159+ room : optionsRoom ,
160+ agentConnectTimeoutMilliseconds,
161+ ...restOptions
162+ } = options ;
157163
158164 const roomFromContext = useMaybeRoomContext ( ) ;
159165 const room = useMemo (
@@ -368,20 +374,22 @@ export function useSession(
368374 ) ,
369375 ) ;
370376
371- const tokenSourceFetch = useCallback ( ( ) => {
377+ const tokenSourceFetch = useCallback ( async ( ) => {
372378 const isConfigurable = tokenSource instanceof TokenSourceConfigurable ;
373379 if ( isConfigurable ) {
374- return tokenSource . fetch ( tokenSourceOptions ) ;
380+ const { tokenFetchOptions } = restOptions as UseSessionConfigurableOptions ;
381+ return tokenSource . fetch ( tokenFetchOptions ) ;
375382 } else {
376383 return tokenSource . fetch ( ) ;
377384 }
378- } , [ tokenSource ] ) ;
385+ } , [ tokenSource , restOptions ] ) ;
379386
380387 const start = useCallback (
381388 async ( connectOptions : SessionConnectOptions = { } ) => {
382389 const {
383390 signal,
384391 tracks = { microphone : { enabled : true , publishOptions : { preConnectBuffer : true } } } ,
392+ roomConnectOptions,
385393 } = connectOptions ;
386394
387395 await waitUntilDisconnected ( signal ) ;
@@ -395,7 +403,7 @@ export function useSession(
395403 // FIXME: swap the below line in once the new `livekit-client` changes are published
396404 // room.connect(tokenSource, { tokenSourceOptions }),
397405 tokenSourceFetch ( ) . then ( ( { serverUrl, participantToken } ) =>
398- room . connect ( serverUrl , participantToken ) ,
406+ room . connect ( serverUrl , participantToken , roomConnectOptions ) ,
399407 ) ,
400408
401409 // Start microphone (with preconnect buffer) by default
0 commit comments