Websocket handler

This commit is contained in:
2025-07-18 16:12:34 +08:00
parent 086a12f971
commit 57f85ec341
12 changed files with 276 additions and 15 deletions

View File

@@ -1,4 +1,5 @@
using System.Text.Json;
using DysonNetwork.Shared.Proto;
using NodaTime;
using NodaTime.Serialization.SystemTextJson;
@@ -7,7 +8,8 @@ namespace DysonNetwork.Pusher.Connection;
public class WebSocketPacket
{
public string Type { get; set; } = null!;
public object Data { get; set; } = null!;
public object? Data { get; set; } = null!;
public string? Endpoint { get; set; }
public string? ErrorMessage { get; set; }
/// <summary>
@@ -62,4 +64,24 @@ public class WebSocketPacket
var json = JsonSerializer.Serialize(this, jsonOpts);
return System.Text.Encoding.UTF8.GetBytes(json);
}
public Shared.Proto.WebSocketPacket ToProtoValue()
{
return new Shared.Proto.WebSocketPacket
{
Type = Type,
Data = GrpcTypeHelper.ConvertClassToValue(Data),
ErrorMessage = ErrorMessage
};
}
public static WebSocketPacket FromProtoValue(Shared.Proto.WebSocketPacket packet)
{
return new WebSocketPacket
{
Type = packet.Type,
Data = GrpcTypeHelper.ConvertValueToObject(packet.Data),
ErrorMessage = packet.ErrorMessage
};
}
}