Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

userId - this can be device identifier or random guid/uuid.
When connection is established you can receive message about changed status of position

Code Block
  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:

Code Block
  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:

Code Block
{
    "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
}

...