Skip to content

Commit 3775e7f

Browse files
author
Enrico Schwendig
committed
groupCall: mute unmute even without device
1 parent 1cad2d7 commit 3775e7f

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

src/webrtc/groupCall.ts

+50-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { CallEventHandlerEvent } from "./callEventHandler";
2424
import { GroupCallEventHandlerEvent } from "./groupCallEventHandler";
2525
import { IScreensharingOpts } from "./mediaHandler";
2626
import { mapsEqual } from "../utils";
27+
import { windows } from "rimraf";
2728

2829
export enum GroupCallIntent {
2930
Ring = "m.ring",
@@ -553,7 +554,17 @@ export class GroupCall extends TypedEventEmitter<
553554
// hasAudioDevice can block indefinitely if the window has lost focus,
554555
// and it doesn't make much sense to keep a device from being muted, so
555556
// we always allow muted = true changes to go through
556-
if (!muted && !(await this.client.getMediaHandler().hasAudioDevice())) {
557+
const hasAudioDevice = await this.client
558+
.getMediaHandler()
559+
.hasAudioDevice()
560+
.catch((_) => {
561+
logger.log(
562+
`GroupCall ${this.groupCallId} setMicrophoneMuted() no audio device or permission for audio device, muted=${muted}`,
563+
);
564+
return false;
565+
});
566+
567+
if (!muted && !hasAudioDevice) {
557568
return false;
558569
}
559570

@@ -592,6 +603,22 @@ export class GroupCall extends TypedEventEmitter<
592603
logger.log(
593604
`GroupCall ${this.groupCallId} setMicrophoneMuted() (streamId=${this.localCallFeed.stream.id}, muted=${muted})`,
594605
);
606+
607+
// We needed this here to avoid an error in case user join a call without a device.
608+
if (!muted) {
609+
const stream = await this.client
610+
.getMediaHandler()
611+
.getUserMediaStream(true, !this.localCallFeed.isVideoMuted())
612+
.catch((_) => null);
613+
if (stream === null) {
614+
// if case permission denied to get a stream stop this here
615+
logger.log(
616+
`GroupCall ${this.groupCallId} setMicrophoneMuted() no device or permission to receive local stream, muted=${muted}`,
617+
);
618+
return false;
619+
}
620+
}
621+
595622
this.localCallFeed.setAudioVideoMuted(muted, null);
596623
// I don't believe its actually necessary to enable these tracks: they
597624
// are the one on the GroupCall's own CallFeed and are cloned before being
@@ -617,15 +644,20 @@ export class GroupCall extends TypedEventEmitter<
617644
* @returns Whether muting/unmuting was successful
618645
*/
619646
public async setLocalVideoMuted(muted: boolean): Promise<boolean> {
620-
// Because we need a Local Call Feed to establish a call connection, we avoid muting video in case of empty
621-
// video track. In this way we go sure if a client implements muting we don't raise an error.
622-
if (this.localCallFeed?.stream.getVideoTracks().length === 0) {
623-
return false;
624-
}
625647
// hasAudioDevice can block indefinitely if the window has lost focus,
626648
// and it doesn't make much sense to keep a device from being muted, so
627649
// we always allow muted = true changes to go through
628-
if (!muted && !(await this.client.getMediaHandler().hasVideoDevice())) {
650+
const hasVideoDevice = await this.client
651+
.getMediaHandler()
652+
.hasVideoDevice()
653+
.catch((_) => {
654+
logger.log(
655+
`GroupCall ${this.groupCallId} setLocalVideoMuted() no video device or permission for video device, muted=${muted}`,
656+
);
657+
return false;
658+
});
659+
660+
if (!muted && !hasVideoDevice) {
629661
return false;
630662
}
631663

@@ -634,7 +666,17 @@ export class GroupCall extends TypedEventEmitter<
634666
`GroupCall ${this.groupCallId} setLocalVideoMuted() (stream=${this.localCallFeed.stream.id}, muted=${muted})`,
635667
);
636668

637-
const stream = await this.client.getMediaHandler().getUserMediaStream(true, !muted);
669+
const stream = await this.client
670+
.getMediaHandler()
671+
.getUserMediaStream(true, !muted)
672+
.catch((_) => null);
673+
if (stream === null) {
674+
// if case permission denied to get a stream stop this here
675+
logger.log(
676+
`GroupCall ${this.groupCallId} setLocalVideoMuted() no device or permission to receive local stream, muted=${muted}`,
677+
);
678+
return false;
679+
}
638680
await this.updateLocalUsermediaStream(stream);
639681
this.localCallFeed.setAudioVideoMuted(null, muted);
640682
setTracksEnabled(this.localCallFeed.stream.getVideoTracks(), !muted);

0 commit comments

Comments
 (0)