diff --git a/JianGongYun/TRTC/LiveClassroom.cs b/JianGongYun/TRTC/LiveClassroom.cs index 38be140..db72085 100644 --- a/JianGongYun/TRTC/LiveClassroom.cs +++ b/JianGongYun/TRTC/LiveClassroom.cs @@ -57,7 +57,7 @@ namespace JianGongYun.TRTC /// 直播窗口 /// public static LiveWindow CurrentLiveWindow; - private static LiveWindowViewModel liveWinMode; + public static LiveWindowViewModel liveWinMode; public static ClassroomEntity CurrentClassroomEntity { get; private set; } public static TRTCCloudCallback TRTCCloudCallback = new TRTCCloudCallback(); @@ -142,19 +142,30 @@ namespace JianGongYun.TRTC var url = new Uri(WSUrl); WSClient = new WebsocketClient(url); - WSClient.ReconnectTimeout = TimeSpan.FromSeconds(30); - WSClient.ReconnectionHappened.Subscribe(info => - Console.WriteLine($"Reconnection happened, type: {info.Type}")); - + WSClient.ErrorReconnectTimeout = TimeSpan.FromSeconds(10); + WSClient.ReconnectTimeout = TimeSpan.FromSeconds(10); + WSClient.ReconnectionHappened.Subscribe((info) => + { + Console.WriteLine($"Reconnection happened, type: {info.Type}"); + WSClient.Send($"{{code:10000,nick:\"{CurrentClassroomEntity.TeacherName}\",\"room\":\"push_{ClassId}\"}}");//进房间 + liveWinMode.WSConneced = true; + }); + WSClient.DisconnectionHappened.Subscribe((info) => + { + Console.WriteLine($"DisconnectionHappened happened, type: {info.Type}, {info.CloseStatusDescription}"); + liveWinMode.WSConneced = false; + }); WSClient.MessageReceived.Subscribe(CurrentLiveWindow.OnMsg); WSClient.Start(); ClassId = CurrentClassroomEntity.TeacherId.Split('_')[1]; - WSClient.Send($"{{code:10000,nick:\"{CurrentClassroomEntity.TeacherName}\",\"room\":\"push_{ClassId}\"}}");//进房间 //发送心跳包 Heartbeat = new DispatcherTimer(DispatcherPriority.Render); Heartbeat.Interval = TimeSpan.FromSeconds(5); - Heartbeat.Tick += new EventHandler((a, b) => WSClient.Send("{code:10016}")); + Heartbeat.Tick += new EventHandler((a, b) => + { + WSClient.Send("{code:10016}");//向服务器发送心跳包 + }); Heartbeat.Start(); callerWindow?.Hide();//隐藏调用窗口 @@ -403,18 +414,24 @@ namespace JianGongYun.TRTC //lTRTCCloud.muteLocalAudio(false); lTXDeviceManager.setCurrentDeviceVolume(ManageLiteAV.TRTCDeviceType.TXMediaDeviceTypeMic, settingWindowViewModel.MicVolume); lTRTCCloud.stopSystemAudioLoopback(); + liveWinMode.MicMute = false; + liveWinMode.SysMute = true; } else if (settingWindowViewModel.AudioSource == "2") { //lTRTCCloud.muteLocalAudio(true); lTXDeviceManager.setCurrentDeviceVolume(ManageLiteAV.TRTCDeviceType.TXMediaDeviceTypeMic, 0); lTRTCCloud.startSystemAudioLoopback(null); + liveWinMode.MicMute = true; + liveWinMode.SysMute = false; } else if (settingWindowViewModel.AudioSource == "3") { //lTRTCCloud.muteLocalAudio(false); lTXDeviceManager.setCurrentDeviceVolume(ManageLiteAV.TRTCDeviceType.TXMediaDeviceTypeMic, settingWindowViewModel.MicVolume); lTRTCCloud.startSystemAudioLoopback(null); + liveWinMode.MicMute = false; + liveWinMode.SysMute = false; } } /// @@ -435,21 +452,37 @@ namespace JianGongYun.TRTC /// /// 设置麦克风静音 /// - public static void SetMicMute(bool? mute = true) + public static void SetMicMute(bool? mute = true, string tag = "mic") { if (liveWinMode.MicRunning) { - liveWinMode.MicMute = mute.HasValue ? mute.Value : !liveWinMode.MicMute; - if (liveWinMode.MicMute) + if (tag=="mic") { - //lTRTCCloud.muteLocalAudio(true); - lTXDeviceManager.setCurrentDeviceVolume(ManageLiteAV.TRTCDeviceType.TXMediaDeviceTypeMic, 0); - lTRTCCloud.stopSystemAudioLoopback(); + liveWinMode.MicMute = mute.HasValue ? mute.Value : !liveWinMode.MicMute; + if (liveWinMode.MicMute) + { + //lTRTCCloud.muteLocalAudio(true); + lTXDeviceManager.setCurrentDeviceVolume(ManageLiteAV.TRTCDeviceType.TXMediaDeviceTypeMic, 0); + } + else + { + //EnableAudio(); + lTXDeviceManager.setCurrentDeviceVolume(ManageLiteAV.TRTCDeviceType.TXMediaDeviceTypeMic, settingWindowViewModel.MicVolume); + } } else { - EnableAudio(); + liveWinMode.SysMute = mute.HasValue ? mute.Value : !liveWinMode.SysMute; + if (liveWinMode.SysMute) + { + + lTRTCCloud.stopSystemAudioLoopback(); + } + else + { + lTRTCCloud.startSystemAudioLoopback(null); + } } //lTRTCCloud.muteLocalAudio(liveWinMode.MicMute); } diff --git a/JianGongYun/TRTC/Utils/TRTCCloudCallback.cs b/JianGongYun/TRTC/Utils/TRTCCloudCallback.cs index d38d556..603beaf 100644 --- a/JianGongYun/TRTC/Utils/TRTCCloudCallback.cs +++ b/JianGongYun/TRTC/Utils/TRTCCloudCallback.cs @@ -1,4 +1,5 @@ -using ManageLiteAV; +using AduSkin.Controls.Metro; +using ManageLiteAV; using System; using System.Collections.Generic; using System.Diagnostics; @@ -10,82 +11,96 @@ namespace JianGongYun.TRTC.Utils { public void onAudioDeviceCaptureVolumeChanged(uint volume, bool muted) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onAudioDevicePlayoutVolumeChanged(uint volume, bool muted) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onAudioEffectFinished(int effectId, int code) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onCameraDidReady() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onConnectionLost() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); + LiveClassroom.liveWinMode.TRTCConneced = false; } public void onConnectionRecovery() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); + LiveClassroom.liveWinMode.TRTCConneced = true; } public void onConnectOtherRoom(string userId, TXLiteAVError errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onDeviceChange(string deviceId, TRTCDeviceType type, TRTCDeviceState state) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onDisconnectOtherRoom(TXLiteAVError errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onEnterRoom(int result) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); + if (result > 0) + { + LiveClassroom.liveWinMode.TRTCConneced = true; + } } public void onError(TXLiteAVError errCode, string errMsg, IntPtr arg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name + " " + errCode + " " + errMsg); + if (errCode == TXLiteAVError.ERR_ROOM_REQUEST_ENTER_ROOM_TIMEOUT) + { + LiveClassroom.CurrentLiveWindow.Dispatcher.Invoke(new Action(() => + { + AduMessageBox.ShowOK("进入教室超时,请检查网络连接是否正常!", "提醒", "确定"); + Environment.Exit(0); + })); + } } public void onExitRoom(int reason) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onFirstAudioFrame(string userId) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onFirstVideoFrame(string userId, TRTCVideoStreamType streamType, int width, int height) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onMicDidReady() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onMissCustomCmdMsg(string userId, int cmdId, int errCode, int missed) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onNetworkQuality(TRTCQualityInfo localQuality, TRTCQualityInfo[] remoteQuality, uint remoteQualityCount) @@ -95,92 +110,92 @@ namespace JianGongYun.TRTC.Utils public void onPlayBGMBegin(TXLiteAVError errCode) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onPlayBGMComplete(TXLiteAVError errCode) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onPlayBGMProgress(uint progressMS, uint durationMS) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onRecvCustomCmdMsg(string userId, int cmdID, uint seq, byte[] msg, uint msgSize) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onRecvSEIMsg(string userId, byte[] message, uint msgSize) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onRemoteUserEnterRoom(string userId) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onRemoteUserLeaveRoom(string userId, int reason) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onScreenCaptureCovered() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onScreenCapturePaused(int reason) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onScreenCaptureResumed(int reason) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onScreenCaptureStarted() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onScreenCaptureStoped(int reason) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onSendFirstLocalAudioFrame() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onSendFirstLocalVideoFrame(TRTCVideoStreamType streamType) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onSetMixTranscodingConfig(int errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onSpeedTest(TRTCSpeedTestResult currentResult, uint finishedCount, uint totalCount) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onStartPublishCDNStream(int errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onStartPublishing(int errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onStatistics(TRTCStatistics statis) @@ -190,72 +205,72 @@ namespace JianGongYun.TRTC.Utils public void onStopPublishCDNStream(int errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onStopPublishing(int errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onSwitchRole(TXLiteAVError errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onSwitchRoom(TXLiteAVError errCode, string errMsg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onTestMicVolume(uint volume) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onTestSpeakerVolume(uint volume) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onTryToReconnect() { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onUserAudioAvailable(string userId, bool available) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onUserEnter(string userId) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onUserExit(string userId, int reason) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onUserSubStreamAvailable(string userId, bool available) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onUserVideoAvailable(string userId, bool available) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onUserVoiceVolume(TRTCVolumeInfo[] userVolumes, uint userVolumesCount, uint totalVolume) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } public void onWarning(TXLiteAVWarning warningCode, string warningMsg, IntPtr arg) { - StackTrace trace = new StackTrace(true);StackFrame frame = trace.GetFrame(1);var method = frame.GetMethod();Console.WriteLine(method.Name); + StackTrace trace = new StackTrace(true); StackFrame frame = trace.GetFrame(1); var method = frame.GetMethod(); Console.WriteLine(method.Name); } } } diff --git a/JianGongYun/TRTC/Utils/UnBooleanToVisibilityConverter.cs b/JianGongYun/TRTC/Utils/UnBooleanToVisibilityConverter.cs index 4601f2b..8c11495 100644 --- a/JianGongYun/TRTC/Utils/UnBooleanToVisibilityConverter.cs +++ b/JianGongYun/TRTC/Utils/UnBooleanToVisibilityConverter.cs @@ -24,7 +24,7 @@ namespace JianGongYun.TRTC bool? nullable = (bool?)value; flag = nullable.HasValue ? nullable.Value : false; } - return (flag ? Visibility.Hidden : Visibility.Visible); + return (flag ? Visibility.Collapsed : Visibility.Visible); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs index 4808041..a00c92e 100644 --- a/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs +++ b/JianGongYun/TRTC/ViewModels/LiveWindowViewModel.cs @@ -73,6 +73,44 @@ namespace JianGongYun.TRTC.ViewModels return _IsLive; } } + /// + /// ws是否连接 + /// + private bool _WSConneced = false; + public bool WSConneced + { + set + { + _WSConneced = value; + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs("WSConneced")); + } + } + get + { + return _WSConneced; + } + } + /// + /// TRTC是否连接 + /// + private bool _TRTCConneced = false; + public bool TRTCConneced + { + set + { + _TRTCConneced = value; + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs("TRTCConneced")); + } + } + get + { + return _TRTCConneced; + } + } public LiveWindowViewModel() { @@ -215,6 +253,7 @@ namespace JianGongYun.TRTC.ViewModels if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("MicMute")); + PropertyChanged(this, new PropertyChangedEventArgs("SoundTip")); } } get @@ -222,6 +261,53 @@ namespace JianGongYun.TRTC.ViewModels return _MicMute; } } + /// + /// 系统音静音 + /// + private bool _SysMute = false; + public bool SysMute + { + set + { + _SysMute = value; + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs("SysMute")); + PropertyChanged(this, new PropertyChangedEventArgs("SoundTip")); + } + } + get + { + return _SysMute; + } + } + /// + /// 声音提示 + /// + private string _SoundTip; + public string SoundTip + { + get + { + if (!SysMute && !MicMute) + { + _SoundTip = "仅开启声音"; + } + else if (SysMute && !MicMute) + { + _SoundTip = "仅开启麦克风"; + } + else if (!SysMute && MicMute) + { + _SoundTip = "仅开启系统音"; + } + else + { + _SoundTip = "所有设备被关闭"; + } + return _SoundTip; + } + } private ObservableCollection _LiveScreens = new ObservableCollection(); diff --git a/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs b/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs index b772393..a5043da 100644 --- a/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs +++ b/JianGongYun/TRTC/ViewModels/SettingWindowViewModel.cs @@ -173,11 +173,18 @@ namespace JianGongYun.TRTC.ViewModels if (_AudioSource == "1")//只采集麦克风,关闭系统音采集 { ShowSytemGatherSlider = Visibility.Collapsed; + ShowMicSetting = Visibility.Visible; //LiveClassroom.lTRTCCloud.stopSystemAudioLoopback(); } - else if (_AudioSource == "2" || _AudioSource == "3")//麦和系统音,开启采集系统音 + else if (_AudioSource == "2")//只显示系统音 { ShowSytemGatherSlider = Visibility.Visible; + ShowMicSetting = Visibility.Collapsed; + } + else if (_AudioSource == "3")//麦和系统音,开启采集系统音 + { + ShowSytemGatherSlider = Visibility.Visible; + ShowMicSetting = Visibility.Visible; //LiveClassroom.lTRTCCloud.startSystemAudioLoopback(null); } if (PropertyChanged != null) @@ -214,6 +221,33 @@ namespace JianGongYun.TRTC.ViewModels } } } + /// + /// 是否显示系统采集滑动条 + /// + private Visibility _ShowMicSetting = Visibility.Collapsed; + public Visibility ShowMicSetting + { + get + { + if (AudioSource == "1" || AudioSource == "3") + { + _ShowMicSetting = Visibility.Visible; + } + else + { + _ShowMicSetting = Visibility.Collapsed; + } + return _ShowMicSetting; + } + set + { + _ShowMicSetting = value; + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs("ShowMicSetting")); + } + } + } /// /// 系统采集音量 diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml b/JianGongYun/TRTC/Windows/LiveWindow.xaml index 19dbb44..5173eb4 100644 --- a/JianGongYun/TRTC/Windows/LiveWindow.xaml +++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml @@ -18,6 +18,7 @@ M512 85.33312C323.499138 85.33312 170.66752 238.164738 170.66752 426.6656s152.831618 341.33248 341.33248 341.33248 341.33248-152.831618 341.33248-341.33248S700.500862 85.33312 512 85.33312zM85.3344 426.6656C85.3344 191.032411 276.366811 0 512 0c235.661633 0 426.6656 191.032411 426.6656 426.6656 0 235.661633-191.003967 426.6656-426.6656 426.6656-235.633189 0-426.6656-191.003967-426.6656-426.6656z m127.99968 554.66528A42.66656 42.66656 0 0 1 256.00064 938.66432h511.99872a42.66656 42.66656 0 1 1 0 85.33312H256.00064a42.66656 42.66656 0 0 1-42.66656-42.66656z M459.776131 775.166062a42.239894 42.239894 0 0 1 19.114618 56.888747l-85.560675 169.642242a42.951004 42.951004 0 0 1-56.774969 17.806178 42.239894 42.239894 0 0 1-19.71195-55.722527l85.560675-169.642243a42.951004 42.951004 0 0 1 57.372301-18.972397z m132.892112 0a42.239894 42.239894 0 0 0-19.114619 56.888747l85.560675 169.642242a42.951004 42.951004 0 0 0 56.774969 17.806178 42.239894 42.239894 0 0 0 19.711951-55.722527l-85.560675-169.642243a42.951004 42.951004 0 0 0-57.372301-18.972397zM526.222187 321.136975c-61.439846 0-111.2175 49.350988-111.2175 110.250391 0 60.927848 49.777653 110.278835 111.2175 110.278835s111.2175-49.350988 111.217499-110.278835c0-60.870959-49.777653-110.250391-111.217499-110.250391z m-196.806619 110.250391c0-107.747286 88.120669-195.099957 196.806619-195.099957 108.685951 0 196.806619 87.352671 196.806619 195.128401 0 107.747286-88.120669 195.099957-196.806619 195.099957-108.685951 0-196.806619-87.352671-196.806619-195.128401zM526.222187 28.444373c23.60883 0 42.780337 19.000841 42.780337 42.410561v63.630063c0 23.409719-19.143063 42.382116-42.780337 42.382116-23.60883 0-42.780337-18.972397-42.780338-42.382116V70.82649c0-23.409719 19.143063-42.410561 42.780338-42.410561z M864 159.872L160 160c-17.696 0-32 14.176-32 31.872v448a32 32 0 0 0 32 32h704a32 32 0 0 0 32-32v-448a32 32 0 0 0-32-32zM864 640H160V191.872h704V640z M928 32H96a96 96 0 0 0-96 96v640a95.904 95.904 0 0 0 95.68 95.936H416v38.944l-199.744 25.952A31.968 31.968 0 0 0 224 991.872h576a32 32 0 0 0 7.744-63.072L608 902.88v-38.944h320.32A95.904 95.904 0 0 0 1024 768V128a96 96 0 0 0-96-96z m32 736c0 17.632-14.368 32-32 32H96c-17.664 0-32-14.368-32-32V128a32 32 0 0 1 32-32h832c17.632 0 32 14.336 32 32v640z M486.4 972.8v-128.9728A332.8 332.8 0 0 1 179.2 512a25.6 25.6 0 0 1 51.2 0 281.6 281.6 0 0 0 563.2 0 25.6 25.6 0 1 1 51.2 0 332.8 332.8 0 0 1-307.2 331.8272V972.8h153.6a25.6 25.6 0 1 1 0 51.2h-358.4a25.6 25.6 0 1 1 0-51.2h153.6zM512 51.2a153.6 153.6 0 0 0-153.6 153.6v307.2a153.6 153.6 0 0 0 307.2 0V204.8a153.6 153.6 0 0 0-153.6-153.6z m0-51.2a204.8 204.8 0 0 1 204.8 204.8v307.2a204.8 204.8 0 1 1-409.6 0V204.8a204.8 204.8 0 0 1 204.8-204.8z + M585.955556 896c-9.197037 0-18.299259-2.74963-26.168889-8.248889l-288.237037-202.145185h-101.451852c-23.22963 0-42.097778-18.583704-42.097778-41.528889V379.922963c0-22.85037 18.868148-41.528889 42.097778-41.528889h101.451852l288.237037-202.145185c14.032593-9.765926 32.142222-10.998519 47.312592-3.128889 14.885926 7.68 24.082963 22.85037 24.082963 39.348148v678.874074c0 16.592593-9.197037 31.668148-24.082963 39.348148-6.637037 3.602963-13.937778 5.30963-21.143703 5.30963zM170.666667 642.939259h114.346666l299.330371 209.92c0.948148 0.663704 1.991111 0.758519 3.128889 0.18963 1.137778-0.568889 1.137778-1.232593 1.137777-1.517037V172.562963c0-0.284444 0-0.948148-1.137777-1.517037-1.137778-0.568889-2.180741-0.474074-3.128889 0.18963L285.013333 381.060741H170.666667v261.878518zM757.57037 758.423704c-6.637037 0-13.179259-3.128889-17.351111-8.912593-6.826667-9.576296-4.645926-22.945185 4.930371-29.771852C812.847407 671.194074 853.333333 593.351111 853.333333 511.81037s-40.391111-159.194074-107.994074-207.834074c-9.576296-6.921481-11.757037-20.195556-4.835555-29.771852 6.921481-9.576296 20.195556-11.757037 29.771852-4.835555 38.115556 27.401481 69.688889 63.525926 91.401481 104.391111 22.471111 42.382222 34.322963 90.074074 34.322963 138.05037 0 48.071111-11.851852 95.857778-34.417778 138.24-21.712593 40.96-53.380741 77.084444-91.591111 104.485926-3.792593 2.56-8.059259 3.887407-12.420741 3.887408z M701.345185 703.715556c-7.016296 0-13.937778-3.508148-18.014815-9.860741-6.352593-9.955556-3.413333-23.134815 6.542223-29.487408 53.285926-33.848889 85.143704-90.927407 85.143703-152.651851 0-61.534815-31.762963-118.613333-84.859259-152.462223-9.955556-6.352593-12.894815-19.531852-6.542222-29.487407 6.352593-9.955556 19.531852-12.894815 29.487407-6.542222 65.517037 41.813333 104.580741 112.260741 104.580741 188.491852 0 76.325926-39.253333 146.868148-104.96 188.681481-3.508148 2.275556-7.49037 3.318519-11.377778 3.318519z M511.626 1.896C229.572 1.896 0.927 230.541 0.927 512.595c0 282.055 228.645 510.699 510.699 510.699s510.698-228.645 510.698-510.699S793.68 1.896 511.626 1.896z m0 69.641c243.606 0 441.058 197.474 441.058 441.058 0 87.347-25.392 168.762-69.194 237.271-73.419-77.609-170.944-132.204-280.597-151.829 70.004-33.755 118.404-105.164 118.404-188.066 0-115.388-93.535-208.922-208.923-208.922S303.452 294.583 303.452 409.97c0 82.902 48.399 154.311 118.403 188.066-110.093 19.704-207.96 74.661-281.479 152.77-44.177-68.704-69.808-150.465-69.808-238.211 0-243.584 197.496-441.058 441.058-441.058z M447.5904 819.1488H166.4a89.6 89.6 0 0 1-89.6-89.4976V166.4c0-49.3568 40.192-89.5488 89.6-89.5488h563.2c49.4592 0 89.6512 40.192 89.6512 89.5488v281.6H896v-281.6A166.5536 166.5536 0 0 0 729.6 0h-563.2A166.5536 166.5536 0 0 0 0 166.4v563.2512A166.656 166.656 0 0 0 166.4 896h281.1904v-76.8512z M947.2 238.5408V857.6c0 49.408-40.192 89.6-89.6 89.6H242.7904V1024H857.6A166.6048 166.6048 0 0 0 1024 857.6V238.5408h-76.8z M577.8944 813.8752h235.9808v-236.032h-76.8v104.96l-395.776-395.8784h104.9088V210.176H210.1248v235.9808h76.8V341.248l395.9296 395.8784h-104.96z M2.896 921.614L924.656 0l102.385 102.386L105.354 1024z @@ -61,11 +62,13 @@ - + - - 直播中 + + + 直播中 + 重连中 @@ -127,6 +130,12 @@ + + + + + + @@ -144,8 +153,12 @@ - - + + + + + + @@ -230,12 +243,12 @@ - - 仅开启声音 + + - + diff --git a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs index 8fa7e05..b8fbae1 100644 --- a/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs +++ b/JianGongYun/TRTC/Windows/LiveWindow.xaml.cs @@ -103,7 +103,7 @@ namespace JianGongYun.TRTC.Windows var time = data["extend"]["time"].ToString(); this.Dispatcher.Invoke(new Action(() => { - if (LiveWindowViewModel.Chats.Count > 520) + if (LiveWindowViewModel.Chats.Count > 200) { LiveWindowViewModel.Chats.RemoveAt(0); } @@ -122,6 +122,7 @@ namespace JianGongYun.TRTC.Windows Rad2.Foreground = color; Rad3.Foreground = color; Rad4.Foreground = color; + ChatConnIcon.Foreground = new SolidColorBrush(Colors.White); if (LiveWindowViewModel.IsLive) { LiveClassroom.PauseAllView(false);//切前台启动实时预览渲染 @@ -245,7 +246,10 @@ namespace JianGongYun.TRTC.Windows if (onEnd == null) { - this.Close(); + this.Dispatcher.Invoke(new Action(() => + { + this.Close(); + })); } //LiveClassroom.CallerWindow.Show();//还原调用者窗口 } @@ -379,11 +383,13 @@ namespace JianGongYun.TRTC.Windows private void SetMute_Click(object sender, RoutedEventArgs e) { - LiveClassroom.SetMicMute(null); + var btn = sender as AduSysButton; + var tag = btn.Tag.ToString(); + LiveClassroom.SetMicMute(null, tag); NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel() { Title = "提醒", - Content = $"{(LiveWindowViewModel.MicMute ? "设置" : "取消")}静音成功" + Content = $"{(LiveWindowViewModel.MicMute ? "设置" : "取消")}{(tag == "mic" ? "麦克风" : "系统音")}静音成功" }); } diff --git a/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml b/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml index 3aebdbc..568e010 100644 --- a/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml +++ b/JianGongYun/TRTC/Windows/LiveWindowRightBottomBlock.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:JianGongYun.TRTC.Windows" xmlns:System="clr-namespace:System;assembly=mscorlib" + xmlns:Metro="clr-namespace:AduSkin.Controls.Metro;assembly=AduSkin" mc:Ignorable="d" ResizeMode="NoResize" ShowInTaskbar="False" @@ -58,6 +59,7 @@ + @@ -72,8 +74,9 @@ - - + + + @@ -119,7 +122,14 @@ - - + + + + + + + + + diff --git a/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml b/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml index f1f1f38..bedb347 100644 --- a/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml +++ b/JianGongYun/TRTC/Windows/LiveWindowTopBlock.xaml @@ -4,6 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:JianGongYun.TRTC.Windows" + xmlns:live="clr-namespace:JianGongYun.TRTC" ShowInTaskbar="False" WindowStyle="None" AllowsTransparency="True" @@ -18,6 +19,10 @@ MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseLeftButtonUp="Window_MouseLeftButtonUp" > + + + + @@ -37,8 +42,10 @@ - - 直播中 + + 直播中 + + 重连中 diff --git a/JianGongYun/TRTC/Windows/SettingWindow.xaml b/JianGongYun/TRTC/Windows/SettingWindow.xaml index 956e0d3..21cc039 100644 --- a/JianGongYun/TRTC/Windows/SettingWindow.xaml +++ b/JianGongYun/TRTC/Windows/SettingWindow.xaml @@ -32,15 +32,6 @@ 摄像头 - - 麦克风 - - - - - 麦采集音量 - - 音频来源 @@ -49,6 +40,15 @@ + + 麦克风 + + + + + 麦采集音量 + + 系统采集音量 diff --git a/WSDemo/Program.cs b/WSDemo/Program.cs index 2868c14..6dd72cf 100644 --- a/WSDemo/Program.cs +++ b/WSDemo/Program.cs @@ -14,20 +14,43 @@ namespace WSDemo using (var client = new WebsocketClient(url)) { - client.ReconnectTimeout = TimeSpan.FromSeconds(30); - client.ReconnectionHappened.Subscribe(info => - Console.WriteLine($"Reconnection happened, type: {info.Type}")); + client.ErrorReconnectTimeout = TimeSpan.FromSeconds(10); + client.ReconnectTimeout = TimeSpan.FromSeconds(10); + client.ReconnectionHappened.Subscribe((info) => + { + Console.WriteLine($"Reconnection happened, type: {info.Type}"); + client.Send("{code:10000,nick:\"张三\",\"room\":\"push_1500\"}"); + //if (!client.IsRunning) + //{ + // client.Reconnect(); + //} + }); + client.DisconnectionHappened.Subscribe((info) => + { + Console.WriteLine($"DisconnectionHappened happened, type: {info.Type}, {info.CloseStatusDescription}"); + //if (!client.IsRunning) + //{ + // client.Reconnect(); + //} + }); client.MessageReceived.Subscribe(msg => Console.WriteLine($"Message received: {msg}")); - client.StartOrFail(); + client.Start(); - Task.Run(() => client.Send("{code:10000,nick:\"张三\",\"room\":\"push_1500\"}")); + //Task.Run(() => client.Send("{code:10000,nick:\"张三\",\"room\":\"push_1500\"}")); Task.Run(() => { while (true) { - client.Send($"{{\"code\":10086,\"mess\":\"{Guid.NewGuid()}\",\"room\":\"push_1500\"}}"); - client.Send("{code:10016}"); + try + { + client.Send($"{{\"code\":10086,\"mess\":\"{Guid.NewGuid()}\",\"room\":\"push_1500\"}}"); + client.Send("{code:10016}"); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } Thread.Sleep(5000); } });