This commit is contained in:
zznty
2022-07-21 21:57:27 +07:00
commit bc4546410e
75 changed files with 2709 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
using System.Net.WebSockets;
using System.Text.Json;
using EmbedIO.WebSockets;
using TorchRemote.Models.Responses;
using TorchRemote.Plugin.Utils;
namespace TorchRemote.Plugin.Modules;
public class ChatModule : WebSocketModule
{
public ChatModule(string urlPath, bool enableConnectionWatchdog) : base(urlPath, enableConnectionWatchdog)
{
}
public async void SendChatResponse(ChatResponseBase response)
{
if (ActiveContexts.Count == 0)
return;
var buffer = JsonSerializer.SerializeToUtf8Bytes(response, Statics.SerializerOptions);
await Task.WhenAll(ActiveContexts
.Where(b => b.WebSocket.State is WebSocketState.Open)
.Select(context => context.WebSocket.SendAsync(buffer, true)));
}
protected override async Task OnMessageReceivedAsync(IWebSocketContext context, byte[] buffer, IWebSocketReceiveResult result)
{
}
}