Skip to content

Commit 717d74d

Browse files
authored
Merge pull request #289 from nathanGroovy/Issue_285#_new
Issue 285# new
2 parents ce5ecd5 + d2ebcd7 commit 717d74d

File tree

6 files changed

+124
-52
lines changed

6 files changed

+124
-52
lines changed

Assets/AgoraEngine/Plugins/WebGL/AgoraWebGLSDK.jslib

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,9 +1637,17 @@ muteLocalVideoStream_channel: function(channel, mute) {
16371637
var str_chan = UTF8ToString(channel);
16381638
muteLocalVideoStream2_mc_WGL(str_chan, mute);
16391639
},
1640+
enableLocalVideoStream_channel: function(channel, mute) {
1641+
var str_chan = UTF8ToString(channel);
1642+
enableLocalVideoStream2_mc_WGL(str_chan, mute);
1643+
},
16401644
muteLocalAudioStream_channel: function(channel, mute) {
16411645
var str_chan = UTF8ToString(channel);
16421646
muteLocalAudioStream2_mc_WGL(str_chan, mute);
1647+
},
1648+
enableLocalAudioStream_channel: function(channel, mute) {
1649+
var str_chan = UTF8ToString(channel);
1650+
enableLocalAudioStream2_mc_WGL(str_chan, mute);
16431651
},
16441652
joinChannelWithUserAccount2: function (
16451653
channel,

Assets/AgoraEngine/Scripts/AgoraGamingSDK/AgoraChannel.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,19 @@ public int MuteLocalVideoStream(bool mute)
17331733
if (_rtcEngine == null)
17341734
return (int)ERROR_CODE.ERROR_NOT_INIT_ENGINE;
17351735

1736+
#if !UNITY_EDITOR && UNITY_WEBGL
1737+
return IRtcEngineNative.muteLocalVideoStream_channel(_channelId, mute);
1738+
#else
1739+
return IRtcEngineNative.muteLocalVideoStream_channel(_channelHandler, mute);
1740+
#endif
1741+
1742+
}
1743+
1744+
public int EnableLocalVideoStream(bool mute)
1745+
{
1746+
if (_rtcEngine == null)
1747+
return (int)ERROR_CODE.ERROR_NOT_INIT_ENGINE;
1748+
17361749
#if !UNITY_EDITOR && UNITY_WEBGL
17371750
return IRtcEngineNative.muteLocalVideoStream_channel(_channelId, mute);
17381751
#else
@@ -1770,6 +1783,18 @@ public int MuteLocalAudioStream(bool mute)
17701783
#endif
17711784
}
17721785

