diff --git a/src/state/CallViewModel/localMember/LocalTransport.test.ts b/src/state/CallViewModel/localMember/LocalTransport.test.ts index aa6228c9..895f3073 100644 --- a/src/state/CallViewModel/localMember/LocalTransport.test.ts +++ b/src/state/CallViewModel/localMember/LocalTransport.test.ts @@ -544,13 +544,13 @@ describe("LocalTransport", () => { }); }); - it("should not update advertised transport on delayID changes, but active should update", async () => { + it("should not update advertised/active transport on delayID changes, but delay Id delegation should be called", async () => { // For simplicity, we'll just use the config livekit customLivekitUrl.setValue("https://lk.example.org"); - vi.spyOn(openIDSFU, "getSFUConfigWithOpenID").mockResolvedValue( - openIdResponse, - ); + const authCallSpy = vi + .spyOn(openIDSFU, "getSFUConfigWithOpenID") + .mockResolvedValue(openIdResponse); const delayId$ = new BehaviorSubject(null); @@ -596,6 +596,7 @@ describe("LocalTransport", () => { "https://lk.example.org", ); + expect(authCallSpy).toHaveBeenCalledTimes(2); // Now emits 3 new delays id delayId$.next("delay_id_1"); await flushPromises(); @@ -604,8 +605,24 @@ describe("LocalTransport", () => { delayId$.next("delay_id_3"); await flushPromises(); - // No new emissions should've happened, it is the same transport. only auth and delegation of delay has changed + // No new emissions should've happened, it is the same transport. expect(advertisedValues.length).toEqual(1); - expect(activeValues.length).toEqual(4); + expect(activeValues.length).toEqual(1); + + // Still we should have updated the delayID to auth + expect(authCallSpy).toHaveBeenCalledTimes( + 4 * 2 /* 2 calls for each delayId ?? why */, + ); + + expect(authCallSpy).toHaveBeenLastCalledWith( + expect.anything(), + expect.anything(), + expect.anything(), + expect.anything(), + expect.objectContaining({ + delayId: "delay_id_3", + }), + expect.anything(), + ); }); }); diff --git a/src/state/CallViewModel/localMember/LocalTransport.ts b/src/state/CallViewModel/localMember/LocalTransport.ts index f4cbd84a..037b6a0b 100644 --- a/src/state/CallViewModel/localMember/LocalTransport.ts +++ b/src/state/CallViewModel/localMember/LocalTransport.ts @@ -222,7 +222,21 @@ export const createLocalTransport$ = ({ ), null, ), - active$: scope.behavior(preferredTransport$, null), + active$: scope.behavior( + preferredTransport$.pipe( + // XXX: WORK AROUND due to a reconnection glitch. + // To remove when we have a proper way to refresh the delegation event ID without refreshing + // the whole credentials. + // We deliberately hide any changes to the SFU config because we + // do not want the app to reconnect whenever the JWT + // token changes due to us delegating a new delayed event. The + // initial SFU config for the transport is all the app needs. + distinctUntilChanged((prev, next) => + areLivekitTransportsEqual(prev.transport, next.transport), + ), + ), + null, + ), }; };