**Initialize React Vite project with basic setup**
Add initial project structure including React, Vite, TailwindCSS, and Syncfusion dependencies. Configure tooling with ESLint, TypeScript, and Tailwind plugins. Set up `.gitignore`, Syncfusion themes, and example components for demonstration purposes.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Api.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -8,6 +9,7 @@ builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddSignalR();
|
||||
builder.Services.AddHostedService<SignalRSendService>();
|
||||
builder.Services.AddSingleton<IUserIdProvider, UserProvider>();
|
||||
builder.Services.AddOpenApiDocument(config =>
|
||||
{
|
||||
config.Title = "NSwag Demo API";
|
||||
|
||||
@@ -12,16 +12,16 @@ namespace Api.SignalR
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
// For example, wait 10 seconds between messages.
|
||||
await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken);
|
||||
await Task.Delay(TimeSpan.FromSeconds(2), stoppingToken);
|
||||
|
||||
// Log or do any work here.
|
||||
logger.LogInformation("Background service sending message at: {Time}", DateTime.Now);
|
||||
|
||||
// Send a message to all connected clients.
|
||||
await hubContext.Clients.All.SendAsync(
|
||||
await hubContext.Clients.User("user1234").SendAsync(
|
||||
"ReceiveMessage", // This is the client method name.
|
||||
"Background Service", // Example sender.
|
||||
"Hello from the background task!", // The message.
|
||||
$"Hello from the background task at {DateTime.Now:F}", // The message.
|
||||
stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
14
Api/SignalR/UserProvider.cs
Normal file
14
Api/SignalR/UserProvider.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Api.SignalR
|
||||
{
|
||||
public class UserProvider : IUserIdProvider
|
||||
{
|
||||
public string GetUserId(HubConnectionContext connection)
|
||||
{
|
||||
// Extract the "userId" query parameter from the HTTP context.
|
||||
var httpContext = connection.GetHttpContext();
|
||||
return httpContext?.Request.Query["userId"].FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user