1786+
public int EnableLocalAudioStream(bool mute)
1787+
{
1788+
if (_rtcEngine == null)
1789+
return (int)ERROR_CODE.ERROR_NOT_INIT_ENGINE;
1790+
1791+
#if !UNITY_EDITOR && UNITY_WEBGL
1792+
return IRtcEngineNative.enableLocalAudioStream_channel(_channelId, mute);
1793+
#else
1794+
return IRtcEngineNative.enableLocalAudioStream_channel(_channelHandler, mute);
1795+
#endif
1796+
}
1797+
17731798
/** Enables/Disables the super-resolution algorithm for a remote user's video stream.
17741799
*
17751800
* @deprecated This method is deprecated from v3.7.1. Use {@link EnableRemoteSuperResolution(bool enabled, SR_MODE mode, uint userId) EnableRemoteSuperResolution [2/2]} instead.

Assets/AgoraEngine/Scripts/AgoraGamingSDK/native/IAgoraGamingRtcEngineNative.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,18 +1401,31 @@ protected static extern void initChannelEventCallback(IntPtr channel, ChannelOnW
14011401
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
14021402
protected static extern int setLocalAccessPoint(string ips, int ipSize, string domainList, int domainListSize, string verifyDomainName, int mode, string serverDomain, string serverPath, int serverPort, bool serverHttps);
14031403

1404+
14041405
#if !UNITY_EDITOR && UNITY_WEBGL
14051406
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
14061407
protected static extern int muteLocalAudioStream_channel(string channel, bool mute);
14071408

1409+
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
1410+
protected static extern int enableLocalAudioStream_channel(string channel, bool mute);
1411+
14081412
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
14091413
protected static extern int muteLocalVideoStream_channel(string channel, bool mute);
1414+
1415+
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
1416+
protected static extern int enableLocalVideoStream_channel(string channel, bool mute);
14101417
#else
14111418
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
14121419
protected static extern int muteLocalAudioStream_channel(IntPtr channel, bool mute);
14131420

1421+
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
1422+
protected static extern int enableLocalAudioStream_channel(IntPtr channel, bool mute);
1423+
14141424
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
14151425
protected static extern int muteLocalVideoStream_channel(IntPtr channel, bool mute);
1426+
1427+
[DllImport(MyLibName, CharSet = CharSet.Ansi)]
1428+
protected static extern int enableLocalVideoStream_channel(IntPtr channel, bool mute);
14161429
#endif
14171430

14181431
#if UNITY_WEBGL

Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/agorachannel.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -668,37 +668,52 @@ class AgoraChannel {
668668

669669
// Must/Unmute local audio (mic)
670670
async muteLocalAudioStream(mute) {
671-
if (mute) {
672-
if (localTracks.audioTrack) {
673-
await this.client.unpublish(localTracks.audioTrack);
674-
}
675-
} else {
676-
if (localTracks.audioTrack) {
677-
await this.client.publish(localTracks.audioTrack);
678-
}
671+
var muted = mute == 1 ? true : false;
672+
if (localTracks.audioTrack) {
673+
await localTracks.audioTrack.setMuted(muted);
679674
}
680-
this.audioEnabled = !mute;
675+
676+
this.audioEnabled = !muted;
681677
}
682678

683679
// Stops/Resumes sending the local video stream.
684680
async muteLocalVideoStream(mute) {
681+
var muted = mute == 1 ? true : false;
685682
if (this.client && !this.is_screensharing) {
686-
if (mute) {
687-
if (localTracks.videoTrack) {
688-
await localTracks.videoTrack.setMuted(true);
689-
}
690-
691-
} else {
692-
693-
if (localTracks.videoTrack) {
694-
await localTracks.videoTrack.setMuted(false);
695-
}
683+
if (localTracks.videoTrack) {
684+
await localTracks.videoTrack.setMuted(muted);
685+
}
696686

697-
await localTracks.videoTrack.setMuted(false);
687+
}
688+
this.videoEnabled = !muted;
689+
}
690+
691+
async enableLocalVideo(enabled) {
692+
var enable = enabled == 1 ? true : false;
693+
console.log("EnableLocalVideo (agoraChannel):" + enable);
694+
if (this.client) {
695+
696+
if(localTracks.videoTrack != null){
697+
localTracks.videoTrack.setEnabled(enable);
698698
}
699-
this.videoEnabled = !mute;
699+
700700
}
701+
this.videoEnabled = enable;
701702
}
703+
704+
async enableLocalAudio(enabled) {
705+
var enable = enabled == 1 ? true : false;
706+
console.log("EnableLocalVideo (agoraChannel):" + enable);
707+
if (this.client) {
708+
709+
if(localTracks.audioTrack != null){
710+
localTracks.audioTrack.setEnabled(enable);
711+
}
712+
713+
}
714+
this.audioEnabled = enable;
715+
}
716+
702717
muteRemoteAudioStream(uid, mute) {
703718
Object.keys(this.remoteUsers).forEach((uid2) => {
704719

Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/clientmanager.js

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ClientManager {
2020
this._inChannel = false;
2121
this._streamMessageRetry = false;
2222
this.is_screensharing = false;
23-
this.tempLocalTracks = null;
23+
this.tempLocalTracks = {videoTrack: null, audioTrack: null};
2424
this.previewVideoTrack;
2525
this.enableLoopbackAudio = false;
2626
this.virtualBackgroundProcessor = null;
@@ -587,19 +587,8 @@ class ClientManager {
587587
this.audioSubscribing = enabled;
588588
}
589589

590-
// Disables/Re-enables the local audio function.
591-
async enableLocalAudio(enabled) {
592-
if (enabled == false) {
593-
if (localTracks.audioTrack) {
594-
localTracks.audioTrack.setVolume(0);
595-
}
596-
} else {
597-
if (localTracks.audioTrack) {
598-
localTracks.audioTrack.setVolume(100);
599-
}
600-
}
601-
this.audioEnabled = enabled;
602-
}
590+
591+
603592

604593
// mutes the video stream by calling setMuted in the video track.
605594
// if mute is equal to true, then the videoTrack will be muted
@@ -609,36 +598,44 @@ class ClientManager {
609598
if(localTracks.videoTrack != undefined){
610599
await localTracks.videoTrack.setMuted(mute);
611600
}
612-
console.log(localTracks.videoTrack.muted, mute);
601+
613602
this.videoPublishing = !mute;
614603
}
615604

616605
async muteLocalAudioStream(mute) {
617-
if (mute) {
618-
if (localTracks.audioTrack) {
619-
await this.client.unpublish(localTracks.audioTrack);
620-
}
621-
} else {
606+
var muted = mute == 1 ? true : false;
622607
if (localTracks.audioTrack) {
623-
await this.client.publish(localTracks.audioTrack);
608+
await localTracks.audioTrack.setMuted(muted);
624609
}
625-
}
610+
626611
this.audioPublishing = !mute;
627612
}
628613

629614
async enableLocalVideo(enabled) {
630-
console.log("EnableLocalVideo (clientManager):" + enabled);
615+
var enable = enabled == 1 ? true : false;
616+
console.log("EnableLocalVideo (clientManager):" + enable);
631617
if (this.client) {
632-
if (enabled == false) {
633618

634-
if(localTracks.videoTrack != null){
635-
await this.client.unpublish(localTracks.videoTrack);
636-
localTracks.videoTrack?.stop();
637-
localTracks.videoTrack?.close();
638-
}
639-
}
619+
if(localTracks.videoTrack != null){
620+
localTracks.videoTrack.setEnabled(enable);
621+
}
622+
623+
}
624+
this.videoEnabled = enable;
625+
}
626+
627+
// Disables/Re-enables the local audio function.
628+
async enableLocalAudio(enabled) {
629+
var enable = enabled == 1 ? true : false;
630+
console.log("EnableLocalAudio (clientManager):" + enable);
631+
if (this.client) {
632+
633+
if(localTracks.audioTrack != null){
634+
localTracks.audioTrack.setEnabled(enable);
635+
}
636+
640637
}
641-
this.videoEnabled = enabled;
638+
this.audioEnabled = enable;
642639
}
643640

644641

Assets/WebGLTemplates/AgoraTemplate/AgoraWebSDK/libs/multichannel.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,20 @@ function muteLocalVideoStream2_mc_WGL(channel, mute) {
323323
clients[channel].muteLocalVideoStream(mute);
324324
}
325325

326+
function enableLocalVideoStream2_mc_WGL(channel, mute) {
327+
if (typeof clients[channel] === "undefined") {
328+
return 0;
329+
}
330+
clients[channel].enableLocalVideo(mute);
331+
}
332+
333+
function enableLocalAudioStream2_mc_WGL(channel, mute) {
334+
if (typeof clients[channel] === "undefined") {
335+
return 0;
336+
}
337+
clients[channel].enableLocalAudio(mute);
338+
}
339+
326340
function muteRemoteAudioStream2_mc_WGL(userId, mute) {
327341
if (typeof clients[selectedCurrentChannel] === "undefined") {
328342
return 0;

0 commit comments

Comments
 (0)