diff --git a/WickerNetwork.cs b/WickerNetwork.cs index cd9de6e..f8c9060 100644 --- a/WickerNetwork.cs +++ b/WickerNetwork.cs @@ -23,7 +23,7 @@ public class WickerNetwork private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); private const string COMMANDS_PATH = "/commands"; - private const string GAME_VARIABLES_PATH = "/game-variables"; + private const string HEARTBEAT_PATH = "/heartbeat"; private const string FAVICON_PATH = "/favicon.ico"; private const string INDEX_URL = @"https://raw.githubusercontent.com/derekShaheen/WickerREST/main/web/index.html"; private const string FAVICON_URL = @"https://raw.githubusercontent.com/derekShaheen/WickerREST/main/web/resources/favicon.ico"; @@ -120,24 +120,9 @@ private async void HandleRequests(CancellationToken cancellationToken) { ServeCommandHandlers(response); } - else if (request.Url.AbsolutePath == GAME_VARIABLES_PATH) + else if (request.Url.AbsolutePath == HEARTBEAT_PATH) { - if (Commands.Instance.GameVariableMethods != null && Commands.Instance.GameVariableMethods.Count > 0) - { - - var variableValues = Commands.Instance.GameVariableMethods.Select(kvp => new - { - VariableName = kvp.Key, - Value = kvp.Value?.Invoke()?.ToString() - }).ToDictionary(kvp => kvp.VariableName, kvp => kvp.Value); - - var json = JsonConvert.SerializeObject(variableValues); - SendResponse(response, json, statusCode: 200, contentType: "application/json"); - } - else - { - SendResponse(response, "No game variables found.", statusCode: 200); - } + ServeHeartbeat(response); } else { @@ -162,6 +147,26 @@ private async void HandleRequests(CancellationToken cancellationToken) } } + private void ServeHeartbeat(HttpListenerResponse response) + { + if (Commands.Instance.GameVariableMethods != null && Commands.Instance.GameVariableMethods.Count > 0) + { + + var variableValues = Commands.Instance.GameVariableMethods.Select(kvp => new + { + VariableName = kvp.Key, + Value = kvp.Value?.Invoke()?.ToString() + }).ToDictionary(kvp => kvp.VariableName, kvp => kvp.Value); + + var json = JsonConvert.SerializeObject(variableValues); + SendResponse(response, json, statusCode: 200, contentType: "application/json"); + } + else + { + SendResponse(response, "No game variables found.", statusCode: 200); + } + } + private void ServeCommandHandlers(HttpListenerResponse response) { if (Commands.Instance.CommandHandlers != null && Commands.Instance.CommandHandlers.Count > 0) diff --git a/web/index.html b/web/index.html index c283e98..eaf0d6f 100644 --- a/web/index.html +++ b/web/index.html @@ -342,13 +342,13 @@