File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed
Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @livekit/components-react " : patch
3+ ---
4+
5+ Don't emit connection errors if ` connect ` is set to false
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ export function useLiveKitRoom<T extends HTMLElement>(
5555
5656 const [ room , setRoom ] = React . useState < Room | undefined > ( ) ;
5757
58+ const shouldConnect = React . useRef ( connect ) ;
59+
5860 React . useEffect ( ( ) => {
5961 setRoom ( passedRoom ?? new Room ( options ) ) ;
6062 } , [ passedRoom ] ) ;
@@ -115,23 +117,28 @@ export function useLiveKitRoom<T extends HTMLElement>(
115117 } ) ;
116118 return ;
117119 }
118- if ( ! token ) {
119- log . debug ( 'no token yet' ) ;
120- return ;
121- }
122- if ( ! serverUrl ) {
123- log . warn ( 'no livekit url provided' ) ;
124- onError ?.( Error ( 'no livekit url provided' ) ) ;
125- return ;
126- }
120+
127121 if ( connect ) {
122+ shouldConnect . current = true ;
128123 log . debug ( 'connecting' ) ;
124+ if ( ! token ) {
125+ log . debug ( 'no token yet' ) ;
126+ return ;
127+ }
128+ if ( ! serverUrl ) {
129+ log . warn ( 'no livekit url provided' ) ;
130+ onError ?.( Error ( 'no livekit url provided' ) ) ;
131+ return ;
132+ }
129133 room . connect ( serverUrl , token , connectOptions ) . catch ( ( e ) => {
130134 log . warn ( e ) ;
131- onError ?.( e as Error ) ;
135+ if ( shouldConnect . current === true ) {
136+ onError ?.( e as Error ) ;
137+ }
132138 } ) ;
133139 } else {
134140 log . debug ( 'disconnecting because connect is false' ) ;
141+ shouldConnect . current = false ;
135142 room . disconnect ( ) ;
136143 }
137144 } , [
You can’t perform that action at this time.
0 commit comments