feat: begin working on client
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
namespace StevesBot.Worker.Discord;
|
||||
|
||||
internal class DiscordGatewayClient : IDiscordGatewayClient
|
||||
{
|
||||
private readonly DiscordGatewayClientOptions _options;
|
||||
private readonly IWebSocketFactory _webSocketFactory;
|
||||
private readonly ILogger<DiscordGatewayClient> _logger;
|
||||
private readonly JsonSerializerOptions _jsonSerializerOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||
Converters =
|
||||
{
|
||||
new DiscordEventConverter(),
|
||||
},
|
||||
};
|
||||
private readonly AsyncLock _lock = new();
|
||||
|
||||
private string _gatewayUrl = string.Empty;
|
||||
private IWebSocket? _webSocket;
|
||||
private Task? _receiveTask;
|
||||
private DateTime _timeLastHeartbeatSent = DateTime.MinValue;
|
||||
private DateTime _timeLastHeartbeatAcknowledged = DateTime.MinValue;
|
||||
private CancellationTokenSource? _heartbeatCts;
|
||||
private Task? _heartbeatTask;
|
||||
private string _sessionId = string.Empty;
|
||||
private string _resumeGatewayUrl = string.Empty;
|
||||
|
||||
public DiscordGatewayClient(
|
||||
DiscordGatewayClientOptions options,
|
||||
IWebSocketFactory webSocketFactory,
|
||||
ILogger<DiscordGatewayClient> logger
|
||||
)
|
||||
{
|
||||
_options = options ?? throw new ArgumentNullException(nameof(options));
|
||||
_webSocketFactory = webSocketFactory ?? throw new ArgumentNullException(nameof(webSocketFactory));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_heartbeatCts?.Cancel();
|
||||
_heartbeatCts?.Dispose();
|
||||
_heartbeatTask?.Dispose();
|
||||
_receiveTask?.Dispose();
|
||||
_webSocket?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace StevesBot.Worker.Discord;
|
||||
|
||||
internal interface IDiscordGatewayClient : IDisposable
|
||||
{
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
global using System.Net.WebSockets;
|
||||
global using System.Text.Json;
|
||||
global using System.Text.Json.Serialization;
|
||||
|
||||
|
||||
global using StevesBot.Worker.Discord.Events;
|
||||
global using StevesBot.Worker.Threading;
|
||||
global using StevesBot.Worker.WebSockets;
|
||||
@@ -5,7 +5,7 @@
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"DiscordClientOptions": {
|
||||
"DiscordGatewayClientOptions": {
|
||||
"ApiUrl": "ApiUrl",
|
||||
"AppToken": "AppToken",
|
||||
"Intents": 0
|
||||
|
||||
Reference in New Issue
Block a user