mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-07-02 10:38:16 +00:00
feat: update version to 2.29.0 and enhance logging in DebugWebsocketSink
This commit is contained in:
parent
30979f2b67
commit
77a5c4476f
2 changed files with 81 additions and 60 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.19.4-local</Version>
|
<Version>2.29.0-local</Version>
|
||||||
<InformationalVersion>$(Version)</InformationalVersion>
|
<InformationalVersion>$(Version)</InformationalVersion>
|
||||||
<Authors>PepperDash Technology</Authors>
|
<Authors>PepperDash Technology</Authors>
|
||||||
<Company>PepperDash Technology</Company>
|
<Company>PepperDash Technology</Company>
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,11 @@ namespace PepperDash.Core
|
||||||
private const string _certificatePassword = "cres12345";
|
private const string _certificatePassword = "cres12345";
|
||||||
|
|
||||||
public int Port
|
public int Port
|
||||||
{ get
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
|
|
||||||
if(_httpsServer == null) return 0;
|
if (_httpsServer == null) return 0;
|
||||||
return _httpsServer.Port;
|
return _httpsServer.Port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +131,7 @@ namespace PepperDash.Core
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StartServerAndSetPort(int port)
|
public void StartServerAndSetPort(int port)
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Starting Websocket Server on port: {0}", port);
|
Debug.LogInformation("Starting Websocket Server on port: {port}", port);
|
||||||
|
|
||||||
|
|
||||||
Start(port, $"\\user\\{_certificateName}.pfx", _certificatePassword);
|
Start(port, $"\\user\\{_certificateName}.pfx", _certificatePassword);
|
||||||
|
|
@ -145,7 +146,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(certPath))
|
if (!string.IsNullOrWhiteSpace(certPath))
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Assigning SSL Configuration");
|
Debug.LogInformation("Assigning SSL Configuration");
|
||||||
_httpsServer.SslConfiguration = new ServerSslConfiguration(new X509Certificate2(certPath, certPassword))
|
_httpsServer.SslConfiguration = new ServerSslConfiguration(new X509Certificate2(certPath, certPassword))
|
||||||
{
|
{
|
||||||
ClientCertificateRequired = false,
|
ClientCertificateRequired = false,
|
||||||
|
|
@ -154,54 +155,24 @@ namespace PepperDash.Core
|
||||||
//this is just to test, you might want to actually validate
|
//this is just to test, you might want to actually validate
|
||||||
ClientCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
|
ClientCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
|
||||||
{
|
{
|
||||||
Debug.Console(0, "HTTPS ClientCerticateValidation Callback triggered");
|
Debug.LogInformation("HTTPS ClientCerticateValidation Callback triggered");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Debug.Console(0, "Adding Debug Client Service");
|
Debug.LogInformation("Adding Debug Client Service");
|
||||||
_httpsServer.AddWebSocketService<DebugClient>(_path);
|
_httpsServer.AddWebSocketService<DebugClient>(_path);
|
||||||
Debug.Console(0, "Assigning Log Info");
|
Debug.LogInformation("Assigning Log Info");
|
||||||
_httpsServer.Log.Level = LogLevel.Trace;
|
_httpsServer.Log.Level = LogLevel.Trace;
|
||||||
_httpsServer.Log.Output = (d, s) =>
|
_httpsServer.Log.Output = WriteWebSocketInternalLog;
|
||||||
{
|
Debug.LogInformation("Starting");
|
||||||
uint level;
|
|
||||||
|
|
||||||
switch(d.Level)
|
|
||||||
{
|
|
||||||
case WebSocketSharp.LogLevel.Fatal:
|
|
||||||
level = 3;
|
|
||||||
break;
|
|
||||||
case WebSocketSharp.LogLevel.Error:
|
|
||||||
level = 2;
|
|
||||||
break;
|
|
||||||
case WebSocketSharp.LogLevel.Warn:
|
|
||||||
level = 1;
|
|
||||||
break;
|
|
||||||
case WebSocketSharp.LogLevel.Info:
|
|
||||||
level = 0;
|
|
||||||
break;
|
|
||||||
case WebSocketSharp.LogLevel.Debug:
|
|
||||||
level = 4;
|
|
||||||
break;
|
|
||||||
case WebSocketSharp.LogLevel.Trace:
|
|
||||||
level = 5;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
level = 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.Console(level, "{1} {0}\rCaller:{2}\rMessage:{3}\rs:{4}", d.Level.ToString(), d.Date.ToString(), d.Caller.ToString(), d.Message, s);
|
|
||||||
};
|
|
||||||
Debug.Console(0, "Starting");
|
|
||||||
|
|
||||||
_httpsServer.Start();
|
_httpsServer.Start();
|
||||||
Debug.Console(0, "Ready");
|
Debug.LogInformation("Ready");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, "WebSocket Failed to start {0}", ex.Message);
|
Debug.LogError(ex, "WebSocket Failed to start: {message}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,18 +181,68 @@ namespace PepperDash.Core
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StopServer()
|
public void StopServer()
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Stopping Websocket Server");
|
Debug.LogInformation("Stopping Websocket Server");
|
||||||
|
|
||||||
_httpsServer.WebSocketServices[_path].Sessions.Broadcast("Server is stopping");
|
try
|
||||||
|
|
||||||
foreach (var session in _httpsServer.WebSocketServices[_path].Sessions.Sessions)
|
|
||||||
{
|
{
|
||||||
session.Context.WebSocket.Close(1001, "Server is stopping" );
|
if (_httpsServer == null || !_httpsServer.IsListening)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_httpsServer?.Stop();
|
// Prevent close-sequence internal websocket logs from re-entering the logging pipeline.
|
||||||
|
_httpsServer.Log.Output = (d, s) => { };
|
||||||
|
|
||||||
|
var serviceHost = _httpsServer.WebSocketServices[_path];
|
||||||
|
|
||||||
|
if (serviceHost == null)
|
||||||
|
{
|
||||||
|
_httpsServer.Stop();
|
||||||
|
_httpsServer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceHost.Sessions.Broadcast("Server is stopping");
|
||||||
|
|
||||||
|
foreach (var session in serviceHost.Sessions.Sessions)
|
||||||
|
{
|
||||||
|
if (session?.Context?.WebSocket != null && session.Context.WebSocket.IsAlive)
|
||||||
|
{
|
||||||
|
session.Context.WebSocket.Close(1001, "Server is stopping");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_httpsServer.Stop();
|
||||||
|
|
||||||
_httpsServer = null;
|
_httpsServer = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.LogError(ex, "WebSocket Failed to stop gracefully {0}", ex.Message);
|
||||||
|
Debug.LogVerbose("Stack Trace\r\n{0}", ex.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteWebSocketInternalLog(LogData data, string supplemental)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = string.IsNullOrWhiteSpace(data.Message) ? "<none>" : data.Message;
|
||||||
|
var details = string.IsNullOrWhiteSpace(supplemental) ? string.Empty : string.Format(" | details: {0}", supplemental);
|
||||||
|
|
||||||
|
// Use direct console output to avoid recursive log sink calls.
|
||||||
|
CrestronConsole.PrintLine(string.Format("WS[{0}] {1} | message: {2}{3}", data.Level, data.Date, message, details));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Never throw from websocket log callback.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,7 +283,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
public DebugClient()
|
public DebugClient()
|
||||||
{
|
{
|
||||||
Debug.Console(0, "DebugClient Created");
|
Debug.LogInformation("DebugClient Created");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnOpen()
|
protected override void OnOpen()
|
||||||
|
|
@ -270,7 +291,7 @@ namespace PepperDash.Core
|
||||||
base.OnOpen();
|
base.OnOpen();
|
||||||
|
|
||||||
var url = Context.WebSocket.Url;
|
var url = Context.WebSocket.Url;
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WebSocket Connection from: {0}", url);
|
Debug.LogInformation("New WebSocket Connection from: {url}", url);
|
||||||
|
|
||||||
_connectionTime = DateTime.Now;
|
_connectionTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
@ -279,14 +300,14 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
base.OnMessage(e);
|
base.OnMessage(e);
|
||||||
|
|
||||||
Debug.Console(0, "WebSocket UiClient Message: {0}", e.Data);
|
Debug.LogInformation("WebSocket UiClient Message: {data}", e.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClose(CloseEventArgs e)
|
protected override void OnClose(CloseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnClose(e);
|
base.OnClose(e);
|
||||||
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "WebSocket UiClient Closing: {0} reason: {1}", e.Code, e.Reason);
|
Debug.LogInformation("WebSocket UiClient Closing: {code} reason: {reason}", e.Code, e.Reason);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,7 +315,7 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
base.OnError(e);
|
base.OnError(e);
|
||||||
|
|
||||||
Debug.Console(2, Debug.ErrorLogLevel.Notice, "WebSocket UiClient Error: {0} message: {1}", e.Exception, e.Message);
|
Debug.LogError(e.Exception, "WebSocket UiClient Error: {message}", e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue