From 0f6a59ed98336f622ff8445e159b215de419c0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 25 Sep 2021 09:54:14 +0200 Subject: [PATCH] Allow answering calls without audio/video MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/call.ts | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 68a003dc3..181fd39ec 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -696,13 +696,34 @@ export class MatrixCall extends EventEmitter { this.setState(CallState.Ended); } + private shouldAnswerWithMediaType( + wantedValue: boolean, valueOfTheOtherSide: boolean, type: "audio" | "video", + ): boolean { + if (wantedValue && !valueOfTheOtherSide) { + // TODO: Figure out how to do this + logger.warn(`Unable to answer with ${type} because the other side isn't sending it either.`); + return false; + } else if ( + !utils.isNullOrUndefined(wantedValue) && + wantedValue !== valueOfTheOtherSide && + !this.opponentSupportsSDPStreamMetadata() + ) { + logger.warn( + `Unable to answer with ${type}=${wantedValue} because the other side doesn't support it. ` + + `Answering with ${type}=${valueOfTheOtherSide}.`, + ); + return valueOfTheOtherSide; + } + return wantedValue ?? valueOfTheOtherSide; + } + /** * Answer a call. */ - public async answer(): Promise { - if (this.inviteOrAnswerSent) { - return; - } + public async answer(audio?: boolean, video?: boolean): Promise { + if (this.inviteOrAnswerSent) return; + // TODO: Figure out how to do this + if (audio === false && video === false) throw new Error("You CANNOT answer a call without media"); logger.debug(`Answering call ${this.callId}`); @@ -712,8 +733,8 @@ export class MatrixCall extends EventEmitter { try { const mediaStream = await this.client.getMediaHandler().getUserMediaStream( - true, - this.hasRemoteUserMediaVideoTrack, + this.shouldAnswerWithMediaType(audio, this.hasRemoteUserMediaAudioTrack, "audio"), + this.shouldAnswerWithMediaType(video, this.hasRemoteUserMediaVideoTrack, "video"), ); this.waitForLocalAVStream = false; this.gotUserMediaForAnswer(mediaStream);