Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>11.0.0-rc.3.2</Version>
<Version>11.0.0-rc.3.3</Version>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="11.0.2-beta04" />
<PackageReference Include="BootstrapBlazor" Version="11.1.0-rc.3.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public Task<bool> Heartbeat(ClientInfo client)
=> ConnectionHandler.ReportHeartbeatAsync(Context, client, services);

/// <summary>
/// <para lang="zh">查询在线连接快照,仅返回给调用方,不向消息订阅者广播;查询被禁用或调用方未获授权时返回 null</para>
/// <para lang="en">Queries a connection snapshot for the caller only, without broadcasting it to dispatch subscribers. Returns null when queries are disabled or the caller is not authorized.</para>
/// <para lang="zh">查询在线连接列表,仅返回给调用方,不向消息订阅者广播;查询被禁用或调用方未获授权时返回 null</para>
/// <para lang="en">Queries the online connections for the caller only, without broadcasting them to dispatch subscribers. Returns null when queries are disabled or the caller is not authorized.</para>
/// </summary>
public Task<ConnectionSnapshot?> GetConnectionSnapshot()
=> ConnectionHandler.GetSnapshotAsync(Context, options, services);
Expand Down
19 changes: 7 additions & 12 deletions src/middleware/BootstrapBlazor.Middleware/ConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ public static async Task<bool> ReportHeartbeatAsync(HubCallerContext context, Cl
return false;
}

if (client == null || string.IsNullOrWhiteSpace(client.Id) || client.Id.Length > 128 ||
!Enum.IsDefined(typeof(WebClientDeviceType), client.Device))
{
throw new HubException("Invalid connection heartbeat.");
}

var httpContext = context.GetHttpContext() ?? throw new HubException("The connection context is unavailable.");
client.Ip = httpContext.Connection.RemoteIpAddress.ToIPv4String();
client.UserName = context.User?.Identity is { IsAuthenticated: true } identity ? identity.Name : null;
Expand All @@ -47,6 +41,12 @@ public static async Task<bool> ReportHeartbeatAsync(HubCallerContext context, Cl
}

public static async Task<ConnectionSnapshot?> GetSnapshotAsync(HubCallerContext context, BootstrapBlazorHubOptions options, IServiceProvider services)
{
var service = await GetConnectionServiceAsync(context, options, services);
return service == null ? null : new ConnectionSnapshot(service.Count, service.Connections);
}

private static async Task<IConnectionService?> GetConnectionServiceAsync(HubCallerContext context, BootstrapBlazorHubOptions options, IServiceProvider services)
{
if (!options.EnableConnectionSnapshots)
{
Expand All @@ -65,11 +65,6 @@ public static async Task<bool> ReportHeartbeatAsync(HubCallerContext context, Cl
}
}

var service = services.GetRequiredService<IConnectionService>();
return new ConnectionSnapshot
{
Count = service.Count,
Connections = service.Connections
};
return services.GetRequiredService<IConnectionService>();
}
}
Loading