mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Added a public field for getting the last packet received time and an async Disconnect method
This commit is contained in:
@@ -25,6 +25,7 @@ public class ChatClient
|
|||||||
private WebsocketClient _wsClient;
|
private WebsocketClient _wsClient;
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
private ChatClientConfigModel _config;
|
private ChatClientConfigModel _config;
|
||||||
|
public DateTime LastPacketReceived = DateTime.UtcNow;
|
||||||
|
|
||||||
public ChatClient(ChatClientConfigModel config)
|
public ChatClient(ChatClientConfigModel config)
|
||||||
{
|
{
|
||||||
@@ -51,6 +52,14 @@ public class ChatClient
|
|||||||
_wsClient.Stop(WebSocketCloseStatus.NormalClosure, "Closing websocket").Wait();
|
_wsClient.Stop(WebSocketCloseStatus.NormalClosure, "Closing websocket").Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bot is inconsistent with what methods are async and not but I don't want to change the Disconnect() method to be
|
||||||
|
// async as then it'll fuck up anyone not waiting for it. This is why there's an explicit async method for this but
|
||||||
|
// none for reconnect.
|
||||||
|
public async Task DisconnectAsync()
|
||||||
|
{
|
||||||
|
await _wsClient.Stop(WebSocketCloseStatus.NormalClosure, "Closing websocket");
|
||||||
|
}
|
||||||
|
|
||||||
public async Task Reconnect()
|
public async Task Reconnect()
|
||||||
{
|
{
|
||||||
await _wsClient.Reconnect();
|
await _wsClient.Reconnect();
|
||||||
@@ -114,6 +123,7 @@ public class ChatClient
|
|||||||
|
|
||||||
private void WsMessageReceived(ResponseMessage message)
|
private void WsMessageReceived(ResponseMessage message)
|
||||||
{
|
{
|
||||||
|
LastPacketReceived = DateTime.UtcNow;
|
||||||
if (message.Text == null)
|
if (message.Text == null)
|
||||||
{
|
{
|
||||||
_logger.Info("Websocket message was null, ignoring packet");
|
_logger.Info("Websocket message was null, ignoring packet");
|
||||||
|
|||||||
Reference in New Issue
Block a user