@@ -269,55 +269,6 @@ describe("MatrixRTCSession", () => {
269269 } ) ;
270270 } ) ;
271271
272- describe ( "getsActiveFocus" , ( ) => {
273- const firstPreferredFocus = {
274- type : "livekit" ,
275- livekit_service_url : "https://active.url" ,
276- livekit_alias : "!active:active.url" ,
277- } ;
278- it ( "gets the correct active focus with oldest_membership" , ( ) => {
279- jest . useFakeTimers ( ) ;
280- jest . setSystemTime ( 3000 ) ;
281- const mockRoom = makeMockRoom ( [
282- Object . assign ( { } , membershipTemplate , {
283- device_id : "foo" ,
284- created_ts : 500 ,
285- foci_preferred : [ firstPreferredFocus ] ,
286- } ) ,
287- Object . assign ( { } , membershipTemplate , { device_id : "old" , created_ts : 1000 } ) ,
288- Object . assign ( { } , membershipTemplate , { device_id : "bar" , created_ts : 2000 } ) ,
289- ] ) ;
290-
291- sess = MatrixRTCSession . roomSessionForRoom ( client , mockRoom ) ;
292-
293- sess . joinRoomSession ( [ { type : "livekit" , livekit_service_url : "htts://test.org" } ] , {
294- type : "livekit" ,
295- focus_selection : "oldest_membership" ,
296- } ) ;
297- expect ( sess . getActiveFocus ( ) ) . toBe ( firstPreferredFocus ) ;
298- jest . useRealTimers ( ) ;
299- } ) ;
300- it ( "does not provide focus if the selection method is unknown" , ( ) => {
301- const mockRoom = makeMockRoom ( [
302- Object . assign ( { } , membershipTemplate , {
303- device_id : "foo" ,
304- created_ts : 500 ,
305- foci_preferred : [ firstPreferredFocus ] ,
306- } ) ,
307- Object . assign ( { } , membershipTemplate , { device_id : "old" , created_ts : 1000 } ) ,
308- Object . assign ( { } , membershipTemplate , { device_id : "bar" , created_ts : 2000 } ) ,
309- ] ) ;
310-
311- sess = MatrixRTCSession . roomSessionForRoom ( client , mockRoom ) ;
312-
313- sess . joinRoomSession ( [ { type : "livekit" , livekit_service_url : "htts://test.org" } ] , {
314- type : "livekit" ,
315- focus_selection : "unknown" ,
316- } ) ;
317- expect ( sess . getActiveFocus ( ) ) . toBe ( undefined ) ;
318- } ) ;
319- } ) ;
320-
321272 describe ( "joining" , ( ) => {
322273 let mockRoom : Room ;
323274 let sendStateEventMock : jest . Mock ;
@@ -368,68 +319,6 @@ describe("MatrixRTCSession", () => {
368319 expect ( sess ! . isJoined ( ) ) . toEqual ( true ) ;
369320 } ) ;
370321
371- it ( "sends a membership event when joining a call" , async ( ) => {
372- const realSetTimeout = setTimeout ;
373- jest . useFakeTimers ( ) ;
374- sess ! . joinRoomSession ( [ mockFocus ] , mockFocus ) ;
375- await Promise . race ( [ sentStateEvent , new Promise ( ( resolve ) => realSetTimeout ( resolve , 500 ) ) ] ) ;
376- expect ( client . sendStateEvent ) . toHaveBeenCalledWith (
377- mockRoom ! . roomId ,
378- EventType . GroupCallMemberPrefix ,
379- {
380- application : "m.call" ,
381- scope : "m.room" ,
382- call_id : "" ,
383- device_id : "AAAAAAA" ,
384- expires : DEFAULT_EXPIRE_DURATION ,
385- foci_preferred : [ mockFocus ] ,
386- focus_active : {
387- focus_selection : "oldest_membership" ,
388- type : "livekit" ,
389- } ,
390- } ,
391- "_@alice:example.org_AAAAAAA" ,
392- ) ;
393- await Promise . race ( [ sentDelayedState , new Promise ( ( resolve ) => realSetTimeout ( resolve , 500 ) ) ] ) ;
394- // Because we actually want to send the state
395- expect ( client . sendStateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
396- // For checking if the delayed event is still there or got removed while sending the state.
397- expect ( client . _unstable_updateDelayedEvent ) . toHaveBeenCalledTimes ( 1 ) ;
398- // For scheduling the delayed event
399- expect ( client . _unstable_sendDelayedStateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
400- // This returns no error so we do not check if we reschedule the event again. this is done in another test.
401-
402- jest . useRealTimers ( ) ;
403- } ) ;
404-
405- it ( "uses membershipExpiryTimeout from join config" , async ( ) => {
406- const realSetTimeout = setTimeout ;
407- jest . useFakeTimers ( ) ;
408- sess ! . joinRoomSession ( [ mockFocus ] , mockFocus , { membershipExpiryTimeout : 60000 } ) ;
409- await Promise . race ( [ sentStateEvent , new Promise ( ( resolve ) => realSetTimeout ( resolve , 500 ) ) ] ) ;
410- expect ( client . sendStateEvent ) . toHaveBeenCalledWith (
411- mockRoom ! . roomId ,
412- EventType . GroupCallMemberPrefix ,
413- {
414- application : "m.call" ,
415- scope : "m.room" ,
416- call_id : "" ,
417- device_id : "AAAAAAA" ,
418- expires : 60000 ,
419- foci_preferred : [ mockFocus ] ,
420- focus_active : {
421- focus_selection : "oldest_membership" ,
422- type : "livekit" ,
423- } ,
424- } ,
425-
426- "_@alice:example.org_AAAAAAA" ,
427- ) ;
428- await Promise . race ( [ sentDelayedState , new Promise ( ( resolve ) => realSetTimeout ( resolve , 500 ) ) ] ) ;
429- expect ( client . _unstable_sendDelayedStateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
430- jest . useRealTimers ( ) ;
431- } ) ;
432-
433322 describe ( "calls" , ( ) => {
434323 const activeFocusConfig = { type : "livekit" , livekit_service_url : "https://active.url" } ;
435324 const activeFocus = { type : "livekit" , focus_selection : "oldest_membership" } ;
@@ -547,78 +436,6 @@ describe("MatrixRTCSession", () => {
547436 expect ( client . sendStateEvent ) . toHaveBeenCalledTimes ( 1 ) ;
548437 } ) ;
549438
550- it ( "renews membership event before expiry time" , async ( ) => {
551- return "TODO add back the renew method since we also want this for non-legacy events." ;
552- const activeFocus = { type : "livekit" , focus_selection : "oldest_membership" } ;
553-
554- jest . useFakeTimers ( ) ;
555- let resolveFn : ( ( _roomId : string , _type : string , val : Record < string , any > ) => void ) | undefined ;
556-
557- const eventSentPromise = new Promise < Record < string , any > > ( ( r ) => {
558- resolveFn = ( _roomId : string , _type : string , val : Record < string , any > ) => {
559- r ( val ) ;
560- } ;
561- } ) ;
562- try {
563- const sendStateEventMock = jest . fn ( ) . mockImplementation ( resolveFn ) ;
564- client . sendStateEvent = sendStateEventMock ;
565-
566- sess ! . joinRoomSession ( [ mockFocus ] , mockFocus , { membershipExpiryTimeout : 60 * 60 * 1000 } ) ;
567-
568- const eventContent = await eventSentPromise ;
569-
570- jest . setSystemTime ( 1000 ) ;
571- const event = mockRTCEvent ( eventContent . memberships , mockRoom . roomId ) ;
572- const getState = mockRoom . getLiveTimeline ( ) . getState ( EventTimeline . FORWARDS ) ! ;
573- getState . getStateEvents = jest . fn ( ) . mockReturnValue ( event ) ;
574- getState . events = new Map ( [
575- [
576- event . getType ( ) ,
577- {
578- size : ( ) => true ,
579- has : ( _stateKey : string ) => true ,
580- get : ( _stateKey : string ) => event ,
581- values : ( ) => [ event ] ,
582- } as unknown as Map < string , MatrixEvent > ,
583- ] ,
584- ] ) ;
585-
586- const eventReSentPromise = new Promise < Record < string , any > > ( ( r ) => {
587- resolveFn = ( _roomId : string , _type : string , val : Record < string , any > ) => {
588- r ( val ) ;
589- } ;
590- } ) ;
591-
592- sendStateEventMock . mockReset ( ) . mockImplementation ( resolveFn ) ;
593-
594- // definitely should have renewed by 1 second before the expiry!
595- const timeElapsed = 60 * 60 * 1000 - 1000 ;
596- jest . setSystemTime ( Date . now ( ) + timeElapsed ) ;
597- jest . advanceTimersByTime ( timeElapsed ) ;
598- await eventReSentPromise ;
599-
600- expect ( sendStateEventMock ) . toHaveBeenCalledWith (
601- mockRoom . roomId ,
602- EventType . GroupCallMemberPrefix ,
603- {
604- application : "m.call" ,
605- scope : "m.room" ,
606- call_id : "" ,
607- device_id : "AAAAAAA" ,
608- expires : 3600000 * 2 ,
609- foci_preferred : [ mockFocus ] ,
610- focus_active : activeFocus ,
611- created_ts : 1000 ,
612- membershipID : expect . stringMatching ( ".*" ) ,
613- } ,
614- "_@alice:example.org_AAAAAAA" ,
615- ) ;
616- } finally {
617- jest . useRealTimers ( ) ;
618- }
619- } ) ;
620- } ) ;
621-
622439 describe ( "onMembershipsChanged" , ( ) => {
623440 it ( "does not emit if no membership changes" , ( ) => {
624441 const mockRoom = makeMockRoom ( membershipTemplate ) ;
@@ -950,92 +767,6 @@ describe("MatrixRTCSession", () => {
950767 }
951768 } ) ;
952769
953- it ( "re-sends key if a member changes membership ID" , async ( ) => {
954- return "membershipID is not a thing anymore" ;
955- /*
956- jest.useFakeTimers();
957- try {
958- const keysSentPromise1 = new Promise((resolve) => {
959- sendEventMock.mockImplementation(resolve);
960- });
961-
962- const member1 = membershipTemplate;
963- const member2 = {
964- ...membershipTemplate,
965- device_id: "BBBBBBB",
966- };
967-
968- const mockRoom = makeMockRoom([member1, member2]);
969- mockRoom.getLiveTimeline().getState = jest
970- .fn()
971- .mockReturnValue(makeMockRoomState([member1, member2], mockRoom.roomId));
972-
973- sess = MatrixRTCSession.roomSessionForRoom(client, mockRoom);
974- sess.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
975-
976- await keysSentPromise1;
977-
978- // make sure an encryption key was sent
979- expect(sendEventMock).toHaveBeenCalledWith(
980- expect.stringMatching(".*"),
981- "io.element.call.encryption_keys",
982- {
983- call_id: "",
984- device_id: "AAAAAAA",
985- keys: [
986- {
987- index: 0,
988- key: expect.stringMatching(".*"),
989- },
990- ],
991- sent_ts: Date.now(),
992- },
993- );
994- expect(sess!.statistics.counters.roomEventEncryptionKeysSent).toEqual(1);
995-
996- sendEventMock.mockClear();
997-
998- // this should be a no-op:
999- sess.onMembershipUpdate();
1000- expect(sendEventMock).toHaveBeenCalledTimes(0);
1001-
1002- // advance time to avoid key throttling
1003- jest.advanceTimersByTime(10000);
1004-
1005- // update membership ID
1006- member2.membershipID = "newID";
1007-
1008- const keysSentPromise2 = new Promise((resolve) => {
1009- sendEventMock.mockImplementation(resolve);
1010- });
1011-
1012- // this should re-send the key
1013- sess.onMembershipUpdate();
1014-
1015- await keysSentPromise2;
1016-
1017- expect(sendEventMock).toHaveBeenCalledWith(
1018- expect.stringMatching(".*"),
1019- "io.element.call.encryption_keys",
1020- {
1021- call_id: "",
1022- device_id: "AAAAAAA",
1023- keys: [
1024- {
1025- index: 0,
1026- key: expect.stringMatching(".*"),
1027- },
1028- ],
1029- sent_ts: Date.now(),
1030- },
1031- );
1032- expect(sess!.statistics.counters.roomEventEncryptionKeysSent).toEqual(2);
1033- } finally {
1034- jest.useRealTimers();
1035- }
1036- */
1037- } ) ;
1038-
1039770 it ( "re-sends key if a member changes created_ts" , async ( ) => {
1040771 jest . useFakeTimers ( ) ;
1041772 jest . setSystemTime ( 1000 ) ;
0 commit comments