diff --git a/src/livekit/useLivekit.ts b/src/livekit/useLivekit.ts index 24e0ca29..4c669b47 100644 --- a/src/livekit/useLivekit.ts +++ b/src/livekit/useLivekit.ts @@ -9,6 +9,7 @@ import { ConnectionState, type E2EEManagerOptions, ExternalE2EEKeyProvider, + type LocalTrackPublication, LocalVideoTrack, Room, type RoomOptions, @@ -181,6 +182,33 @@ export function useLivekit( sfuConfig, ); + // Log errors when local participant has issues publishing a track. + useEffect(() => { + const localTrackUnpublishedFn = ( + publication: LocalTrackPublication, + ): void => { + logger.info( + "Local track unpublished", + publication.trackName, + publication.trackInfo, + ); + }; + const mediaDevicesErrorFn = (error: Error): void => { + logger.warn("Media devices error when publishing a track", error); + }; + + room.localParticipant.on("localTrackUnpublished", localTrackUnpublishedFn); + room.localParticipant.on("mediaDevicesError", mediaDevicesErrorFn); + + return (): void => { + room.localParticipant.off( + "localTrackUnpublished", + localTrackUnpublishedFn, + ); + room.localParticipant.off("mediaDevicesError", mediaDevicesErrorFn); + }; + }, [room.localParticipant]); + useEffect(() => { // Sync the requested mute states with LiveKit's mute states. We do it this // way around rather than using LiveKit as the source of truth, so that the