v2 (WPF)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user