From 561e4f734e2b286e1c12cec6945986a4418805bc Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 18 May 2022 18:32:49 +0100 Subject: [PATCH] Handle other members having no e2e keys Fetch the device info once at the start of the cal and cache it rather than fetching every time, and throw if we're supposed to be using e2e but the other end has no e2e keys. --- src/webrtc/call.ts | 23 ++++++++++++++++++++--- src/webrtc/groupCall.ts | 24 ++++++++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index cbc6390d15..cfe94976d7 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -47,6 +47,7 @@ import { CallFeed } from './callFeed'; import { MatrixClient } from "../client"; import { ISendEventResponse } from "../@types/requests"; import { EventEmitterEvents, TypedEventEmitter } from "../models/typed-event-emitter"; +import { DeviceInfo } from '../crypto/deviceinfo'; // events: hangup, error(err), replaced(call), state(state, oldState) @@ -343,6 +344,7 @@ export class MatrixCall extends TypedEventEmitter !feed.isLocal()); } + private async initOpponentCrypto() { + if (!this.opponentDeviceId) return; + + const userId = this.invitee || this.getOpponentMember().userId; + const deviceInfoMap = await this.client.crypto.deviceList.downloadKeys([userId], false); + this.opponentDeviceInfo = deviceInfoMap[userId][this.opponentDeviceId]; + if (this.opponentDeviceInfo === undefined) { + throw new Error(`No keys found for opponent device ${this.opponentDeviceId}!`); + } + } + /** * Generates and returns localSDPStreamMetadata * @returns {SDPStreamMetadata} localSDPStreamMetadata @@ -792,6 +805,7 @@ export class MatrixCall extends TypedEventEmitter { + public onMemberStateChanged = async (event: MatrixEvent) => { // The member events may be received for another room, which we will ignore. if (event.getRoomId() !== this.room.roomId) { return; @@ -751,8 +752,23 @@ export class GroupCall extends TypedEventEmitter feed.purpose === SDPStreamMetadataPurpose.Screenshare); - // Safari can't send a MediaStream to multiple sources, so clone it - newCall.placeCallWithCallFeeds(this.getLocalFeeds().map(feed => feed.clone()), requestScreenshareFeed); + try { + // Safari can't send a MediaStream to multiple sources, so clone it + await newCall.placeCallWithCallFeeds( + this.getLocalFeeds().map(feed => feed.clone()), + requestScreenshareFeed, + ); + } catch (e) { + logger.warn(`Failed to place call to ${member.userId}!`, e); + this.emit( + GroupCallEvent.Error, + new GroupCallError( + GroupCallErrorCode.PlaceCallFailed, + `Failed to place call to ${member.userId}.`, + ), + ); + return; + } if (this.dataChannelsEnabled) { newCall.createDataChannel("datachannel", this.dataChannelOptions);