@@ -21,6 +21,7 @@ import {
2121} from "matrix-js-sdk/lib/matrixrtc" ;
2222import { BehaviorSubject , lastValueFrom } from "rxjs" ;
2323import fetchMock from "fetch-mock" ;
24+ import { AutoDiscovery } from "matrix-js-sdk/lib/autodiscovery" ;
2425
2526import {
2627 mockConfig ,
@@ -60,6 +61,7 @@ describe("LocalTransport", () => {
6061 client : {
6162 // eslint-disable-next-line @typescript-eslint/naming-convention
6263 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
64+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
6365 getDomain : ( ) => "" ,
6466 baseUrl : "example.org" ,
6567 // These won't be called in this error path but satisfy the type
@@ -102,6 +104,7 @@ describe("LocalTransport", () => {
102104 baseUrl : "https://lk.example.org" ,
103105 // Use empty domain to skip .well-known and use config directly
104106 getDomain : ( ) => "" ,
107+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
105108 // eslint-disable-next-line @typescript-eslint/naming-convention
106109 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
107110 getOpenIdToken : vi . fn ( ) ,
@@ -149,6 +152,7 @@ describe("LocalTransport", () => {
149152 getOpenIdToken : vi . fn ( ) ,
150153 getDeviceId : vi . fn ( ) ,
151154 baseUrl : "https://lk.example.org" ,
155+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
152156 } ,
153157 ownMembershipIdentity : ownMemberMock ,
154158 forceJwtEndpoint : JwtEndpointVersion . Legacy ,
@@ -217,6 +221,7 @@ describe("LocalTransport", () => {
217221 getDomain : ( ) => "" ,
218222 // eslint-disable-next-line @typescript-eslint/naming-convention
219223 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
224+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
220225 getOpenIdToken : vi . fn ( ) ,
221226 getDeviceId : vi . fn ( ) ,
222227 baseUrl : "https://lk.example.org" ,
@@ -273,6 +278,7 @@ describe("LocalTransport", () => {
273278 // eslint-disable-next-line @typescript-eslint/naming-convention
274279 _unstable_getRTCTransports : async ( ) =>
275280 Promise . resolve ( [ aliceTransport ] ) ,
281+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
276282 getOpenIdToken : vi . fn ( ) ,
277283 getDeviceId : vi . fn ( ) ,
278284 baseUrl : "https://lk.example.org" ,
@@ -323,6 +329,7 @@ describe("LocalTransport", () => {
323329 getDomain : vi . fn ( ) . mockReturnValue ( "" ) ,
324330 // eslint-disable-next-line @typescript-eslint/naming-convention
325331 _unstable_getRTCTransports : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
332+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
326333 getOpenIdToken : vi . fn ( ) ,
327334 getDeviceId : vi . fn ( ) ,
328335 } ,
@@ -410,6 +417,49 @@ describe("LocalTransport", () => {
410417 } ) ;
411418 } ) ;
412419
420+ it ( "Should not call _unstable_getRTCTransports in widget mode but use well-known" , async ( ) => {
421+ mockConfig ( {
422+ livekit : { livekit_service_url : "https://do-not-use.lk.example.org" } ,
423+ } ) ;
424+
425+ localTransportOpts . client . getDomain . mockReturnValue ( "example.org" ) ;
426+
427+ vi . spyOn ( AutoDiscovery , "getRawClientConfig" ) . mockImplementation (
428+ async ( domain ) => {
429+ if ( domain === "example.org" ) {
430+ return Promise . resolve ( {
431+ "org.matrix.msc4143.rtc_foci" : [
432+ {
433+ type : "livekit" ,
434+ livekit_service_url : "https://use-me.jwt.call.example.org" ,
435+ } ,
436+ ] ,
437+ } ) ;
438+ }
439+ return Promise . resolve ( { } ) ;
440+ } ,
441+ ) ;
442+
443+ localTransportOpts . client . getAccessToken . mockReturnValue ( null ) ;
444+ const { advertised$, active$ } =
445+ createLocalTransport$ ( localTransportOpts ) ;
446+ openIdResolver . resolve ?.( openIdResponse ) ;
447+ expect ( advertised$ . value ) . toBe ( null ) ;
448+ expect ( active$ . value ) . toBe ( null ) ;
449+ await flushPromises ( ) ;
450+
451+ expect (
452+ localTransportOpts . client . _unstable_getRTCTransports ,
453+ ) . not . toHaveBeenCalled ( ) ;
454+
455+ const expectedTransport = {
456+ type : "livekit" ,
457+ livekit_service_url : "https://use-me.jwt.call.example.org" ,
458+ } ;
459+
460+ expect ( advertised$ . value ) . toStrictEqual ( expectedTransport ) ;
461+ } ) ;
462+
413463 it ( "fails fast if the openID request fails for backend config" , async ( ) => {
414464 localTransportOpts . client . _unstable_getRTCTransports . mockResolvedValue ( [
415465 { type : "livekit" , livekit_service_url : "https://lk.example.org" } ,
@@ -481,6 +531,7 @@ describe("LocalTransport", () => {
481531 baseUrl : "https://example.org" ,
482532 // eslint-disable-next-line @typescript-eslint/naming-convention
483533 _unstable_getRTCTransports : async ( ) => Promise . resolve ( [ ] ) ,
534+ getAccessToken : vi . fn ( ) . mockReturnValue ( "access_token" ) ,
484535 // These won't be called in this error path but satisfy the type
485536 getOpenIdToken : vi . fn ( ) ,
486537 getDeviceId : vi . fn ( ) ,
0 commit comments