Skip to content

Commit

Permalink
V12/generic hub (#535)
Browse files Browse the repository at this point in the history
* Add ability to pass hub url to signalR hub (making it a bit more generic)

* Add obsolete marker to config changes for v13
  • Loading branch information
KevinJump authored Aug 23, 2023
1 parent e826ede commit f61b4ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions uSync.BackOffice/Configuration/uSyncSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class uSyncSettings
/// location of SignalR hub script
/// </summary>
[DefaultValue("")]
[Obsolete("Will remove the option to move the route in v13")]
public string SignalRRoot { get; set; } = string.Empty;

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion uSync.BackOffice/Hubs/uSyncHubRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace uSync.BackOffice.Hubs
{
/// <summary>
/// Handles SignlarR routes for uSync
/// Handles SignalR routes for uSync
/// </summary>
public class uSyncHubRoutes : IAreaRoutes
{
Expand All @@ -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;
Expand All @@ -41,6 +42,7 @@ public uSyncHubRoutes(
{
_umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment);
}
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
Expand Down
12 changes: 8 additions & 4 deletions uSync.Backoffice.Assets/App_Plugins/uSync/usync.hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
//////////////

function initHub(callback) {
initializeHub(Umbraco.Sys.ServerVariables.uSync.signalRHub, callback);
}

function initializeHub(url, callback) {

callbacks.push(callback);

Expand All @@ -34,25 +38,25 @@
.then(function () {
while (callbacks.length) {
var cb = callbacks.pop();
hubSetup(cb);
hubSetup(url, cb);
}
starting = false;
});
}
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();
Expand Down

0 comments on commit f61b4ea

Please sign in to comment.