@@ -60,6 +60,7 @@ describe("LocalTransport", () => {
6060 client : {
6161 // eslint-disable-next-line @typescript-eslint/naming-convention
6262 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
63+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
6364 getDomain : ( ) => "" ,
6465 baseUrl : "example.org" ,
6566 // These won't be called in this error path but satisfy the type
@@ -102,6 +103,7 @@ describe("LocalTransport", () => {
102103 baseUrl : "https://lk.example.org" ,
103104 // Use empty domain to skip .well-known and use config directly
104105 getDomain : ( ) => "" ,
106+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
105107 // eslint-disable-next-line @typescript-eslint/naming-convention
106108 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
107109 getOpenIdToken : vi . fn ( ) ,
@@ -149,6 +151,7 @@ describe("LocalTransport", () => {
149151 getOpenIdToken : vi . fn ( ) ,
150152 getDeviceId : vi . fn ( ) ,
151153 baseUrl : "https://lk.example.org" ,
154+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
152155 } ,
153156 ownMembershipIdentity : ownMemberMock ,
154157 forceJwtEndpoint : JwtEndpointVersion . Legacy ,
@@ -217,6 +220,7 @@ describe("LocalTransport", () => {
217220 getDomain : ( ) => "" ,
218221 // eslint-disable-next-line @typescript-eslint/naming-convention
219222 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
223+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
220224 getOpenIdToken : vi . fn ( ) ,
221225 getDeviceId : vi . fn ( ) ,
222226 baseUrl : "https://lk.example.org" ,
@@ -273,6 +277,7 @@ describe("LocalTransport", () => {
273277 // eslint-disable-next-line @typescript-eslint/naming-convention
274278 _unstable_getRTCTransports : async ( ) =>
275279 Promise . resolve ( [ aliceTransport ] ) ,
280+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
276281 getOpenIdToken : vi . fn ( ) ,
277282 getDeviceId : vi . fn ( ) ,
278283 baseUrl : "https://lk.example.org" ,
@@ -323,6 +328,7 @@ describe("LocalTransport", () => {
323328 getDomain : vi . fn ( ) . mockReturnValue ( "" ) ,
324329 // eslint-disable-next-line @typescript-eslint/naming-convention
325330 _unstable_getRTCTransports : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
331+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
326332 getOpenIdToken : vi . fn ( ) ,
327333 getDeviceId : vi . fn ( ) ,
328334 } ,
@@ -410,6 +416,42 @@ describe("LocalTransport", () => {
410416 } ) ;
411417 } ) ;
412418
419+ it ( "Should not call _unstable_getRTCTransports in widget mode but use well-known" , async ( ) => {
420+ mockConfig ( {
421+ livekit : { livekit_service_url : "https://do-not-use.lk.example.org" } ,
422+ } ) ;
423+
424+ localTransportOpts . client . getDomain . mockReturnValue ( "example.org" ) ;
425+
426+ fetchMock . getOnce ( "https://example.org/.well-known/matrix/client" , {
427+ "org.matrix.msc4143.rtc_foci" : [
428+ {
429+ type : "livekit" ,
430+ livekit_service_url : "https://use-me.jwt.call.example.org" ,
431+ } ,
432+ ] ,
433+ } ) ;
434+
435+ localTransportOpts . client . getAccessToken . mockReturnValue ( null ) ;
436+ const { advertised$, active$ } =
437+ createLocalTransport$ ( localTransportOpts ) ;
438+ openIdResolver . resolve ?.( openIdResponse ) ;
439+ expect ( advertised$ . value ) . toBe ( null ) ;
440+ expect ( active$ . value ) . toBe ( null ) ;
441+ await flushPromises ( ) ;
442+
443+ expect (
444+ localTransportOpts . client . _unstable_getRTCTransports ,
445+ ) . not . toHaveBeenCalled ( ) ;
446+
447+ const expectedTransport = {
448+ type : "livekit" ,
449+ livekit_service_url : "https://use-me.jwt.call.example.org" ,
450+ } ;
451+
452+ expect ( advertised$ . value ) . toStrictEqual ( expectedTransport ) ;
453+ } ) ;
454+
413455 it ( "fails fast if the openID request fails for backend config" , async ( ) => {
414456 localTransportOpts . client . _unstable_getRTCTransports . mockResolvedValue ( [
415457 { type : "livekit" , livekit_service_url : "https://lk.example.org" } ,
@@ -481,6 +523,7 @@ describe("LocalTransport", () => {
481523 baseUrl : "https://example.org" ,
482524 // eslint-disable-next-line @typescript-eslint/naming-convention
483525 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
526+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
484527 // These won't be called in this error path but satisfy the type
485528 getOpenIdToken : vi . fn ( ) ,
486529 getDeviceId : vi . fn ( ) ,
0 commit comments