mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-17 13:45:01 +00:00
feat: updates to DebugSessionRequestHandler
This commit is contained in:
@@ -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" />
|
||||||
|
|||||||
@@ -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
|
||||||
|
{
|
||||||
// Start the WS Server
|
|
||||||
|
|
||||||
// Return the port number with the full url of the WS Server
|
|
||||||
|
|
||||||
var ip = CrestronEthernetHelper.GetEthernetParameter(
|
var ip = CrestronEthernetHelper.GetEthernetParameter(
|
||||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||||
|
|
||||||
var port = new Random().Next(65435, 65535);
|
var port = 0;
|
||||||
|
|
||||||
object data = new {
|
if(Debug.WebsocketSink == null)
|
||||||
url = string.Format(@"ws://{ip}:{port}", ip, port)
|
{
|
||||||
|
Debug.Console(0, "WebsocketSink is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Debug.WebsocketSink.IsListening)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
object data = new
|
||||||
|
{
|
||||||
|
url = string.Format(@"wss://{0}:{1}", ip, Debug.WebsocketSink.Port)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Return the port number with the full url of the WS Server
|
||||||
var res = JsonConvert.SerializeObject(data);
|
var res = JsonConvert.SerializeObject(data);
|
||||||
|
|
||||||
context.Response.Write(res, false);
|
|
||||||
context.Response.ContentType = "application/json";
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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();
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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" />
|
||||||
|
|||||||
Reference in New Issue
Block a user