v14: Implement backoffice signalR hub (#16723)

* Implement backoffice signalR hub

* Fix test

* Refactor to use object instead of string

* Update src/Umbraco.Cms.Api.Management/Routing/BackofficeHub.cs

Co-authored-by: Bjarke Berg <mail@bergmania.dk>

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Nikolaj Geisle
2024-07-02 17:14:43 +02:00
committed by GitHub
parent 46acd51759
commit 6069610f83
4 changed files with 11 additions and 4 deletions

View File

@@ -7,8 +7,6 @@ using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web.Mvc;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Cms.Web.Common.Routing;
using Umbraco.Extensions;
@@ -54,8 +52,8 @@ public sealed class BackOfficeAreaRoutes : IAreaRoutes
case RuntimeLevel.Install:
case RuntimeLevel.Upgrade:
case RuntimeLevel.Run:
MapMinimalBackOffice(endpoints);
endpoints.MapHub<BackofficeHub>(_umbracoPathSegment + Constants.Web.BackofficeSignalRHub);
break;
case RuntimeLevel.BootFailed:
case RuntimeLevel.Unknown:

View File

@@ -0,0 +1,8 @@
using Microsoft.AspNetCore.SignalR;
namespace Umbraco.Cms.Api.Management.Routing;
public class BackofficeHub : Hub
{
public async Task SendPayload(object payload) => await Clients.All.SendAsync("payloadReceived", payload);
}

View File

@@ -56,6 +56,7 @@ public static partial class Constants
/// The "base" path to the Management API
/// </summary>
public const string ManagementApiPath = "/management/api/";
public const string BackofficeSignalRHub = "/backofficeHub";
public static class Routing
{

View File

@@ -45,7 +45,7 @@ public class BackOfficeAreaRoutesTests
var endpoints = new TestRouteBuilder();
routes.CreateRoutes(endpoints);
Assert.AreEqual(1, endpoints.DataSources.Count);
Assert.AreEqual(2, endpoints.DataSources.Count);
var route = endpoints.DataSources.First();
Assert.AreEqual(2, route.Endpoints.Count);