@@ -435,17 +435,34 @@ class ClientManager {
435435 // Help function for JoinChannel
436436 async processJoinChannelAVTrack ( ) {
437437 if ( this . videoEnabled && this . isHosting ( ) ) {
438- await this . setupLocalVideoTrack ( ) ;
438+ [ localTracks . videoTrack ] = await Promise . all ( [
439+ AgoraRTC . createCameraVideoTrack ( this . _customVideoConfiguration )
440+ ] ) ;
441+ currentVideoDevice = wrapper . getCameraDeviceIdFromDeviceName (
442+ localTracks . videoTrack . _deviceName
443+ ) ;
439444 }
440445
441446 if ( this . audioEnabled && this . isHosting ( ) ) {
442- await this . setupLocalAudioTrack ( ) ;
447+ [ localTracks . audioTrack ] = await Promise . all ( [
448+ AgoraRTC . createMicrophoneAudioTrack ( )
449+ ] ) ;
450+ currentAudioDevice = wrapper . getMicrophoneDeviceIdFromDeviceName (
451+ localTracks . audioTrack . _deviceName
452+ ) ;
443453 }
444-
445454 event_manager . raiseGetCurrentVideoDevice ( ) ;
446455 event_manager . raiseGetCurrentAudioDevice ( ) ;
447456 event_manager . raiseGetCurrentPlayBackDevice ( ) ;
448457
458+ // videoTrack exists implies videoEnabled
459+ if ( localTracks . videoTrack ) {
460+ localTracks . videoTrack . play ( "local-player" , {
461+ fit : "cover" ,
462+ mirror : mlocal ,
463+ } ) ;
464+ }
465+
449466 $ ( "#local-player-name" ) . text ( `localVideo(${ this . options . uid } )` ) ;
450467 if ( this . isHosting ( ) && this . _inChannel ) {
451468 for ( var trackName in localTracks ) {
@@ -457,32 +474,6 @@ class ClientManager {
457474 }
458475 }
459476
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-
486477 async setClientRole ( role , optionLevel ) {
487478 if ( this . client ) {
488479 var wasAudience = ( this . client_role == 2 ) ;
@@ -524,22 +515,12 @@ class ClientManager {
524515 // can still be on
525516 // if wanting both off, call disableLocalVideo
526517 async muteLocalVideoStream ( mute ) {
527- if ( this . client && ! this . is_screensharing ) {
518+ if ( localTracks . videoTrack ) {
528519 if ( mute ) {
529- if ( localTracks . videoTrack ) {
530- localTracks . videoTrack . stop ( ) ;
531- localTracks . videoTrack . close ( ) ;
532- await this . client . unpublish ( localTracks . videoTrack ) ;
533- }
520+ await this . client . unpublish ( localTracks . videoTrack ) ;
534521 } else {
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- }
522+ await this . client . publish ( localTracks . videoTrack ) ;
541523 }
542- this . videoEnabled = ! mute ;
543524 }
544525 }
545526
@@ -551,12 +532,8 @@ class ClientManager {
551532 } else {
552533 if ( localTracks . audioTrack ) {
553534 await this . client . publish ( localTracks . audioTrack ) ;
554- } else {
555- await this . setupLocalAudioTrack ( ) ;
556- await this . client . publish ( localTracks . audioTrack ) ;
557535 }
558536 }
559- this . audioEnabled = ! mute ;
560537 }
561538
562539 async enableLocalVideo ( enabled ) {
@@ -1026,4 +1003,4 @@ class ClientManager {
10261003 event_manager . raiseOnClientVideoSizeChanged ( uid , width , height ) ;
10271004 } ) ;
10281005 }
1029- }
1006+ }
0 commit comments