Skip to content

Commit 9880a2e

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

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

src/webrtc/groupCall.ts

+49-8
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,17 @@ export class GroupCall extends TypedEventEmitter<
553553
// hasAudioDevice can block indefinitely if the window has lost focus,
554554
// and it doesn't make much sense to keep a device from being muted, so
555555
// we always allow muted = true changes to go through
556-
if (!muted && !(await this.client.getMediaHandler().hasAudioDevice())) {
556+
const hasAudioDevice = await this.client
557+
.getMediaHandler()
558+
.hasAudioDevice()
559+
.catch((_) => {
560+
logger.log(
561+
`GroupCall ${this.groupCallId} setMicrophoneMuted() no audio device or permission for audio device, muted=${muted}`,
562+
);
563+
return false;
564+
});
565+
566+
if (!muted && !hasAudioDevice) {
557567
return false;
558568
}
559569

@@ -592,6 +602,22 @@ export class GroupCall extends TypedEventEmitter<
592602
logger.log(
593603
`GroupCall ${this.groupCallId} setMicrophoneMuted() (streamId=${this.localCallFeed.stream.id}, muted=${muted})`,
594604
);
605+
606+
// We needed this here to avoid an error in case user join a call without a device.
607+
if (!muted) {
608+
const stream = await this.client
609+
.getMediaHandler()
610+
.getUserMediaStream(true, !this.localCallFeed.isVideoMuted())
611+
.catch((_) => null);
612+
if (stream === null) {
613+
// if case permission denied to get a stream stop this here
614+
logger.log(
615+
`GroupCall ${this.groupCallId} setMicrophoneMuted() no device or permission to receive local stream, muted=${muted}`,
616+
);
617+
return false;
618+
}
619+
}
620+
595621
this.localCallFeed.setAudioVideoMuted(muted, null);
596622
// I don't believe its actually necessary to enable these tracks: they
597623
// are the one on the GroupCall's own CallFeed and are cloned before being
@@ -617,15 +643,20 @@ export class GroupCall extends TypedEventEmitter<
617643
* @returns Whether muting/unmuting was successful
618644
*/
619645
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-
}
625646
// hasAudioDevice can block indefinitely if the window has lost focus,
626647
// and it doesn't make much sense to keep a device from being muted, so
627648
// we always allow muted = true changes to go through
628-
if (!muted && !(await this.client.getMediaHandler().hasVideoDevice())) {
649+
const hasVideoDevice = await this.client
650+
.getMediaHandler()
651+
.hasVideoDevice()
652+
.catch((_) => {
653+
logger.log(
654+
`GroupCall ${this.groupCallId} setLocalVideoMuted() no video device or permission for video device, muted=${muted}`,
655+
);
656+
return false;
657+
});
658+
659+
if (!muted && !hasVideoDevice) {
629660
return false;
630661
}
631662

@@ -634,7 +665,17 @@ export class GroupCall extends TypedEventEmitter<
634665
`GroupCall ${this.groupCallId} setLocalVideoMuted() (stream=${this.localCallFeed.stream.id}, muted=${muted})`,
635666
);
636667

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

0 commit comments

Comments
 (0)