...
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 |
---|
const positionUpdateHubMethodName = subscription.subscribe('position-update' hubConnection.on(hubMethodName, ({message: position }:any) => { position: Position }) => { const position if= JSON.parse(positionmessage) {as Position; const normalized =if normalizePosition(position).entities; { dispatchPosition({ type: loadPosition..fulfilled.type, payload: normalized }); } }); |
The position contains the following properties:
...