10 changed files with 23 additions and 174 deletions
@ -1,3 +0,0 @@ |
|||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|
||||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|
||||
</Weavers> |
|
||||
@ -1,30 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|
||||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|
||||
<xs:element name="Weavers"> |
|
||||
<xs:complexType> |
|
||||
<xs:all> |
|
||||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|
||||
<xs:complexType> |
|
||||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|
||||
</xs:complexType> |
|
||||
</xs:element> |
|
||||
</xs:all> |
|
||||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|
||||
<xs:annotation> |
|
||||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|
||||
</xs:annotation> |
|
||||
</xs:attribute> |
|
||||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|
||||
<xs:annotation> |
|
||||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|
||||
</xs:annotation> |
|
||||
</xs:attribute> |
|
||||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|
||||
<xs:annotation> |
|
||||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|
||||
</xs:annotation> |
|
||||
</xs:attribute> |
|
||||
</xs:complexType> |
|
||||
</xs:element> |
|
||||
</xs:schema> |
|
||||
@ -1,19 +0,0 @@ |
|||||
<Project Sdk="Microsoft.NET.Sdk"> |
|
||||
|
|
||||
<Import Project="..\..\..\configureawait.props" /> |
|
||||
<Import Project="..\..\..\common.props" /> |
|
||||
|
|
||||
<PropertyGroup> |
|
||||
<TargetFramework>net6.0</TargetFramework> |
|
||||
<RootNamespace /> |
|
||||
</PropertyGroup> |
|
||||
|
|
||||
<ItemGroup> |
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.SignalR" Version="$(VoloAbpPackageVersion)" /> |
|
||||
</ItemGroup> |
|
||||
|
|
||||
<ItemGroup> |
|
||||
<ProjectReference Include="..\LINGYUN.Abp.RealTime\LINGYUN.Abp.RealTime.csproj" /> |
|
||||
</ItemGroup> |
|
||||
|
|
||||
</Project> |
|
||||
@ -1,12 +0,0 @@ |
|||||
using Volo.Abp.AspNetCore.SignalR; |
|
||||
using Volo.Abp.Modularity; |
|
||||
|
|
||||
namespace LINGYUN.Abp.RealTime.SignalR |
|
||||
{ |
|
||||
[DependsOn( |
|
||||
typeof(AbpRealTimeModule), |
|
||||
typeof(AbpAspNetCoreSignalRModule))] |
|
||||
public class AbpRealTimeSignalRModule : AbpModule |
|
||||
{ |
|
||||
} |
|
||||
} |
|
||||
@ -1,98 +0,0 @@ |
|||||
using LINGYUN.Abp.RealTime.Client; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
using System; |
|
||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.AspNetCore.SignalR; |
|
||||
using Volo.Abp.AspNetCore.WebClientInfo; |
|
||||
|
|
||||
namespace LINGYUN.Abp.RealTime.SignalR |
|
||||
{ |
|
||||
public abstract class OnlineClientHubBase : AbpHub, IClient |
|
||||
{ |
|
||||
protected IWebClientInfoProvider WebClientInfoProvider => LazyServiceProvider.LazyGetRequiredService<IWebClientInfoProvider>(); |
|
||||
protected IOnlineClientManager OnlineClientManager => LazyServiceProvider.LazyGetRequiredService<IOnlineClientManager>(); |
|
||||
|
|
||||
public override async Task OnConnectedAsync() |
|
||||
{ |
|
||||
await base.OnConnectedAsync(); |
|
||||
|
|
||||
IOnlineClient onlineClient = CreateClientForCurrentConnection(); |
|
||||
OnlineClientManager.Add(onlineClient); |
|
||||
|
|
||||
await OnConnectedAsync(onlineClient); |
|
||||
} |
|
||||
|
|
||||
public async Task OnConnectedAsync(IOnlineClient client) |
|
||||
{ |
|
||||
Logger.LogDebug("A client is connected: " + client.ToString()); |
|
||||
|
|
||||
// 角色添加进组
|
|
||||
foreach (var role in client.Roles) |
|
||||
{ |
|
||||
await Groups.AddToGroupAsync(client.ConnectionId, role); |
|
||||
} |
|
||||
|
|
||||
await OnClientConnectedAsync(client); |
|
||||
} |
|
||||
|
|
||||
public override async Task OnDisconnectedAsync(Exception exception) |
|
||||
{ |
|
||||
// 从通讯组移除
|
|
||||
var onlineClient = OnlineClientManager.GetByConnectionIdOrNull(Context.ConnectionId); |
|
||||
await OnDisconnectedAsync(onlineClient); |
|
||||
|
|
||||
await base.OnDisconnectedAsync(exception); |
|
||||
} |
|
||||
|
|
||||
public async Task OnDisconnectedAsync(IOnlineClient client) |
|
||||
{ |
|
||||
if (client != null) |
|
||||
{ |
|
||||
try |
|
||||
{ |
|
||||
// 角色添加进组
|
|
||||
foreach (var role in client.Roles) |
|
||||
{ |
|
||||
await Groups.RemoveFromGroupAsync(client.ConnectionId, role); |
|
||||
} |
|
||||
|
|
||||
Logger.LogDebug("A client is disconnected: " + client); |
|
||||
// 移除在线客户端
|
|
||||
OnlineClientManager.Remove(Context.ConnectionId); |
|
||||
|
|
||||
await OnClientDisconnectedAsync(client); |
|
||||
} |
|
||||
catch (Exception ex) |
|
||||
{ |
|
||||
Logger.LogWarning(ex.ToString(), ex); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
protected virtual IOnlineClient CreateClientForCurrentConnection() |
|
||||
{ |
|
||||
return new OnlineClient( |
|
||||
Context.ConnectionId, |
|
||||
WebClientInfoProvider.ClientIpAddress, |
|
||||
CurrentTenant.Id, |
|
||||
CurrentUser.Id) |
|
||||
{ |
|
||||
ConnectTime = Clock.Now, |
|
||||
UserName = CurrentUser.UserName, |
|
||||
UserAccount = CurrentUser.UserName, |
|
||||
Roles = CurrentUser.Roles ?? new string[0], |
|
||||
Properties = Context.Items |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
protected virtual Task OnClientConnectedAsync(IOnlineClient client) |
|
||||
{ |
|
||||
return Task.CompletedTask; |
|
||||
} |
|
||||
|
|
||||
protected virtual Task OnClientDisconnectedAsync(IOnlineClient client) |
|
||||
{ |
|
||||
return Task.CompletedTask; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue