✨ Websocket handler
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user