@@ -435,34 +435,17 @@ class ClientManager {
435435 // Help function for JoinChannel
436436 async processJoinChannelAVTrack ( ) {
437437 if ( this . videoEnabled && this . isHosting ( ) ) {
438- [ localTracks . videoTrack ] = await Promise . all ( [
439- AgoraRTC . createCameraVideoTrack ( this . _customVideoConfiguration )
440- ] ) ;
441- currentVideoDevice = wrapper . getCameraDeviceIdFromDeviceName (
442- localTracks . videoTrack . _deviceName
443- ) ;
438+ await this . setupLocalVideoTrack ( ) ;
444439 }
445440
446441 if ( this . audioEnabled && this . isHosting ( ) ) {
447- [ localTracks . audioTrack ] = await Promise . all ( [
448- AgoraRTC . createMicrophoneAudioTrack ( )
449- ] ) ;
450- currentAudioDevice = wrapper . getMicrophoneDeviceIdFromDeviceName (
451- localTracks . audioTrack . _deviceName
452- ) ;
442+ await this . setupLocalAudioTrack ( ) ;
453443 }
444+
454445 event_manager . raiseGetCurrentVideoDevice ( ) ;
455446 event_manager . raiseGetCurrentAudioDevice ( ) ;
456447 event_manager . raiseGetCurrentPlayBackDevice ( ) ;
457448
458- // videoTrack exists implies videoEnabled
459- if ( localTracks . videoTrack ) {
460- localTracks . videoTrack . play ( "local-player" , {
461- fit : "cover" ,
462- mirror : mlocal ,
463- } ) ;
464- }
465-
466449 $ ( "#local-player-name" ) . text ( `localVideo(${ this . options . uid } )` ) ;
467450 if ( this . isHosting ( ) && this . _inChannel ) {
468451 for ( var trackName in localTracks ) {
@@ -474,6 +457,32 @@ class ClientManager {
474457 }
475458 }
476459
460+ async setupLocalVideoTrack ( ) {
461+ [ localTracks . videoTrack ] = await Promise . all ( [
462+ AgoraRTC . createCameraVideoTrack ( this . _customVideoConfiguration )
463+ ] ) ;
464+ currentVideoDevice = wrapper . getCameraDeviceIdFromDeviceName (
465+ localTracks . videoTrack . _deviceName
466+ ) ;
467+
468+ // videoTrack exists implies videoEnabled
469+ if ( localTracks . videoTrack ) {
470+ localTracks . videoTrack . play ( "local-player" , {
471+ fit : "cover" ,
472+ mirror : mlocal ,
473+ } ) ;
474+ }
475+ }
476+
477+ async setupLocalAudioTrack ( ) {
478+ [ localTracks . audioTrack ] = await Promise . all ( [
479+ AgoraRTC . createMicrophoneAudioTrack ( )
480+ ] ) ;
481+ currentAudioDevice = wrapper . getMicrophoneDeviceIdFromDeviceName (
482+ localTracks . audioTrack . _deviceName
483+ ) ;
484+ }
485+
477486 async setClientRole ( role , optionLevel ) {
478487 if ( this . client ) {
479488 var wasAudience = ( this . client_role == 2 ) ;
@@ -515,12 +524,22 @@ class ClientManager {
515524 // can still be on
516525 // if wanting both off, call disableLocalVideo
517526 async muteLocalVideoStream ( mute ) {
518- if ( localTracks . videoTrack ) {
527+ if ( this . client && ! this . is_screensharing ) {
519528 if ( mute ) {
520- await this . client . unpublish ( localTracks . videoTrack ) ;
529+ if ( localTracks . videoTrack ) {
530+ localTracks . videoTrack . stop ( ) ;
531+ localTracks . videoTrack . close ( ) ;
532+ await this . client . unpublish ( localTracks . videoTrack ) ;
533+ }
521534 } else {
522- await this . client . publish ( localTracks . videoTrack ) ;
535+ if ( localTracks . videoTrack ) {
536+ await this . client . publish ( localTracks . videoTrack ) ;
537+ } else {
538+ await this . setupLocalVideoTrack ( ) ;
539+ await this . client . publish ( localTracks . videoTrack ) ;
540+ }
523541 }
542+ this . videoEnabled = ! mute ;
524543 }
525544 }
526545
@@ -532,8 +551,12 @@ class ClientManager {
532551 } else {
533552 if ( localTracks . audioTrack ) {
534553 await this . client . publish ( localTracks . audioTrack ) ;
554+ } else {
555+ await this . setupLocalAudioTrack ( ) ;
556+ await this . client . publish ( localTracks . audioTrack ) ;
535557 }
536558 }
559+ this . audioEnabled = ! mute ;
537560 }
538561
539562 async enableLocalVideo ( enabled ) {
@@ -1003,4 +1026,4 @@ class ClientManager {
10031026 event_manager . raiseOnClientVideoSizeChanged ( uid , width , height ) ;
10041027 } ) ;
10051028 }
1006- }
1029+ }
0 commit comments