Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created June 16, 2021 21:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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