Setting up SignalR communication for updates
We strongly recommend using the SignalR SDKs 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
:
{baseUrl}/queues/{queueId}/positions/{positionId}?userId=${userId}
Parameters
Parameter | Type | Description |
---|---|---|
userId | guid/uuid | A random GUID/UUID. |
Establishing Connection
Initialize and build the hub connection as shown:
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:
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: