Realtime
Xams provides built-in support for real-time communication between server and client using SignalR.
Creating a Hub
Xams uses a single SignalR hub per browser window instance for optimal performance. You can create service-specific hubs using the ServiceHub
attribute and implementing the IServiceHub
interface.
Project/Hubs/ChatHub.cs
Hub Permissions
Hub access is controlled through role-based permissions.

Modifying hub permissions forces affected clients to reconnect, causing temporary disconnection.
The IServiceHub
interface defines four methods with specific permission requirements:
IServiceHub Interface
Client Implementation
The client connects to the hub using the appContext.signalR()
method, which returns a singleton SignalR connection for the browser window.
src/pages/Chat.tsx
Sending Messages from Services
Service classes (Actions, Jobs, or Service Logic) can send messages to clients using the HubSend
method, which invokes the hub's Send
method.
Project/Service/WidgetService.cs
The HubSend
method executes in a new database transaction, independent of the current service's transaction context.
The hub's Send
method processes the message:
Project/Hubs/ChatHub.cs
The Clients.All
property sends messages to all connected clients across the entire application, not just those connected to this specific hub. Use groups to target specific client subsets.
Authentication
SignalR authentication requires configuring JWT bearer token support in Program.cs
:
Project/Program.cs
The getAccessToken
function provides bearer tokens to both the useAuthRequest
hook and SignalR connections.
src/pages/_app.tsx
SignalR connections require access tokens to be passed via query string due to WebSocket limitations with headers.
Ensure getAccessToken
is ready before initializing SignalR connections: