From f61b4ea22930d3c5348238b727d44f2a8cf89add Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Wed, 23 Aug 2023 08:16:53 +0100 Subject: [PATCH] V12/generic hub (#535) * Add ability to pass hub url to signalR hub (making it a bit more generic) * Add obsolete marker to config changes for v13 --- uSync.BackOffice/Configuration/uSyncSettings.cs | 1 + uSync.BackOffice/Hubs/uSyncHubRoutes.cs | 4 +++- .../App_Plugins/uSync/usync.hub.js | 12 ++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/uSync.BackOffice/Configuration/uSyncSettings.cs b/uSync.BackOffice/Configuration/uSyncSettings.cs index 2ad47d52..fab11231 100644 --- a/uSync.BackOffice/Configuration/uSyncSettings.cs +++ b/uSync.BackOffice/Configuration/uSyncSettings.cs @@ -96,6 +96,7 @@ public class uSyncSettings /// location of SignalR hub script /// [DefaultValue("")] + [Obsolete("Will remove the option to move the route in v13")] public string SignalRRoot { get; set; } = string.Empty; /// diff --git a/uSync.BackOffice/Hubs/uSyncHubRoutes.cs b/uSync.BackOffice/Hubs/uSyncHubRoutes.cs index 94fb09d2..b68aa5a8 100644 --- a/uSync.BackOffice/Hubs/uSyncHubRoutes.cs +++ b/uSync.BackOffice/Hubs/uSyncHubRoutes.cs @@ -15,7 +15,7 @@ namespace uSync.BackOffice.Hubs { /// - /// Handles SignlarR routes for uSync + /// Handles SignalR routes for uSync /// public class uSyncHubRoutes : IAreaRoutes { @@ -33,6 +33,7 @@ public uSyncHubRoutes( { _runtimeState = runtimeState; +#pragma warning disable CS0618 // Type or member is obsolete if (!string.IsNullOrWhiteSpace(uSyncSettings.Value?.SignalRRoot)) { _umbracoPathSegment = uSyncSettings.Value.SignalRRoot; @@ -41,6 +42,7 @@ public uSyncHubRoutes( { _umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment); } +#pragma warning restore CS0618 // Type or member is obsolete } /// diff --git a/uSync.Backoffice.Assets/App_Plugins/uSync/usync.hub.js b/uSync.Backoffice.Assets/App_Plugins/uSync/usync.hub.js index 6b6c3cc6..b580e19e 100644 --- a/uSync.Backoffice.Assets/App_Plugins/uSync/usync.hub.js +++ b/uSync.Backoffice.Assets/App_Plugins/uSync/usync.hub.js @@ -18,6 +18,10 @@ ////////////// function initHub(callback) { + initializeHub(Umbraco.Sys.ServerVariables.uSync.signalRHub, callback); + } + + function initializeHub(url, callback) { callbacks.push(callback); @@ -34,7 +38,7 @@ .then(function () { while (callbacks.length) { var cb = callbacks.pop(); - hubSetup(cb); + hubSetup(url, cb); } starting = false; }); @@ -42,17 +46,17 @@ else { while (callbacks.length) { var cb = callbacks.pop(); - hubSetup(cb); + hubSetup(url, cb); } starting = false; } } } - function hubSetup(callback) { + function hubSetup(url, callback) { $.connection = new signalR.HubConnectionBuilder() - .withUrl(Umbraco.Sys.ServerVariables.uSync.signalRHub) + .withUrl(url) .withAutomaticReconnect() .configureLogging(signalR.LogLevel.Warning) .build();