Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit unknown device errors for group call participants without e2e #2447

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { MatrixClient } from "../client";
import { ISendEventResponse } from "../@types/requests";
import { EventEmitterEvents, TypedEventEmitter } from "../models/typed-event-emitter";
import { DeviceInfo } from '../crypto/deviceinfo';
import { GroupCallUnknownDeviceError } from './groupCall';

// events: hangup, error(err), replaced(call), state(state, oldState)

Expand Down Expand Up @@ -521,7 +522,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
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}!`);
throw new GroupCallUnknownDeviceError(userId);
}
}

Expand Down
18 changes: 11 additions & 7 deletions src/webrtc/callEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CallDirection, CallErrorCode, CallState, createNewMatrixCall, MatrixCal
import { EventType } from '../@types/event';
import { ClientEvent, MatrixClient } from '../client';
import { MCallAnswer, MCallHangupReject } from "./callEventTypes";
import { GroupCallError, GroupCallErrorCode, GroupCallEvent } from './groupCall';
import { GroupCallErrorCode, GroupCallEvent, GroupCallUnknownDeviceError } from './groupCall';
import { RoomEvent } from "../models/room";

// Don't ring unless we'd be ringing for at least 3 seconds: the user needs some
Expand Down Expand Up @@ -210,8 +210,9 @@ export class CallEventHandler {

let opponentDeviceId: string | undefined;

let groupCall;
dbkr marked this conversation as resolved.
Show resolved Hide resolved
if (groupCallId) {
const groupCall = this.client.groupCallEventHandler.getGroupCallById(groupCallId);
groupCall = this.client.groupCallEventHandler.getGroupCallById(groupCallId);

if (!groupCall) {
logger.warn(`Cannot find a group call ${groupCallId} for event ${type}. Ignoring event.`);
Expand All @@ -224,10 +225,7 @@ export class CallEventHandler {
logger.warn(`Cannot find a device id for ${senderId}. Ignoring event.`);
groupCall.emit(
GroupCallEvent.Error,
new GroupCallError(
GroupCallErrorCode.UnknownDevice,
`Incoming Call: No opponent device found for ${senderId}, ignoring.`,
),
new GroupCallUnknownDeviceError(senderId),
);
return;
}
Expand Down Expand Up @@ -282,7 +280,13 @@ export class CallEventHandler {
}

call.callId = content.call_id;
await call.initWithInvite(event);
try {
await call.initWithInvite(event);
} catch (e) {
if (e.code === GroupCallErrorCode.UnknownDevice) {
groupCall?.emit(GroupCallEvent.Error, e);
}
}
this.calls.set(call.callId, call);

// if we stashed candidate events for that call ID, play them back now
Expand Down
31 changes: 19 additions & 12 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export enum GroupCallEvent {
LocalScreenshareStateChanged = "local_screenshare_state_changed",
LocalMuteStateChanged = "local_mute_state_changed",
ParticipantsChanged = "participants_changed",
Error = "error"
Error = "error",
}

export type GroupCallEventHandlerMap = {
Expand Down Expand Up @@ -77,6 +77,12 @@ export class GroupCallError extends Error {
}
}

export class GroupCallUnknownDeviceError extends GroupCallError {
constructor(public userId: string) {
super(GroupCallErrorCode.UnknownDevice, "No device found for " + userId);
}
}

export class OtherUserSpeakingError extends Error {
constructor() {
super("Cannot unmute: another user is speaking");
Expand Down Expand Up @@ -750,10 +756,7 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
logger.warn(`No opponent device found for ${member.userId}, ignoring.`);
this.emit(
GroupCallEvent.Error,
new GroupCallError(
GroupCallErrorCode.UnknownDevice,
`Outgoing Call: No opponent device found for ${member.userId}, ignoring.`,
),
new GroupCallUnknownDeviceError(member.userId),
);
return;
}
Expand Down Expand Up @@ -791,13 +794,17 @@ export class GroupCall extends TypedEventEmitter<GroupCallEvent, GroupCallEventH
);
} 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}.`,
),
);
if (e.code === GroupCallErrorCode.UnknownDevice) {
this.emit(GroupCallEvent.Error, e);
} else {
this.emit(
GroupCallEvent.Error,
new GroupCallError(
GroupCallErrorCode.PlaceCallFailed,
`Failed to place call to ${member.userId}.`,
),
);
}
return;
}

Expand Down