@@ -14,19 +14,9 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import {
18
- encodeBase64 ,
19
- EventType ,
20
- IRoomTimelineData ,
21
- MatrixClient ,
22
- RoomEvent ,
23
- type MatrixError ,
24
- type MatrixEvent ,
25
- type Room ,
26
- } from "../../../src" ;
17
+ import { encodeBase64 , EventType , MatrixClient , type MatrixError , type MatrixEvent , type Room } from "../../../src" ;
27
18
import { KnownMembership } from "../../../src/@types/membership" ;
28
19
import { DEFAULT_EXPIRE_DURATION , type SessionMembershipData } from "../../../src/matrixrtc/CallMembership" ;
29
- import { IKeyTransport } from "../../../src/matrixrtc/IKeyTransport" ;
30
20
import { MatrixRTCSession , MatrixRTCSessionEvent } from "../../../src/matrixrtc/MatrixRTCSession" ;
31
21
import { type EncryptionKeysEventContent } from "../../../src/matrixrtc/types" ;
32
22
import { secureRandomString } from "../../../src/randomstring" ;
@@ -45,6 +35,9 @@ describe("MatrixRTCSession", () => {
45
35
client . getUserId = jest . fn ( ) . mockReturnValue ( "@alice:example.org" ) ;
46
36
client . getDeviceId = jest . fn ( ) . mockReturnValue ( "AAAAAAA" ) ;
47
37
client . sendEvent = jest . fn ( ) . mockResolvedValue ( { event_id : "success" } ) ;
38
+ client . decryptEventIfNeeded = jest . fn ( ) . mockImplementation ( ( ) => {
39
+ console . log ( "Fake decryptEventIfNeeded" ) ;
40
+ } ) ;
48
41
} ) ;
49
42
50
43
afterEach ( async ( ) => {
@@ -997,7 +990,7 @@ describe("MatrixRTCSession", () => {
997
990
} ) ;
998
991
999
992
describe ( "receiving" , ( ) => {
1000
- it ( "collects keys from encryption events" , ( ) => {
993
+ it ( "collects keys from encryption events" , async ( ) => {
1001
994
const mockRoom = makeMockRoom ( [ membershipTemplate ] ) ;
1002
995
sess = MatrixRTCSession . roomSessionForRoom ( client , mockRoom ) ;
1003
996
sess ! . joinRoomSession ( [ mockFocus ] , mockFocus , { manageMediaKeys : true } ) ;
@@ -1013,6 +1006,7 @@ describe("MatrixRTCSession", () => {
1013
1006
] ,
1014
1007
} ) ,
1015
1008
) ;
1009
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1016
1010
const encryptionKeyChangedListener = jest . fn ( ) ;
1017
1011
sess ! . on ( MatrixRTCSessionEvent . EncryptionKeyChanged , encryptionKeyChangedListener ) ;
1018
1012
sess ! . reemitEncryptionKeys ( ) ;
@@ -1026,7 +1020,7 @@ describe("MatrixRTCSession", () => {
1026
1020
expect ( sess ! . statistics . counters . roomEventEncryptionKeysReceived ) . toEqual ( 1 ) ;
1027
1021
} ) ;
1028
1022
1029
- it ( "collects keys at non-zero indices" , ( ) => {
1023
+ it ( "collects keys at non-zero indices" , async ( ) => {
1030
1024
const mockRoom = makeMockRoom ( [ membershipTemplate ] ) ;
1031
1025
sess = MatrixRTCSession . roomSessionForRoom ( client , mockRoom ) ;
1032
1026
sess ! . joinRoomSession ( [ mockFocus ] , mockFocus , { manageMediaKeys : true } ) ;
@@ -1042,6 +1036,7 @@ describe("MatrixRTCSession", () => {
1042
1036
] ,
1043
1037
} ) ,
1044
1038
) ;
1039
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1045
1040
1046
1041
const encryptionKeyChangedListener = jest . fn ( ) ;
1047
1042
sess ! . on ( MatrixRTCSessionEvent . EncryptionKeyChanged , encryptionKeyChangedListener ) ;
@@ -1056,7 +1051,7 @@ describe("MatrixRTCSession", () => {
1056
1051
expect ( sess ! . statistics . counters . roomEventEncryptionKeysReceived ) . toEqual ( 1 ) ;
1057
1052
} ) ;
1058
1053
1059
- it ( "collects keys by merging" , ( ) => {
1054
+ it ( "collects keys by merging" , async ( ) => {
1060
1055
const mockRoom = makeMockRoom ( [ membershipTemplate ] ) ;
1061
1056
sess = MatrixRTCSession . roomSessionForRoom ( client , mockRoom ) ;
1062
1057
sess ! . joinRoomSession ( [ mockFocus ] , mockFocus , { manageMediaKeys : true } ) ;
@@ -1072,6 +1067,7 @@ describe("MatrixRTCSession", () => {
1072
1067
] ,
1073
1068
} ) ,
1074
1069
) ;
1070
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1075
1071
1076
1072
const encryptionKeyChangedListener = jest . fn ( ) ;
1077
1073
sess ! . on ( MatrixRTCSessionEvent . EncryptionKeyChanged , encryptionKeyChangedListener ) ;
@@ -1097,6 +1093,7 @@ describe("MatrixRTCSession", () => {
1097
1093
] ,
1098
1094
} ) ,
1099
1095
) ;
1096
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1100
1097
1101
1098
encryptionKeyChangedListener . mockClear ( ) ;
1102
1099
sess ! . reemitEncryptionKeys ( ) ;
@@ -1115,7 +1112,7 @@ describe("MatrixRTCSession", () => {
1115
1112
expect ( sess ! . statistics . counters . roomEventEncryptionKeysReceived ) . toEqual ( 2 ) ;
1116
1113
} ) ;
1117
1114
1118
- it ( "ignores older keys at same index" , ( ) => {
1115
+ it ( "ignores older keys at same index" , async ( ) => {
1119
1116
const mockRoom = makeMockRoom ( [ membershipTemplate ] ) ;
1120
1117
sess = MatrixRTCSession . roomSessionForRoom ( client , mockRoom ) ;
1121
1118
sess ! . joinRoomSession ( [ mockFocus ] , mockFocus , { manageMediaKeys : true } ) ;
@@ -1174,6 +1171,7 @@ describe("MatrixRTCSession", () => {
1174
1171
1000 ,
1175
1172
) ,
1176
1173
) ;
1174
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1177
1175
1178
1176
const encryptionKeyChangedListener = jest . fn ( ) ;
1179
1177
sess ! . on ( MatrixRTCSessionEvent . EncryptionKeyChanged , encryptionKeyChangedListener ) ;
@@ -1188,7 +1186,7 @@ describe("MatrixRTCSession", () => {
1188
1186
expect ( sess ! . statistics . counters . roomEventEncryptionKeysReceived ) . toEqual ( 3 ) ;
1189
1187
} ) ;
1190
1188
1191
- it ( "key timestamps are treated as monotonic" , ( ) => {
1189
+ it ( "key timestamps are treated as monotonic" , async ( ) => {
1192
1190
const mockRoom = makeMockRoom ( [ membershipTemplate ] ) ;
1193
1191
sess = MatrixRTCSession . roomSessionForRoom ( client , mockRoom ) ;
1194
1192
sess ! . joinRoomSession ( [ mockFocus ] , mockFocus , { manageMediaKeys : true } ) ;
@@ -1229,6 +1227,7 @@ describe("MatrixRTCSession", () => {
1229
1227
1000 ,
1230
1228
) ,
1231
1229
) ;
1230
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1232
1231
1233
1232
const encryptionKeyChangedListener = jest . fn ( ) ;
1234
1233
sess ! . on ( MatrixRTCSessionEvent . EncryptionKeyChanged , encryptionKeyChangedListener ) ;
@@ -1267,7 +1266,7 @@ describe("MatrixRTCSession", () => {
1267
1266
expect ( sess ! . statistics . counters . roomEventEncryptionKeysReceived ) . toEqual ( 0 ) ;
1268
1267
} ) ;
1269
1268
1270
- it ( "tracks total age statistics for collected keys" , ( ) => {
1269
+ it ( "tracks total age statistics for collected keys" , async ( ) => {
1271
1270
jest . useFakeTimers ( ) ;
1272
1271
try {
1273
1272
const mockRoom = makeMockRoom ( [ membershipTemplate ] ) ;
@@ -1294,6 +1293,7 @@ describe("MatrixRTCSession", () => {
1294
1293
0 ,
1295
1294
) ,
1296
1295
) ;
1296
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1297
1297
1298
1298
expect ( sess ! . statistics . totals . roomEventEncryptionKeysReceivedTotalAge ) . toEqual ( 1000 ) ;
1299
1299
@@ -1312,6 +1312,7 @@ describe("MatrixRTCSession", () => {
1312
1312
sent_ts : 0 ,
1313
1313
} ) ,
1314
1314
) ;
1315
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1315
1316
1316
1317
expect ( sess ! . statistics . totals . roomEventEncryptionKeysReceivedTotalAge ) . toEqual ( 3000 ) ;
1317
1318
@@ -1329,6 +1330,7 @@ describe("MatrixRTCSession", () => {
1329
1330
sent_ts : 1000 ,
1330
1331
} ) ,
1331
1332
) ;
1333
+ await jest . advanceTimersToNextTimerAsync ( ) ;
1332
1334
1333
1335
expect ( sess ! . statistics . totals . roomEventEncryptionKeysReceivedTotalAge ) . toEqual ( 5000 ) ;
1334
1336
} finally {
0 commit comments