Skip to content

Instantly share code, notes, and snippets.

View Chandankkrr's full-sized avatar
🎯
Focusing

Chandan Rauniyar Chandankkrr

🎯
Focusing
View GitHub Profile
public async Task SendMessage(string x, string y)
{
await Clients.All.SendAsync("ReceiveMessage", Context.ConnectionId, x, y);
}
@Chandankkrr
Chandankkrr / index.js
Last active June 1, 2021 12:49
window.nextjs
window.nextjs = {
addMouseEventListener: function () {
window.addEventListener('mousemove', (e) => {
const data = {
X: e.clientX.toString(),
Y: e.clientY.toString(),
};
DotNet.invokeMethodAsync(
'NextJSConf.Client',
@Chandankkrr
Chandankkrr / index.razor
Created May 30, 2021 18:48
Mousemove event
[JSInvokable]
public static void CaptureMouseEvents(string data)
{
var cursorInfo = System.Text.Json.JsonSerializer.Deserialize<Cursor>(data);
func(cursorInfo);
}
public async Task SendMouseEvents(Cursor cursorInfo)
{
@Chandankkrr
Chandankkrr / index.razor
Created May 30, 2021 18:28
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();
<script>
const colors = [
'#f44336',
'#e91e63',
'#9c27b0',
'#673ab7',
'#3f51b5',
'#009688',
'#ffeb3b',
'#795548',
@Chandankkrr
Chandankkrr / index.razor
Created May 27, 2021 13:43
SignalR razor client
@page "/"
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager NavigationManager
@implements IAsyncDisposable
@inject IJSRuntime JSRuntime;
<div class="container py-4">
<div class="row align-items-md-stretch">
<div class="col-md-8" style="border: 1px solid white;">
<div class="h-100 p-5 text-white rounded-3">
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
namespace NextJSConf.Server.Hubs
{
public static class ConnectedClients
{
public static List<string> ConnectedClientIds = new List<string>();
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddGrpcClient<LocationData.LocationDataClient>(client =>
{
client.Address = new Uri("http://localhost:80");
});
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<LocationService>();
if (env.IsDevelopment())
{
endpoints.MapGrpcReflectionService();
}
@Chandankkrr
Chandankkrr / Mapbox.razor
Last active February 16, 2021 12:39
gRPC client - Razor page
@page "/mapbox"
@using Grpc.Core
@using GPRCStreaming
@using System.Diagnostics
@inject IJSRuntime JSRuntime;
@inject System.Net.Http.IHttpClientFactory _clientFactory
@inject GPRCStreaming.LocationData.LocationDataClient LocationDataClient