(_path);
_httpsServer.Log.Level = LogLevel.Warn;
_httpsServer.Start();
+ RoutingFeedbackClient.Owner = this;
SubscribeToRoutingEvents();
Debug.LogMessage(LogEventLevel.Information, "Routing Feedback WebSocket ready at {url}", this, Url);
@@ -340,23 +338,6 @@ public class RoutingFeedbackWebsocket : IKeyed
service.Sessions.Broadcast(message);
}
- private void HandleHttpGet(object sender, HttpRequestEventArgs e)
- {
- var res = e.Response;
- res.ContentType = "text/html";
- res.ContentEncoding = Encoding.UTF8;
- res.StatusCode = 200;
-
- const string html = @"
-Essentials Routing Feedback
-
-Certificate Accepted
-You may close this tab and return to the configuration app.
-";
-
- res.WriteContent(Encoding.UTF8.GetBytes(html));
- }
-
private static X509Certificate2 LoadCert(string certPath, string certPassword)
{
return new X509Certificate2(certPath, certPassword, X509KeyStorageFlags.EphemeralKeySet);
@@ -408,32 +389,34 @@ public class RoutingFeedbackWebsocket : IKeyed
///
public class RoutingFeedbackClient : WebSocketBehavior
{
- private readonly RoutingFeedbackWebsocket _owner;
+ ///
+ /// Static reference to the owning instance.
+ /// Set before the server starts accepting connections.
+ ///
+ internal static RoutingFeedbackWebsocket Owner { get; set; }
///
/// Initializes a new instance of the class.
///
- /// The owning instance.
- public RoutingFeedbackClient(RoutingFeedbackWebsocket owner)
+ public RoutingFeedbackClient()
{
- _owner = owner;
}
///
protected override void OnOpen()
{
base.OnOpen();
- Debug.LogMessage(LogEventLevel.Information, "Routing feedback client connected from: {url}", _owner, Context.WebSocket.Url);
+ Debug.LogMessage(LogEventLevel.Information, "Routing feedback client connected from: {url}", Owner, Context.WebSocket.Url);
// Send full state snapshot to the newly connected client
try
{
- var snapshot = _owner.GetSnapshotMessage();
+ var snapshot = Owner.GetSnapshotMessage();
Send(snapshot);
}
catch (Exception ex)
{
- Debug.LogError(ex, "Error sending routing snapshot to client: {message}", _owner, ex.Message);
+ Debug.LogError(ex, "Error sending routing snapshot to client: {message}", Owner, ex.Message);
}
}
@@ -441,13 +424,13 @@ public class RoutingFeedbackClient : WebSocketBehavior
protected override void OnClose(CloseEventArgs e)
{
base.OnClose(e);
- Debug.LogMessage(LogEventLevel.Debug, "Routing feedback client disconnected: {code} {reason}", _owner, e.Code, e.Reason);
+ Debug.LogMessage(LogEventLevel.Debug, "Routing feedback client disconnected: {code} {reason}", Owner, e.Code, e.Reason);
}
///
protected override void OnError(WebSocketSharp.ErrorEventArgs e)
{
base.OnError(e);
- Debug.LogError(e.Exception, "Routing feedback client error: {message}", _owner, e.Message);
+ Debug.LogError(e.Exception, "Routing feedback client error: {message}", Owner, e.Message);
}
}