mirror of
https://github.com/yawaflua/WebSockets.git
synced 2026-02-04 14:04:11 +02:00
Adds jsonSerializer for sendMessage for better user experience
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using yawaflua.WebSockets.Models.Interfaces;
|
||||
|
||||
namespace yawaflua.WebSockets.Core;
|
||||
@@ -38,6 +39,13 @@ internal class WebSocket : IWebSocket
|
||||
true,
|
||||
cts);
|
||||
|
||||
public async Task SendAsync<T>(T message, WebSocketMessageType messageType = WebSocketMessageType.Text, CancellationToken cts = default)
|
||||
=> await _webSocket.SendAsync(
|
||||
Encoding.UTF8.GetBytes(JsonSerializer.Serialize(message)),
|
||||
messageType,
|
||||
true,
|
||||
cts);
|
||||
|
||||
public async Task CloseAsync(WebSocketCloseStatus closeStatus = WebSocketCloseStatus.NormalClosure, string? reason = null, CancellationToken cts = default)
|
||||
=> await _webSocket.CloseAsync(closeStatus, reason, cts);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user