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
2 changes: 1 addition & 1 deletion src/SignalR/server/Core/src/Internal/HubCallerClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ISingleClientProxy Client(string connectionId)
{
if (!InvokeAllowed)
{
return new NoInvokeSingleClientProxy(_hubClients.Client(_connectionId));
return new NoInvokeSingleClientProxy(_hubClients.Client(connectionId));
}
return new SingleClientProxy(_hubClients.Client(connectionId), this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1396,3 +1396,15 @@ public void ManyParams(int a1, string a2, bool a3, float a4, string a5, int a6,
int a64, [FromService] Service1 service)
{ }
}

public class OnConnectedSendToClientHub : Hub
{
public override async Task OnConnectedAsync()
{
string id = Context.GetHttpContext()?.Request.Query["client"] ?? string.Empty;
if (!string.IsNullOrEmpty(id))
{
await Clients.Client(id).SendAsync("Test", 1);
}
}
}
33 changes: 33 additions & 0 deletions src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4891,6 +4891,39 @@ public void TooManyParametersWithServiceThrows()
() => serviceProvider.GetService<HubConnectionHandler<TooManyParamsHub>>());
}

[Fact]
public async Task SendToAnotherClientFromOnConnectedAsync()
{
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(provider =>
{
provider.AddSignalR(options =>
{
options.EnableDetailedErrors = true;
});
});
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<OnConnectedSendToClientHub>>();

using (var client1 = new TestClient())
using (var client2 = new TestClient())
{
var httpContext = new DefaultHttpContext();
httpContext.Request.QueryString = new QueryString($"?client={client1.Connection.ConnectionId}");
var feature = new TestHttpContextFeature
{
HttpContext = httpContext
};
client2.Connection.Features.Set<IHttpContextFeature>(feature);

var connectionHandlerTask = await client1.ConnectAsync(connectionHandler).DefaultTimeout();
_ = await client2.ConnectAsync(connectionHandler).DefaultTimeout();

var message = Assert.IsType<InvocationMessage>(await client1.ReadAsync().DefaultTimeout());
Assert.Single(message.Arguments);
Assert.Equal(1L, message.Arguments[0]);
Assert.Equal("Test", message.Target);
}
}

private class CustomHubActivator<THub> : IHubActivator<THub> where THub : Hub
{
public int ReleaseCount;
Expand Down