SignalR
The Notification component of Portos API uses SignalR to provide real-time updates to client applications.
System-defined events
Portos API triggers following system-defined events, which can be handled in client applications:
Event | Event name | Description |
---|---|---|
Resource changed |
| Raised when resource is changed (created, updated or deleted). |
License activated |
| Raised when Portos license is activated. |
Receiving Events from Portos API
To receive events from the Portos API, the client application must follow these steps:
Configure authentication when communicating with SignalR server.
Register an event Handler: specify the client application method to invoke when a notification is sent from the Portos API.
Start the connection to SignalR server.
Subscribe to Events using the
Subscribe
method, so the Portos API will deliver notifications to the client application.
The code examples below uses JavaScript and Microsoft's SignalR library. You can install it using npm:
Client authentication
When communicating with SignalR server, client application must be authenticated, as described in Authentication section. Obtained accces token must be used when communication with notification server.
Register Event Handler
Use the connection.on
method to subscribe to the notification events. When a notification is received, the callback function will be executed, and you can handle the notification (e.g., update the UI).
The incoming notification is represented by Notification
class, described below.
Notification
Property name | Type | Description |
---|---|---|
|
| Event name, as listed in System-defined events. |
| Information about sender, who sends the message (usually, the server/API). | |
|
| Optional notification reference identifier. |
|
| "Created At" ISO8601-formatted string representing date and time of notification creation. |
|
| "Expires At" Optional ISO8601-formatted string representing date and time of notification expiration. |
|
| The notification payload. Based on event, payload may vary. |
NotificationSender
Property name | Type | Description |
---|---|---|
|
| Connection identifier. |
| Information about sender, who performs action resulting in given event. |
NotificationSenderUserIdentity
Property name | Type | Description |
---|---|---|
|
| Unique user name or "System" for system events. |
|
| Name of device, on which user operates on. Or "System" for system events. |
|
| Feature name. Specified if source of event is not user, but system module (feature), a.k.a "virtual user". |
ResourceChangedNotificationPayload
Property name | Type | Description |
---|---|---|
| ||
|
| One of system-defined resource names. |
|
| Numeric identifier for resource action. 1 = Created 2 = Updated 3 = Deleted |
| Information about changed resource. | |
|
| Collection of affected resources. |
UserIdentity
Property name | Type | Description |
---|---|---|
|
| Unique user identifier. |
|
| User display name. |
|
| Name of "feature" (has value only for virtual users). |
ResourceInfo
Property name | Type | Description |
---|---|---|
|
| Unique resource identifier (e.g. database ID). |
|
| |
|
| Version of resource. |
Example payload for resource changed notification:
Start the connection
To start the connection, await the result of the start
method call.
Subscribe to Events
To subscribe to Portos events, a client application must send a "Subscribe" message containing a payload with the subscription details. In the payload, the client application specifies which system-defined events to subscribe to.
Subscribe to Resource Changed Event
To subscribe to resource change events, your client application must set portos.resources.changed
in the payload property's e
(event name). Optionally, you can also specify a collection of resources. Please refer to the table below:
Property name | Type | Description |
---|---|---|
|
| The event name. Set to |
| Optional collection of resources that is client application subscribing to. Leave empty to subscribe to all resources. |
SubscriptionRequestResource
Property name | Type | Description |
---|---|---|
|
| One of system-defined resource names. |
|
| Optional collection of actions that is client application subscribing to. Leave empty to subscribe to all actions. Allowed values:
- |
Example:
Subscribe to License activated event
To subscribe to license activated event, your client application must set portos.licence.activated
in the payload property e
(event name).
Example:
Unsubscribe from Events
To unsubscribe, invoke the Unsubscribe
method with the same parameters used for event subscription.
Last updated