This commit is contained in:
lxmou666 2021-03-14 19:19:04 +08:00
parent 10405cb902
commit abdb761b8c
3 changed files with 59 additions and 4 deletions

View File

@ -146,16 +146,18 @@ namespace JianGongYun.TRTC
WSClient.ReconnectTimeout = TimeSpan.FromSeconds(10);
WSClient.ReconnectionHappened.Subscribe((info) =>
{
Console.WriteLine($"Reconnection happened, type: {info.Type}");
$"Reconnection happened, type: {info.Type}".ToLocalLog();
if (WSClient.IsRunning)
{
WSClient.Send($"{{code:10000,nick:\"{CurrentClassroomEntity.TeacherName}\",\"room\":\"push_{ClassId}\"}}");//进房间
var joinRoom = $"{{code:10000,nick:\"{CurrentClassroomEntity.TeacherName}\",\"room\":\"push_{ClassId}\"}}";
WSClient.Send(joinRoom);//进房间
joinRoom.ToLocalLog();
}
liveWinMode.WSConneced = true;
});
WSClient.DisconnectionHappened.Subscribe((info) =>
{
Console.WriteLine($"DisconnectionHappened happened, type: {info.Type}, {info.CloseStatusDescription}");
$"DisconnectionHappened happened, type: {info.Type} {info.CloseStatusDescription} {info.Exception}".ToLocalLog();
liveWinMode.WSConneced = false;
});
WSClient.MessageReceived.Subscribe(CurrentLiveWindow.OnMsg);
@ -170,6 +172,7 @@ namespace JianGongYun.TRTC
if (WSClient.IsRunning)
{
WSClient.Send("{code:10016}");//向服务器发送心跳包
"发送心跳包 {code:10016}".ToLocalLog();
}
});
Heartbeat.Start();

View File

@ -7,6 +7,8 @@ using System.Security.Cryptography;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace JianGongYun.TRTC.Utils
{
@ -53,7 +55,7 @@ namespace JianGongYun.TRTC.Utils
public static bool IsTestEnv()
{
string path =Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ShowTestEnv.txt");
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ShowTestEnv.txt");
return File.Exists(path);
}
@ -91,5 +93,53 @@ namespace JianGongYun.TRTC.Utils
}
public static string TimeStr() => DateTime.Now.ToString("yyyyMMddHHmmssfff");
private static readonly Channel<string> _logQueue = Channel.CreateUnbounded<string>(new UnboundedChannelOptions()
{
SingleReader = true,
SingleWriter = false
});
static Util()
{
string log = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
if (!System.IO.Directory.Exists(log))
{
Directory.CreateDirectory(log);
}
log = Path.Combine(log, $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.log");
Task.Factory.StartNew(async () =>
{
try
{
while (await _logQueue.Reader.WaitToReadAsync())
{
while (_logQueue.Reader.TryRead(out var message))
{
try
{
await System.IO.File.AppendAllTextAsync(log, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}--------------------------{Environment.NewLine}{message}{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}");
}
catch (Exception e)
{
e.Message.ToLocalLog();
}
}
}
}
catch (Exception ex)
{
ex.Message.ToLocalLog();
}
}, TaskCreationOptions.LongRunning);
}
public static void ToLocalLog(this string val)
{
if (!string.IsNullOrWhiteSpace(val))
{
Console.WriteLine(val);
_logQueue.Writer.TryWrite(val);
}
}
}
}

View File

@ -19,6 +19,7 @@ using System.ComponentModel;
using Websocket.Client;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using JianGongYun.TRTC.Utils;
namespace JianGongYun.TRTC.Windows
{
@ -91,6 +92,7 @@ namespace JianGongYun.TRTC.Windows
}));
}
}
$"心跳包回应 {msg.Text}".ToLocalLog();
break;
}
return;