Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created June 16, 2021 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/14377beff9912ba400599059ed4dece3 to your computer and use it in GitHub Desktop.
Save dcomartin/14377beff9912ba400599059ed4dece3 to your computer and use it in GitHub Desktop.
protected override async Task OnInitializedAsync()
{
var tokenResult = await _tokenProvider.RequestAccessToken();
tokenResult.TryGetToken(out var token);
_hubConnection = new HubConnectionBuilder()
.WithUrl(_navigationManager.ToAbsoluteUri("https://localhost:6001/customer/orderhub"), options =>
{
options.AccessTokenProvider = () => Task.FromResult(token.Value);
})
.Build();
_hubConnection.On("OrderBeingPrepared", async () =>
{
await GetOrderDetails();
StateHasChanged();
});
_hubConnection.On("OrderPickedUpForDelivery", async () =>
{
await GetOrderDetails();
StateHasChanged();
});
_hubConnection.On("OrderDelivered", async () =>
{
await GetOrderDetails();
StateHasChanged();
});
await _hubConnection.StartAsync();
await _hubConnection.InvokeAsync("WatchOrder", OrderId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment