diff --git a/spec/unit/matrixrtc/MatrixRTCSessionManager.spec.ts b/spec/unit/matrixrtc/MatrixRTCSessionManager.spec.ts index 8784ab48b48..f5ffc13e05b 100644 --- a/spec/unit/matrixrtc/MatrixRTCSessionManager.spec.ts +++ b/spec/unit/matrixrtc/MatrixRTCSessionManager.spec.ts @@ -87,7 +87,7 @@ describe("MatrixRTCSessionManager", () => { 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]); jest.spyOn(client, "getRooms").mockReturnValue([room1]); jest.spyOn(client, "getRoom").mockReturnValue(room1); @@ -95,7 +95,7 @@ describe("MatrixRTCSessionManager", () => { client.emit(ClientEvent.Room, room1); const onCallEncryptionMock = jest.fn(); client.matrixRTC.getRoomSession(room1).onCallEncryption = onCallEncryptionMock; - + client.decryptEventIfNeeded = () => Promise.resolve(); const timelineEvent = { getType: jest.fn().mockReturnValue(EventType.CallEncryptionKeysPrefix), getContent: jest.fn().mockReturnValue({}), @@ -106,6 +106,7 @@ describe("MatrixRTCSessionManager", () => { }, } as unknown as MatrixEvent; client.emit(RoomEvent.Timeline, timelineEvent, undefined, undefined, false, {} as IRoomTimelineData); + await new Promise(process.nextTick); expect(onCallEncryptionMock).toHaveBeenCalled(); }); }); diff --git a/src/matrixrtc/MatrixRTCSession.ts b/src/matrixrtc/MatrixRTCSession.ts index b8ee6626fd0..403fd248f65 100644 --- a/src/matrixrtc/MatrixRTCSession.ts +++ b/src/matrixrtc/MatrixRTCSession.ts @@ -176,7 +176,7 @@ export class MatrixRTCSession extends TypedEventEmitter { - if (event.getType() !== EventType.CallEncryptionKeysPrefix) return; + private async consumeCallEncryptionEvent(event: MatrixEvent): Promise { + await this.client.decryptEventIfNeeded(event); + if (event.getType() !== EventType.CallEncryptionKeysPrefix) return Promise.resolve(); const room = this.client.getRoom(event.getRoomId()); if (!room) { logger.error(`Got room state event for unknown room ${event.getRoomId()}!`); - return; + return Promise.resolve(); } this.getRoomSession(room).onCallEncryption(event); + } + private onTimeline = (event: MatrixEvent): void => { + this.consumeCallEncryptionEvent(event); }; private onRoom = (room: Room): void => {