feat: add DeleteAllUiClientsHandler and route for deleting all clients. Resolve issues with client closing websocket connection to DebugWebsocketSink

This commit is contained in:
Neil Dorin 2026-04-14 22:12:39 -06:00
parent a610e127de
commit 6e9480f503
3 changed files with 255 additions and 108 deletions

View file

@ -0,0 +1,43 @@
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers;
using PepperDash.Essentials.Core.Web;
using PepperDash.Essentials.WebSocketServer;
using Serilog.Events;
namespace PepperDash.Essentials.WebApiHandlers
{
/// <summary>
/// Represents a DeleteAllUiClientsHandler
/// </summary>
public class DeleteAllUiClientsHandler : WebApiBaseRequestHandler
{
private readonly MobileControlWebsocketServer server;
/// <summary>
/// Essentials CWS API handler for the MC Direct Server
/// </summary>
/// <param name="directServer">Direct Server instance</param>
public DeleteAllUiClientsHandler(MobileControlWebsocketServer directServer) : base(true)
{
server = directServer;
}
/// <summary>
/// Deletes all clients from the Direct Server
/// </summary>
/// <param name="context">HTTP Context for this request</param>
protected override void HandleDelete(HttpCwsContext context)
{
server.RemoveAllTokens("confirm");
var res = context.Response;
res.StatusCode = 200;
res.ContentType = "application/json";
res.Headers.Add("Content-Type", "application/json");
res.Write(JsonConvert.SerializeObject(new { success = true }), false);
res.End();
}
}
}

View file

@ -238,11 +238,17 @@ namespace PepperDash.Essentials.WebSocketServer
var routes = new List<HttpCwsRoute>
{
new HttpCwsRoute($"devices/{Key}/client")
new HttpCwsRoute($"device/{Key}/client")
{
Name = "ClientHandler",
RouteHandler = new UiClientHandler(this)
},
new HttpCwsRoute($"device/{Key}/deleteAllUiClients")
{
Name = "DeleteAllClientsHandler",
RouteHandler = new DeleteAllUiClientsHandler(this)
},
};
apiServer.AddRoute(routes);
@ -908,7 +914,7 @@ namespace PepperDash.Essentials.WebSocketServer
/// <summary>
/// Removes all clients from the server
/// </summary>
private void RemoveAllTokens(string s)
public void RemoveAllTokens(string s)
{
if (s == "?" || string.IsNullOrEmpty(s))
{