warren
(Warren Buckley)
March 15, 2025, 7:28pm
1
Hello gang
Has anyone done anything specifically with SignalR with Bellissima yet?
I have seen this PR and yet to fully get my head round it and was wondering if this PR is intended for HQ/Core use only or is also planned to be used as an extension point?
Github PR
v15/dev
← v15/feature/notification-hub
opened 01:32PM - 11 Dec 24 UTC
Creates a SignalR hub that relays server events to the backoffice frontend.
… ## Terminology
* ServerEvent - Some event that has happened on the server, the default events map to the notifications
* EventSource - The source of the event, I.E. "Document", "Media", etc. this is just a string and can be anything
* EventType - The type of event, for instance, Created, Deleted, etc. This is also just a string and can be anything
* Routing - In the context of server events routing means ensuring that the event gets to the connections which are authorized for it.
## Details
Each event consists of:
* EventType
* EventSource
* Key - The key of the entity the event is about
These default events are
* Created
* Updated
* Deleted
* Trashed
The events come from a single hub using a single method `notify`. Upon connecting, the user is authorized to receive certain events. This means that users with only `DocumentTreeAccess` will only see document events, and so on.
Additionally, it's also possible to notify a specific user. This still goes through the `notify` method and notifies all the users' connections. It is used to notify a specific user that they've been updated.
Events are routed using the "group" concept in SignalR, every event source is its own group. An `IEventSourceAuthorizer` is then used to authorize a user (using a ClaimsPrincipal) for one or more event sources (groups), if a user is approved it's added to the group. This means that an authorizer is required for each event source for the routing to be used. If authorization is not required the `IServerEventRouter.BroadcastEventAsync` method can instead be used, this sends the event to ***all*** connected users.
If a user is updated, the authorization is re-run ensuring that any permission changes are reflected in the event routing.
This means to extend this you must:
1. Implement an `IEventSourceAuthorizer`
2. Add it to the `EventSourceAuthorizerCollection`
3. Create and route an event using `IServerEventRouter.RouteEventAsync`, this can be done from anywhere, but a notification handler is an ideal place
If you want to authorize using a standard .Net Core policy you can use the `EventSourcePolicyAuthorizer` abstract class, and specify which event sources should be authorized using which policy.
**Note that the event source authorized by the `IEventSourceAuthorizer` must be the same as the one your `ServeEvent` for the event to be routed anywhere**
Example of adding event authorizer
```C#
private static IUmbracoBuilder AddAuthorizers(this IUmbracoBuilder builder)
{
builder.EventSourceAuthorizers()
.Append<DocumentEventAuthorizer>();
return builder;
}
```
## Testing
* Extract this zip file in you wwwroot folder: [js.zip](https://github.com/user-attachments/files/18209196/js.zip)
* Create a simple content node
* In the template for the content node add the following HTML:
```html
@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@{
Layout = null;
}
<div class="container">
<h1>Messages:</h1>
<div class="row p-1">
<div class="col-6">
<ul id="messagesList"></ul>
</div>
</div>
</div>
<script src="~/js/signalr/dist/browser/signalr.js"></script>
<script src="~/js/event.js"></script>
```
* Login to the backoffice
* Copy your auth token:

* Replace `YOUR-ACCESS-TOKEN-HERE` with that token in the `wwwroot/js/event.js` file
* Go the the front page (or hard reset it)
* A SignalR connection should now be active
* Do actions like creating, updating, deleting, content, media, data types, etc. and verify that they're displayed on the front page
**Note: The auth token is short lived, so it may expire**
LuukPeters
(Luuk Peters (Proud Nerds))
March 15, 2025, 11:06pm
2
KevinJump
(Kevin Jump 🐶🐖🍞)
March 17, 2025, 9:39am
3
Hi Warren,
I asked the same on discord when i saw it, I think the answer was ‘no firm’ plans from the front end team at the moment, but the feature is there to use.
I have done some code to use this, it basically sends the guid and type of an item for the events, which lets you know they have happened, but probibly needs a bit more for you to do the usefull stuff like “dave has just saved this” (unless you just use the signalR to then ask the Management API for info about this thing.
warren
(Warren Buckley)
March 17, 2025, 11:26am
4
Heya Kevin
Thanks so its more a generic thing to be notified of key/uniques having some action performed on them.
Sounds like for me I may need to roll my own. Was just wondering if there was any use/benefits of using what has been put in place.
Cheers
KevinJump
(Kevin Jump 🐶🐖🍞)
March 18, 2025, 2:06pm
5
I think you can piggy back on it and add your own ‘ServerEvents’ so you don’t have to start your own hub (which to be honest isn’t the hard bit ) but i haven’t really looked into it much other than noting that’s in the source code
1 Like
warren
(Warren Buckley)
March 18, 2025, 4:52pm
6
Thanks Kevin,
I need to spend some time later this week to investigate. It would be good to do some piggy backing if Umbraco does stuff rather than add more stuff myself.
Will do some stuff soon and report back or perhaps I may do one of those Discord Mob programming sessions to see what can be done.