1+ import * as React from 'react' ;
12import type TypedEventEmitter from 'typed-emitter' ;
23import {
34 Room ,
@@ -11,7 +12,6 @@ import {
1112 RoomConnectOptions ,
1213} from 'livekit-client' ;
1314import { EventEmitter } from 'events' ;
14- import { useCallback , useEffect , useMemo , useState } from 'react' ;
1515
1616import { useMaybeRoomContext } from '../context' ;
1717import { useAgent } from './useAgent' ;
@@ -170,14 +170,17 @@ export function useSession(
170170 const { room : optionsRoom , agentConnectTimeoutMilliseconds, ...restOptions } = options ;
171171
172172 const roomFromContext = useMaybeRoomContext ( ) ;
173- const room = useMemo (
173+ const room = React . useMemo (
174174 ( ) => roomFromContext ?? optionsRoom ?? new Room ( ) ,
175175 [ roomFromContext , optionsRoom ] ,
176176 ) ;
177177
178- const emitter = useMemo ( ( ) => new EventEmitter ( ) as TypedEventEmitter < SessionCallbacks > , [ ] ) ;
178+ const emitter = React . useMemo (
179+ ( ) => new EventEmitter ( ) as TypedEventEmitter < SessionCallbacks > ,
180+ [ ] ,
181+ ) ;
179182
180- const generateDerivedConnectionStateValues = useCallback (
183+ const generateDerivedConnectionStateValues = React . useCallback (
181184 < State extends UseSessionReturn [ 'connectionState' ] > ( connectionState : State ) =>
182185 ( {
183186 isConnected :
@@ -203,8 +206,8 @@ export function useSession(
203206 [ ] ,
204207 ) ;
205208
206- const [ roomConnectionState , setRoomConnectionState ] = useState ( room . state ) ;
207- useEffect ( ( ) => {
209+ const [ roomConnectionState , setRoomConnectionState ] = React . useState ( room . state ) ;
210+ React . useEffect ( ( ) => {
208211 const handleConnectionStateChanged = ( connectionState : ConnectionState ) => {
209212 setRoomConnectionState ( connectionState ) ;
210213 } ;
@@ -215,7 +218,7 @@ export function useSession(
215218 } ;
216219 } , [ room ] ) ;
217220
218- useEffect ( ( ) => {
221+ React . useEffect ( ( ) => {
219222 const handleMediaDevicesError = async ( error : Error ) => {
220223 emitter . emit ( SessionEvent . MediaDevicesError , error ) ;
221224 } ;
@@ -226,7 +229,7 @@ export function useSession(
226229 } ;
227230 } , [ room , emitter ] ) ;
228231
229- useEffect ( ( ) => {
232+ React . useEffect ( ( ) => {
230233 const handleEncryptionError = async ( error : Error ) => {
231234 emitter . emit ( SessionEvent . EncryptionError , error ) ;
232235 } ;
@@ -239,7 +242,7 @@ export function useSession(
239242
240243 const { localParticipant } = useLocalParticipant ( { room } ) ;
241244 const cameraPublication = localParticipant . getTrackPublication ( Track . Source . Camera ) ;
242- const localCamera = useMemo ( ( ) => {
245+ const localCamera = React . useMemo ( ( ) => {
243246 if ( ! cameraPublication || cameraPublication . isMuted ) {
244247 return null ;
245248 }
@@ -250,7 +253,7 @@ export function useSession(
250253 } ;
251254 } , [ localParticipant , cameraPublication , cameraPublication ?. isMuted ] ) ;
252255 const microphonePublication = localParticipant . getTrackPublication ( Track . Source . Microphone ) ;
253- const localMicrophone = useMemo ( ( ) => {
256+ const localMicrophone = React . useMemo ( ( ) => {
254257 if ( ! microphonePublication || microphonePublication . isMuted ) {
255258 return null ;
256259 }
@@ -261,7 +264,7 @@ export function useSession(
261264 } ;
262265 } , [ localParticipant , microphonePublication , microphonePublication ?. isMuted ] ) ;
263266
264- const conversationState = useMemo ( ( ) :
267+ const conversationState = React . useMemo ( ( ) :
265268 | SessionStateConnecting
266269 | SessionStateConnected
267270 | SessionStateDisconnected => {
@@ -327,11 +330,11 @@ export function useSession(
327330 localMicrophone ,
328331 generateDerivedConnectionStateValues ,
329332 ] ) ;
330- useEffect ( ( ) => {
333+ React . useEffect ( ( ) => {
331334 emitter . emit ( SessionEvent . ConnectionStateChanged , conversationState . connectionState ) ;
332335 } , [ emitter , conversationState . connectionState ] ) ;
333336
334- const waitUntilConnectionState = useCallback (
337+ const waitUntilConnectionState = React . useCallback (
335338 async ( state : UseSessionReturn [ 'connectionState' ] , signal ?: AbortSignal ) => {
336339 if ( conversationState . connectionState === state ) {
337340 return ;
@@ -362,7 +365,7 @@ export function useSession(
362365 [ conversationState . connectionState , emitter ] ,
363366 ) ;
364367
365- const waitUntilConnected = useCallback (
368+ const waitUntilConnected = React . useCallback (
366369 async ( signal ?: AbortSignal ) => {
367370 return waitUntilConnectionState (
368371 ConnectionState . Connected /* FIXME: should I check for other states too? */ ,
@@ -372,15 +375,15 @@ export function useSession(
372375 [ waitUntilConnectionState ] ,
373376 ) ;
374377
375- const waitUntilDisconnected = useCallback (
378+ const waitUntilDisconnected = React . useCallback (
376379 async ( signal ?: AbortSignal ) => {
377380 return waitUntilConnectionState ( ConnectionState . Disconnected , signal ) ;
378381 } ,
379382 [ waitUntilConnectionState ] ,
380383 ) ;
381384
382385 const agent = useAgent (
383- useMemo (
386+ React . useMemo (
384387 ( ) => ( {
385388 connectionState : conversationState . connectionState ,
386389 room,
@@ -393,7 +396,7 @@ export function useSession(
393396 ) ,
394397 ) ;
395398
396- const tokenSourceFetch = useCallback ( async ( ) => {
399+ const tokenSourceFetch = React . useCallback ( async ( ) => {
397400 const isConfigurable = tokenSource instanceof TokenSourceConfigurable ;
398401 if ( isConfigurable ) {
399402 const tokenFetchOptions = restOptions as UseSessionConfigurableOptions ;
@@ -403,7 +406,7 @@ export function useSession(
403406 }
404407 } , [ tokenSource , restOptions ] ) ;
405408
406- const start = useCallback (
409+ const start = React . useCallback (
407410 async ( connectOptions : SessionConnectOptions = { } ) => {
408411 const {
409412 signal,
@@ -443,24 +446,24 @@ export function useSession(
443446 [ room , waitUntilDisconnected , tokenSourceFetch , waitUntilConnected , agent . waitUntilAvailable ] ,
444447 ) ;
445448
446- const end = useCallback ( async ( ) => {
449+ const end = React . useCallback ( async ( ) => {
447450 await room . disconnect ( ) ;
448451 } , [ room ] ) ;
449452
450- const prepareConnection = useCallback ( async ( ) => {
453+ const prepareConnection = React . useCallback ( async ( ) => {
451454 const credentials = await tokenSourceFetch ( ) ;
452455 // FIXME: swap the below line in once the new `livekit-client` changes are published
453456 // room.prepareConnection(tokenSource, { tokenSourceOptions }),
454457 await room . prepareConnection ( credentials . serverUrl , credentials . participantToken ) ;
455458 } , [ tokenSourceFetch , room ] ) ;
456- useEffect ( ( ) => {
459+ React . useEffect ( ( ) => {
457460 prepareConnection ( ) . catch ( ( err ) => {
458461 // FIXME: figure out a better logging solution?
459462 console . warn ( 'WARNING: Room.prepareConnection failed:' , err ) ;
460463 } ) ;
461464 } , [ prepareConnection ] ) ;
462465
463- return useMemo (
466+ return React . useMemo (
464467 ( ) => ( {
465468 ...conversationState ,
466469
0 commit comments