Setup SignalR communication about position.
We strongly recommend using SignalR SDKs.
For negotiation we use HubConnectionBuilder
. The following negotiate endpoint we provide in withUrl
method:
Negotiate endpoint
https://ombori-queue-dev.azure-api.net/api/organizations/xyz/queues/c179a3a2-9fd7-4e12-96e7-19d9e957e094/positions/5387920d-dfdd-4904-8a51-3f007effcffa?userId=${userId}
userId - this can be device identifier or random guid/uuid.
let hubConnectionBuilder = new signalR.HubConnectionBuilder() .withUrl(url, options) // - https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client?view=aspnetcore-3.1#reconnect-clients .withAutomaticReconnect({ nextRetryDelayInMilliseconds: (retryContext) => { const retryInSeconds = retryContext.previousRetryCount < 5 ? Math.pow(2, retryContext.previousRetryCount) : maxRetryDelayInSeconds; console.log(`Automatic reconnect retry, reconnecting in: ${retryInSeconds}`); return retryInSeconds * 1000; }, }); const hubConnection = hubConnectionBuilder.build(); const start = () => { makeRetryableFetch(() => { return hubConnection .start() .then(() => console.log('Queue service connection is established')) .catch((err) => { console.error(err); throw err; }); }); };
When connection is established you need to subscribe for specific hubMethodName. In our case it is position-update
:
subscription.subscribe('position-update', ({ position }: { position: Position }) => { if (position) { const normalized = normalizePosition(position).entities; dispatchPosition({ type: loadPosition.fulfilled.type, payload: normalized }); } });
The position contains the following properties:
{ "id": "5387920d-dfdd-4904-8a51-3f007effcffa", "_ts": 1605613557, "status": "notified", "priority": 0, "location": null, "label": "A3", "customerInfo": [ "Jörgen", "Svensson", "2200001910105" ], "type": "anonymous", "queue": "c179a3a2-9fd7-4e12-96e7-19d9e957e094", "createdAt": "2020-11-17T11:45:57.114Z", "numberInTheQueue": 6 }