Skip to content

Instantly share code, notes, and snippets.

@Chandankkrr
Created May 30, 2021 18:28
Show Gist options
  • Select an option

  • Save Chandankkrr/b2f2113b759ac92e44e320b4adc865ec to your computer and use it in GitHub Desktop.

Select an option

Save Chandankkrr/b2f2113b759ac92e44e320b4adc865ec to your computer and use it in GitHub Desktop.
OnInitializedAsync
protected override async Task OnInitializedAsync()
{
hubConnection = new HubConnectionBuilder()
.WithUrl(NavigationManager.ToAbsoluteUri("/clienthub"))
.Build();
hubConnection.On<string, string, string>("ReceiveMessage", (connectionId, x, y) =>
{
JSRuntime.InvokeVoidAsync("nextjs.updateCursor", connectionId, x, y);
StateHasChanged();
});
hubConnection.On<string, int>("UserConnected", (connectionId, connectedUserIdsCount) =>
{
connectedUsersCount = connectedUserIdsCount;
JSRuntime.InvokeVoidAsync("nextjs.onUserConnected", connectionId);
StateHasChanged();
});
hubConnection.On<string, int>("UserDisconnected", (connectionId, connectedUserIdsCount) =>
{
connectedUsersCount = connectedUserIdsCount;
JSRuntime.InvokeVoidAsync("nextjs.onUserDisconnected", connectionId);
StateHasChanged();
});
hubConnection.On<List<string>>("LoadAllConnectedUsers", (connectedUserIds) =>
{
connectedUsersCount = connectedUserIds.Count;
JSRuntime.InvokeVoidAsync("nextjs.loadAllConnectedUsers", connectedUserIds);
StateHasChanged();
});
func = new Func<Cursor, Task>((cursor) => SendMouseEvents(cursor));
await hubConnection.StartAsync();
await JSRuntime.InvokeVoidAsync("nextjs.addMouseEventListener");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment