feat: updates to DebugSessionRequestHandler

This commit is contained in:
Neil Dorin
2023-11-06 21:50:30 -07:00
parent 1727e81e33
commit b263c7421b
4 changed files with 54 additions and 16 deletions

View File

@@ -26,7 +26,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"> <PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<Aliases>Full</Aliases> <Aliases>Full</Aliases>
</PackageReference> </PackageReference>
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-344" /> <PackageReference Include="PepperDashCore" Version="2.0.0-alpha-351" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Crestron\CrestronGenericBaseDevice.cs.orig" /> <None Include="Crestron\CrestronGenericBaseDevice.cs.orig" />

View File

@@ -1,4 +1,6 @@
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.WebScripting;
using Crestron.SimplSharpPro.EthernetCommunication;
using Newtonsoft.Json; using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Core.Web.RequestHandlers; using PepperDash.Core.Web.RequestHandlers;
@@ -17,6 +19,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
{ {
} }
/// <summary>
/// Gets details for a debug session
/// </summary>
/// <param name="context"></param>
protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context) protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context)
{ {
var routeData = context.Request.RouteData; var routeData = context.Request.RouteData;
@@ -29,25 +35,57 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
return; return;
} }
// Generate a random port within a specified range try
{
var ip = CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
// Start the WS Server var port = 0;
// Return the port number with the full url of the WS Server if(Debug.WebsocketSink == null)
{
Debug.Console(0, "WebsocketSink is null");
}
var ip = CrestronEthernetHelper.GetEthernetParameter( if (!Debug.WebsocketSink.IsListening)
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); {
Debug.Console(0, "Starting WS Server");
// Generate a random port within a specified range
port = new Random().Next(65435, 65535);
// Start the WS Server
Debug.WebsocketSink.StartServerAndSetPort(port);
}
var port = new Random().Next(65435, 65535); object data = new
{
url = string.Format(@"wss://{0}:{1}", ip, Debug.WebsocketSink.Port)
};
object data = new { // Return the port number with the full url of the WS Server
url = string.Format(@"ws://{ip}:{port}", ip, port) var res = JsonConvert.SerializeObject(data);
};
var res = JsonConvert.SerializeObject(data); context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.Write(res, false);
context.Response.End();
}
catch (Exception e)
{
Debug.Console(0, "Error: {0}", e);
}
}
context.Response.Write(res, false); /// <summary>
context.Response.ContentType = "application/json"; /// Stops a debug session
/// </summary>
/// <param name="context"></param>
protected override void HandlePost(HttpCwsContext context)
{
Debug.WebsocketSink.StopServer();
context.Response.StatusDescription = "Ending Debug Session";
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK"; context.Response.StatusDescription = "OK";
context.Response.End(); context.Response.End();

View File

@@ -31,6 +31,6 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"> <PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<Aliases>Full</Aliases> <Aliases>Full</Aliases>
</PackageReference> </PackageReference>
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-344" /> <PackageReference Include="PepperDashCore" Version="2.0.0-alpha-351" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -51,7 +51,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"> <PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<Aliases>Full</Aliases> <Aliases>Full</Aliases>
</PackageReference> </PackageReference>
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-344" /> <PackageReference Include="PepperDashCore" Version="2.0.0-alpha-351" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PepperDash.Essentials.Core\PepperDash.Essentials.Core.csproj" /> <ProjectReference Include="..\PepperDash.Essentials.Core\PepperDash.Essentials.Core.csproj" />