add(tools):添加signalR调试工具
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using IM_API.Interface.Services;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace IM_API.Hubs
|
||||
{
|
||||
public class ChatHub:Hub
|
||||
{
|
||||
private IJWTService _JWTService;
|
||||
public ChatHub(IJWTService jWTService)
|
||||
{
|
||||
_JWTService = jWTService;
|
||||
}
|
||||
|
||||
public override Task OnConnectedAsync()
|
||||
{
|
||||
var userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
int userId = int.Parse(userIdStr);
|
||||
Console.WriteLine(userId);
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
public async Task SendMessage(string user,string message)
|
||||
{
|
||||
await Clients.Caller.SendAsync("ReceiveMessage", "qwfqwfqw","test");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.21" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.21">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
using IM_API.Configs;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Models;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -42,7 +43,6 @@ namespace IM_API
|
||||
policy.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyOrigin();
|
||||
});
|
||||
});
|
||||
@@ -104,6 +104,8 @@ namespace IM_API
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseCors();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
@@ -120,6 +122,8 @@ namespace IM_API
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.MapHub<ChatHub>("/chat").RequireCors();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user