@@ -24,6 +24,7 @@ import { CallEventHandlerEvent } from "./callEventHandler";
24
24
import { GroupCallEventHandlerEvent } from "./groupCallEventHandler" ;
25
25
import { IScreensharingOpts } from "./mediaHandler" ;
26
26
import { mapsEqual } from "../utils" ;
27
+ import { windows } from "rimraf" ;
27
28
28
29
export enum GroupCallIntent {
29
30
Ring = "m.ring" ,
@@ -553,7 +554,17 @@ export class GroupCall extends TypedEventEmitter<
553
554
// hasAudioDevice can block indefinitely if the window has lost focus,
554
555
// and it doesn't make much sense to keep a device from being muted, so
555
556
// 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 ) {
557
568
return false ;
558
569
}
559
570
@@ -592,6 +603,22 @@ export class GroupCall extends TypedEventEmitter<
592
603
logger . log (
593
604
`GroupCall ${ this . groupCallId } setMicrophoneMuted() (streamId=${ this . localCallFeed . stream . id } , muted=${ muted } )` ,
594
605
) ;
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
+
595
622
this . localCallFeed . setAudioVideoMuted ( muted , null ) ;
596
623
// I don't believe its actually necessary to enable these tracks: they
597
624
// are the one on the GroupCall's own CallFeed and are cloned before being
@@ -617,15 +644,20 @@ export class GroupCall extends TypedEventEmitter<
617
644
* @returns Whether muting/unmuting was successful
618
645
*/
619
646
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
- }
625
647
// hasAudioDevice can block indefinitely if the window has lost focus,
626
648
// and it doesn't make much sense to keep a device from being muted, so
627
649
// 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 ) {
629
661
return false ;
630
662
}
631
663
@@ -634,7 +666,17 @@ export class GroupCall extends TypedEventEmitter<
634
666
`GroupCall ${ this . groupCallId } setLocalVideoMuted() (stream=${ this . localCallFeed . stream . id } , muted=${ muted } )` ,
635
667
) ;
636
668
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
+ }
638
680
await this . updateLocalUsermediaStream ( stream ) ;
639
681
this . localCallFeed . setAudioVideoMuted ( null , muted ) ;
640
682
setTracksEnabled ( this . localCallFeed . stream . getVideoTracks ( ) , ! muted ) ;
0 commit comments