diff --git a/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/agorachannel.js b/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/agorachannel.js index 429c91a0..2e235b4a 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,9 +280,8 @@ class AgoraChannel { if (this.client_role === 1 && this.videoEnabled) { await this.setupLocalVideoTrack(); if (localTracks.videoTrack != undefined) { - localTracks.videoTrack.play("local-player"); + await this.client.publish(localTracks.videoTrack); } - await this.client.publish(localTracks.videoTrack); this.is_publishing = true; } @@ -608,8 +607,14 @@ 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; @@ -629,16 +634,15 @@ class AgoraChannel { AgoraRTC.createCameraVideoTrack(), ]); localTracks.videoTrack.play("local-player"); - if (this.is_publishing) { - await this.client.publish(localTracks.videoTrack); - } + this.is_publishing = true; + 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 794701a8..8109d1f4 100644 --- a/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/clientmanager.js +++ b/Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/clientmanager.js @@ -435,34 +435,17 @@ class ClientManager { // Help function for JoinChannel async processJoinChannelAVTrack() { if (this.videoEnabled && this.isHosting()) { - [localTracks.videoTrack] = await Promise.all([ - AgoraRTC.createCameraVideoTrack(this._customVideoConfiguration) - ]); - currentVideoDevice = wrapper.getCameraDeviceIdFromDeviceName( - localTracks.videoTrack._deviceName - ); + await this.setupLocalVideoTrack(); } if (this.audioEnabled && this.isHosting()) { - [localTracks.audioTrack] = await Promise.all([ - AgoraRTC.createMicrophoneAudioTrack() - ]); - currentAudioDevice = wrapper.getMicrophoneDeviceIdFromDeviceName( - localTracks.audioTrack._deviceName - ); + await this.setupLocalAudioTrack(); } + 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) { @@ -474,6 +457,32 @@ 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); @@ -515,12 +524,22 @@ class ClientManager { // can still be on // if wanting both off, call disableLocalVideo async muteLocalVideoStream(mute) { - if (localTracks.videoTrack) { + if (this.client && !this.is_screensharing) { if (mute) { - await this.client.unpublish(localTracks.videoTrack); + if (localTracks.videoTrack) { + localTracks.videoTrack.stop(); + localTracks.videoTrack.close(); + await this.client.unpublish(localTracks.videoTrack); + } } else { - await this.client.publish(localTracks.videoTrack); + if (localTracks.videoTrack) { + await this.client.publish(localTracks.videoTrack); + } else { + await this.setupLocalVideoTrack(); + await this.client.publish(localTracks.videoTrack); + } } + this.videoEnabled = !mute; } } @@ -532,8 +551,12 @@ 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) { @@ -1003,4 +1026,4 @@ class ClientManager { event_manager.raiseOnClientVideoSizeChanged(uid, width, height); }); } -} +} \ No newline at end of file