mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Root cause: server's db.Role and db.VoiceState structs had no JSON tags, causing Go to serialize field names as PascalCase while the C# client expected snake_case. Every role deserialized with Id=0, crashing ToDictionary with "duplicate key: 0". - Add json tags to Role and VoiceState in Server/db/models.go - Change Disconnected event to carry reason string for diagnostics - Wire ErrorReceived in MainViewModel to show server-side WS errors - Fix MainWindow to surface WebSocket errors on MainPage (not ConnectPage) - Use _reconnectCts.Token for receive loop instead of caller's token - Make ToDictionary calls safe with TryAdd to prevent future crashes
26 lines
852 B
C#
26 lines
852 B
C#
using System.Net.WebSockets;
|
|
|
|
namespace OwnCord.Client.Services;
|
|
|
|
public interface IWebSocketService
|
|
{
|
|
bool IsConnected { get; }
|
|
WebSocketState State { get; }
|
|
|
|
/// <summary>Fires for each raw JSON message received.</summary>
|
|
event Action<string>? MessageReceived;
|
|
|
|
/// <summary>Fires when the connection drops unexpectedly, with a reason string.</summary>
|
|
event Action<string>? Disconnected;
|
|
|
|
Task ConnectAsync(string uri, string token, CancellationToken ct = default);
|
|
Task SendAsync(object message, CancellationToken ct = default);
|
|
|
|
/// <summary>Starts the receive loop, firing MessageReceived for each message.
|
|
/// Returns when the connection closes.</summary>
|
|
Task RunReceiveLoopAsync(CancellationToken ct);
|
|
|
|
IAsyncEnumerable<string> ReceiveAsync(CancellationToken ct);
|
|
Task DisconnectAsync();
|
|
}
|