@@ -220,6 +220,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
220220
221221 private shouldFailNext : boolean = false ;
222222
223+ private shouldFailOnV1Path : boolean = false ;
224+
223225 private regionUrlProvider ?: RegionUrlProvider ;
224226
225227 private log = log ;
@@ -321,9 +323,16 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
321323 offerProto = toProtoSessionDescription ( offer . offer , offer . offerId ) ;
322324 }
323325 }
326+
324327 if ( abortSignal ?. aborted ) {
325328 throw ConnectionError . cancelled ( 'Connection aborted' ) ;
326329 }
330+
331+ if ( ! useV0Path && this . shouldFailOnV1Path ) {
332+ this . shouldFailOnV1Path = false ;
333+ throw ConnectionError . serviceNotFound ( 'Simulated v1 path failure' , 'v0-rtc' ) ;
334+ }
335+ log . warn ( 'joining signal with ' , url ) ;
327336 const joinResponse = await this . client . join (
328337 url ,
329338 token ,
@@ -383,6 +392,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
383392 }
384393 } else if ( e . reason === ConnectionErrorReason . ServiceNotFound ) {
385394 this . log . warn ( `Initial connection failed: ${ e . message } – Retrying` ) ;
395+ if ( this . pcManager ) {
396+ this . pcManager . onStateChange = undefined ;
397+ await this . cleanupPeerConnections ( ) ;
398+ }
386399 return this . join ( url , token , opts , abortSignal , true ) ;
387400 }
388401 }
@@ -1860,6 +1873,12 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
18601873 this . shouldFailNext = true ;
18611874 }
18621875
1876+ /* @internal */
1877+ failNextV1Path ( ) {
1878+ // debugging method to fail the next connection attempt for /rtc/v1 to trigger the fallback version
1879+ this . shouldFailOnV1Path = true ;
1880+ }
1881+
18631882 private dataChannelsInfo ( ) : DataChannelInfo [ ] {
18641883 const infos : DataChannelInfo [ ] = [ ] ;
18651884 const getInfo = ( dc : RTCDataChannel | undefined , target : SignalTarget ) => {
0 commit comments