This commit is contained in:
2026-03-13 01:22:28 +01:00
parent 695e4560b5
commit 86641919f8
27 changed files with 755 additions and 344 deletions

View File

@@ -22,6 +22,9 @@ public class LcuWebsocket : IDisposable
private readonly ClientWebSocket _socket = new();
public event EventHandler? Connecting;
public event EventHandler? Connected;
public event EventHandler? Disconnected;
public event EventHandler<LcuApiEvent>? LcuApiEvent;
public event EventHandler<Exception>? LcuApiException;
@@ -42,7 +45,15 @@ public class LcuWebsocket : IDisposable
public async Task Connect()
{
ProcessInfo = ProcessFinder.GetProcessInfo();
Connecting?.Invoke(this, EventArgs.Empty);
try
{
ProcessInfo = ProcessFinder.GetProcessInfo();
}
catch (Exception ex)
{
return;
}
if (!ProcessFinder.IsPortOpen(ProcessInfo))
{
throw new InvalidOperationException("Failed to connect to LCUx process port.");
@@ -57,6 +68,8 @@ public class LcuWebsocket : IDisposable
{
await _socket.ConnectAsync(uri, CancellationToken.None);
Connected?.Invoke(this, EventArgs.Empty);
foreach (string eventName in SUBSCRIBE_EVENTS)
{
string message = $"[{OPCODE_SUBSCRIBE}, \"{eventName}\"]";
@@ -108,6 +121,10 @@ public class LcuWebsocket : IDisposable
{
LcuApiException?.Invoke(this, ex);
}
finally
{
Disconnected?.Invoke(this, EventArgs.Empty);
}
}
#region IDisposable