Setup SignalR communication about position.
We strongly recommend using the SignalR SDKs .
For negotiation we use HubConnectionBuilder
. The following negotiate endpoint we provide in withUrl
method:
Negotiate endpoint
...
for robust and efficient client-server communication.
To establish a connection, utilize the HubConnectionBuilder
for negotiation as described below:
Negotiate endpoint
Utilize the following endpoint with the withUrl
method of HubConnectionBuilder
:
Code Block |
---|
{baseUrl}/queues/{queueId}/positions/{positionId}?userId=${userId} |
Parameters
Parameter | Type | Description |
---|---|---|
userId |
...
When connection is established you can receive message about changed status of position:
...
guid/uuid | A random GUID/UUID. |
Establishing Connection
Initialize and build the hub connection as shown:
Code Block |
---|
let hubConnectionBuilder = new signalR.HubConnectionBuilder()
.withUrl(url, options);
const hubConnection = hubConnectionBuilder.build();
hubConnection
.start()
.then(() => console.log('Queue service connection is established'))
.catch((err) => {
console.error(err);
throw err;
});
|
Subscription to Position Updates
Once the connection is established, subscribe to updates for the position-update
hub method:
Code Block |
---|
const positionUpdateHubMethodName = 'position-update'
hubConnection.on(positionUpdateHubMethodName, (message: any) => {
const { position } = JSON.parse(message);
if (position) {
...
}
}); |
Message Structure
The message from the position-update
contains the following properties:
Code Block |
---|
{ "position": { "id": "5387920d-dfdd-4904-8a51-3f007effcffa", "_ts": 1605613557, "status": "notified", "priority": 0, "location": null, "label": "A3", "customerInfo": [ "Jörgen", "Svensson", "220000191010512345" ], "type": "anonymous", "queue": "c179a3a2-9fd7-4e12-96e7-19d9e957e094", "createdAt": "2020-11-17T11:45:57.114Z", "numberInTheQueue": 6 } } |