1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Await encrypted messages (#4063)

* await encrypted messages
+ fix comments

Signed-off-by: Timo K <toger5@hotmail.de>

* fix Tests

Signed-off-by: Timo K <toger5@hotmail.de>

* fix test

Signed-off-by: Timo K <toger5@hotmail.de>

* make sonar happy

Signed-off-by: Timo K <toger5@hotmail.de>

---------

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo
2024-02-14 12:25:43 +01:00
committed by GitHub
parent d03db17405
commit 5d7218476a
3 changed files with 12 additions and 7 deletions

View File

@@ -87,7 +87,7 @@ describe("MatrixRTCSessionManager", () => {
expect(onEnded).toHaveBeenCalledWith(room1.roomId, client.matrixRTC.getActiveRoomSession(room1)); expect(onEnded).toHaveBeenCalledWith(room1.roomId, client.matrixRTC.getActiveRoomSession(room1));
}); });
it("Calls onCallEncryption on encryption keys event", () => { it("Calls onCallEncryption on encryption keys event", async () => {
const room1 = makeMockRoom([membershipTemplate]); const room1 = makeMockRoom([membershipTemplate]);
jest.spyOn(client, "getRooms").mockReturnValue([room1]); jest.spyOn(client, "getRooms").mockReturnValue([room1]);
jest.spyOn(client, "getRoom").mockReturnValue(room1); jest.spyOn(client, "getRoom").mockReturnValue(room1);
@@ -95,7 +95,7 @@ describe("MatrixRTCSessionManager", () => {
client.emit(ClientEvent.Room, room1); client.emit(ClientEvent.Room, room1);
const onCallEncryptionMock = jest.fn(); const onCallEncryptionMock = jest.fn();
client.matrixRTC.getRoomSession(room1).onCallEncryption = onCallEncryptionMock; client.matrixRTC.getRoomSession(room1).onCallEncryption = onCallEncryptionMock;
client.decryptEventIfNeeded = () => Promise.resolve();
const timelineEvent = { const timelineEvent = {
getType: jest.fn().mockReturnValue(EventType.CallEncryptionKeysPrefix), getType: jest.fn().mockReturnValue(EventType.CallEncryptionKeysPrefix),
getContent: jest.fn().mockReturnValue({}), getContent: jest.fn().mockReturnValue({}),
@@ -106,6 +106,7 @@ describe("MatrixRTCSessionManager", () => {
}, },
} as unknown as MatrixEvent; } as unknown as MatrixEvent;
client.emit(RoomEvent.Timeline, timelineEvent, undefined, undefined, false, {} as IRoomTimelineData); client.emit(RoomEvent.Timeline, timelineEvent, undefined, undefined, false, {} as IRoomTimelineData);
await new Promise(process.nextTick);
expect(onCallEncryptionMock).toHaveBeenCalled(); expect(onCallEncryptionMock).toHaveBeenCalled();
}); });
}); });

View File

@@ -176,7 +176,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
} }
/** /**
* Return a the MatrixRTC for the room, whether there are currently active members or not * Return the MatrixRTC session for the room, whether there are currently active members or not
*/ */
public static roomSessionForRoom(client: MatrixClient, room: Room): MatrixRTCSession { public static roomSessionForRoom(client: MatrixClient, room: Room): MatrixRTCSession {
const callMemberships = MatrixRTCSession.callMembershipsForRoom(room); const callMemberships = MatrixRTCSession.callMembershipsForRoom(room);
@@ -506,7 +506,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
return; return;
} }
// We currently only handle callId = "" // We currently only handle callId = "" (which is the default for room scoped calls)
if (callId !== "") { if (callId !== "") {
logger.warn( logger.warn(
`Received m.call.encryption_keys with unsupported callId: userId=${userId}, deviceId=${deviceId}, callId=${callId}`, `Received m.call.encryption_keys with unsupported callId: userId=${userId}, deviceId=${deviceId}, callId=${callId}`,

View File

@@ -98,16 +98,20 @@ export class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionM
return this.roomSessions.get(room.roomId)!; return this.roomSessions.get(room.roomId)!;
} }
private onTimeline = (event: MatrixEvent): void => { private async consumeCallEncryptionEvent(event: MatrixEvent): Promise<void> {
if (event.getType() !== EventType.CallEncryptionKeysPrefix) return; await this.client.decryptEventIfNeeded(event);
if (event.getType() !== EventType.CallEncryptionKeysPrefix) return Promise.resolve();
const room = this.client.getRoom(event.getRoomId()); const room = this.client.getRoom(event.getRoomId());
if (!room) { if (!room) {
logger.error(`Got room state event for unknown room ${event.getRoomId()}!`); logger.error(`Got room state event for unknown room ${event.getRoomId()}!`);
return; return Promise.resolve();
} }
this.getRoomSession(room).onCallEncryption(event); this.getRoomSession(room).onCallEncryption(event);
}
private onTimeline = (event: MatrixEvent): void => {
this.consumeCallEncryptionEvent(event);
}; };
private onRoom = (room: Room): void => { private onRoom = (room: Room): void => {