diff --git a/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/agorachannel.js b/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/agorachannel.js index 2e235b4a..429c91a0 100644 --- a/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/agorachannel.js +++ b/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/agorachannel.js @@ -206,7 +206,7 @@ class AgoraChannel { const vad = 0; const channel_str = this.channelId; result.forEach(function (volume, index) { - //console.log(`${index} UID ${volume.uid} Level ${volume.level}`); + console.log(`${index} UID ${volume.uid} Level ${volume.level}`); if (volume.level > total) { total = volume.level; @@ -280,8 +280,9 @@ class AgoraChannel { if (this.client_role === 1 && this.videoEnabled) { await this.setupLocalVideoTrack(); if (localTracks.videoTrack != undefined) { - await this.client.publish(localTracks.videoTrack); + localTracks.videoTrack.play("local-player"); } + await this.client.publish(localTracks.videoTrack); this.is_publishing = true; } @@ -607,14 +608,8 @@ class AgoraChannel { await this.client.unpublish(localTracks.audioTrack); } } else { - if(localTracks.audioTrack) { + if (localTracks.audioTrack) { await this.client.publish(localTracks.audioTrack); - } else { - await this.setupLocalAudioTrack(); - if (localTracks.audioTrack != undefined) { - await this.client.publish(localTracks.audioTrack); - } - this.is_publishing = true; } } this.audioEnabled = !mute; @@ -634,15 +629,16 @@ class AgoraChannel { AgoraRTC.createCameraVideoTrack(), ]); localTracks.videoTrack.play("local-player"); - this.is_publishing = true; - await this.client.publish(localTracks.videoTrack); + if (this.is_publishing) { + await this.client.publish(localTracks.videoTrack); + } } this.videoEnabled = !mute; } } - muteRemoteAudioStream(uid, mute) { Object.keys(this.remoteUsers).forEach((uid2) => { + if (uid2 == uid) { if (mute == true) { this.unsubscribe(this.remoteUsers[uid], "audio"); diff --git a/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/clientmanager.js b/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/clientmanager.js index 8109d1f4..794701a8 100644 --- a/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/clientmanager.js +++ b/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/clientmanager.js @@ -435,17 +435,34 @@ class ClientManager { // Help function for JoinChannel async processJoinChannelAVTrack() { if (this.videoEnabled && this.isHosting()) { - await this.setupLocalVideoTrack(); + [localTracks.videoTrack] = await Promise.all([ + AgoraRTC.createCameraVideoTrack(this._customVideoConfiguration) + ]); + currentVideoDevice = wrapper.getCameraDeviceIdFromDeviceName( + localTracks.videoTrack._deviceName + ); } if (this.audioEnabled && this.isHosting()) { - await this.setupLocalAudioTrack(); + [localTracks.audioTrack] = await Promise.all([ + AgoraRTC.createMicrophoneAudioTrack() + ]); + currentAudioDevice = wrapper.getMicrophoneDeviceIdFromDeviceName( + localTracks.audioTrack._deviceName + ); } - event_manager.raiseGetCurrentVideoDevice(); event_manager.raiseGetCurrentAudioDevice(); event_manager.raiseGetCurrentPlayBackDevice(); + // videoTrack exists implies videoEnabled + if (localTracks.videoTrack) { + localTracks.videoTrack.play("local-player", { + fit: "cover", + mirror: mlocal, + }); + } + $("#local-player-name").text(`localVideo(${this.options.uid})`); if (this.isHosting() && this._inChannel) { for (var trackName in localTracks) { @@ -457,32 +474,6 @@ class ClientManager { } } - async setupLocalVideoTrack(){ - [localTracks.videoTrack] = await Promise.all([ - AgoraRTC.createCameraVideoTrack(this._customVideoConfiguration) - ]); - currentVideoDevice = wrapper.getCameraDeviceIdFromDeviceName( - localTracks.videoTrack._deviceName - ); - - // videoTrack exists implies videoEnabled - if (localTracks.videoTrack) { - localTracks.videoTrack.play("local-player", { - fit: "cover", - mirror: mlocal, - }); - } - } - - async setupLocalAudioTrack(){ - [localTracks.audioTrack] = await Promise.all([ - AgoraRTC.createMicrophoneAudioTrack() - ]); - currentAudioDevice = wrapper.getMicrophoneDeviceIdFromDeviceName( - localTracks.audioTrack._deviceName - ); - } - async setClientRole(role, optionLevel) { if (this.client) { var wasAudience = (this.client_role == 2); @@ -524,22 +515,12 @@ class ClientManager { // can still be on // if wanting both off, call disableLocalVideo async muteLocalVideoStream(mute) { - if (this.client && !this.is_screensharing) { + if (localTracks.videoTrack) { if (mute) { - if (localTracks.videoTrack) { - localTracks.videoTrack.stop(); - localTracks.videoTrack.close(); - await this.client.unpublish(localTracks.videoTrack); - } + await this.client.unpublish(localTracks.videoTrack); } else { - if (localTracks.videoTrack) { - await this.client.publish(localTracks.videoTrack); - } else { - await this.setupLocalVideoTrack(); - await this.client.publish(localTracks.videoTrack); - } + await this.client.publish(localTracks.videoTrack); } - this.videoEnabled = !mute; } } @@ -551,12 +532,8 @@ class ClientManager { } else { if (localTracks.audioTrack) { await this.client.publish(localTracks.audioTrack); - } else { - await this.setupLocalAudioTrack(); - await this.client.publish(localTracks.audioTrack); } } - this.audioEnabled = !mute; } async enableLocalVideo(enabled) { @@ -1026,4 +1003,4 @@ class ClientManager { event_manager.raiseOnClientVideoSizeChanged(uid, width, height); }); } -} \ No newline at end of file +}