Skip to content

Instantly share code, notes, and snippets.

@dcomartin

dcomartin/SignalRClient.cs Secret

Created Jun 16, 2021
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