Others in Group (#1230)
This commit is contained in:
parent
1a842e92ec
commit
c8bd72be36
|
|
@ -20,6 +20,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
public dynamic Client(string connectionId) => new DynamicClientProxy(_clients.Client(connectionId));
|
public dynamic Client(string connectionId) => new DynamicClientProxy(_clients.Client(connectionId));
|
||||||
public dynamic Group(string groupName) => new DynamicClientProxy(_clients.Group(groupName));
|
public dynamic Group(string groupName) => new DynamicClientProxy(_clients.Group(groupName));
|
||||||
public dynamic GroupExcept(string groupName, IReadOnlyList<string> excludedIds) => new DynamicClientProxy(_clients.GroupExcept(groupName, excludedIds));
|
public dynamic GroupExcept(string groupName, IReadOnlyList<string> excludedIds) => new DynamicClientProxy(_clients.GroupExcept(groupName, excludedIds));
|
||||||
|
public dynamic OthersInGroup(string groupName) => new DynamicClientProxy(_clients.OthersInGroup(groupName));
|
||||||
public dynamic Others => new DynamicClientProxy(_clients.Others);
|
public dynamic Others => new DynamicClientProxy(_clients.Others);
|
||||||
public dynamic User(string userId) => new DynamicClientProxy(_clients.User(userId));
|
public dynamic User(string userId) => new DynamicClientProxy(_clients.User(userId));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,11 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
return _hubClients.Group(groupName);
|
return _hubClients.Group(groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IClientProxy OthersInGroup(string groupName)
|
||||||
|
{
|
||||||
|
return _hubClients.GroupExcept(groupName, _currentConnectionId);
|
||||||
|
}
|
||||||
|
|
||||||
public IClientProxy GroupExcept(string groupName, IReadOnlyList<string> excludeIds)
|
public IClientProxy GroupExcept(string groupName, IReadOnlyList<string> excludeIds)
|
||||||
{
|
{
|
||||||
return _hubClients.GroupExcept(groupName, excludeIds);
|
return _hubClients.GroupExcept(groupName, excludeIds);
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
T Caller { get; }
|
T Caller { get; }
|
||||||
|
|
||||||
T Others { get; }
|
T Others { get; }
|
||||||
|
|
||||||
|
T OthersInGroup(string groupName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
return TypedClientBuilder<T>.Build(_hubClients.GroupExcept(groupName, excludeIds));
|
return TypedClientBuilder<T>.Build(_hubClients.GroupExcept(groupName, excludeIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T OthersInGroup(string groupName)
|
||||||
|
{
|
||||||
|
return TypedClientBuilder<T>.Build(_hubClients.OthersInGroup(groupName));
|
||||||
|
}
|
||||||
|
|
||||||
public T User(string userId)
|
public T User(string userId)
|
||||||
{
|
{
|
||||||
return TypedClientBuilder<T>.Build(_hubClients.User(userId));
|
return TypedClientBuilder<T>.Build(_hubClients.User(userId));
|
||||||
|
|
|
||||||
|
|
@ -127,10 +127,10 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
|
||||||
await manager.InvokeGroupExceptAsync("gunit", "Hello", new object[] { "World" }, excludedIds).OrTimeout();
|
await manager.InvokeGroupExceptAsync("gunit", "Hello", new object[] { "World" }, excludedIds).OrTimeout();
|
||||||
|
|
||||||
await AssertMessageAsync(client1);
|
await AssertMessageAsync(client1);
|
||||||
|
Assert.Null(client2.TryRead());
|
||||||
|
|
||||||
await connection1.DisposeAsync().OrTimeout();
|
await connection1.DisposeAsync().OrTimeout();
|
||||||
await connection2.DisposeAsync().OrTimeout();
|
await connection2.DisposeAsync().OrTimeout();
|
||||||
Assert.Null(client2.TryRead());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1044,6 +1044,56 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(HubTypes))]
|
||||||
|
public async Task SendToOthersInGroup(Type hubType)
|
||||||
|
{
|
||||||
|
var serviceProvider = CreateServiceProvider();
|
||||||
|
|
||||||
|
dynamic endPoint = serviceProvider.GetService(GetEndPointType(hubType));
|
||||||
|
|
||||||
|
using (var firstClient = new TestClient())
|
||||||
|
using (var secondClient = new TestClient())
|
||||||
|
{
|
||||||
|
Task firstEndPointTask = endPoint.OnConnectedAsync(firstClient.Connection);
|
||||||
|
Task secondEndPointTask = endPoint.OnConnectedAsync(secondClient.Connection);
|
||||||
|
|
||||||
|
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
|
||||||
|
|
||||||
|
var result = (await firstClient.InvokeAsync("GroupSendMethod", "testGroup", "test").OrTimeout()).Result;
|
||||||
|
|
||||||
|
// check that 'firstConnection' hasn't received the group send
|
||||||
|
Assert.Null(firstClient.TryRead());
|
||||||
|
|
||||||
|
// check that 'secondConnection' hasn't received the group send
|
||||||
|
Assert.Null(secondClient.TryRead());
|
||||||
|
|
||||||
|
await firstClient.InvokeAsync(nameof(MethodHub.GroupAddMethod), "testGroup").OrTimeout();
|
||||||
|
await secondClient.InvokeAsync(nameof(MethodHub.GroupAddMethod), "testGroup").OrTimeout();
|
||||||
|
|
||||||
|
await firstClient.SendInvocationAsync("SendToOthersInGroup", "testGroup", "test").OrTimeout();
|
||||||
|
|
||||||
|
// check that 'secondConnection' has received the group send
|
||||||
|
var hubMessage = await secondClient.ReadAsync().OrTimeout();
|
||||||
|
var invocation = Assert.IsType<InvocationMessage>(hubMessage);
|
||||||
|
Assert.Equal("Send", invocation.Target);
|
||||||
|
Assert.Single(invocation.Arguments);
|
||||||
|
Assert.Equal("test", invocation.Arguments[0]);
|
||||||
|
|
||||||
|
// Check that first client only got the completion message
|
||||||
|
hubMessage = await firstClient.ReadAsync().OrTimeout();
|
||||||
|
Assert.IsType<CompletionMessage>(hubMessage);
|
||||||
|
|
||||||
|
Assert.Null(firstClient.TryRead());
|
||||||
|
|
||||||
|
// kill the connections
|
||||||
|
firstClient.Dispose();
|
||||||
|
secondClient.Dispose();
|
||||||
|
|
||||||
|
await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RemoveFromGroupWhenNotInGroupDoesNotFail()
|
public async Task RemoveFromGroupWhenNotInGroupDoesNotFail()
|
||||||
{
|
{
|
||||||
|
|
@ -1683,6 +1733,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
return Clients.GroupExcept(groupName, excludedIds).Send(message);
|
return Clients.GroupExcept(groupName, excludedIds).Send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task SendToOthersInGroup(string groupName, string message)
|
||||||
|
{
|
||||||
|
return Clients.OthersInGroup(groupName).Send(message);
|
||||||
|
}
|
||||||
|
|
||||||
public Task BroadcastMethod(string message)
|
public Task BroadcastMethod(string message)
|
||||||
{
|
{
|
||||||
return Clients.All.Broadcast(message);
|
return Clients.All.Broadcast(message);
|
||||||
|
|
@ -1876,6 +1931,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
return Clients.GroupExcept(groupName, excludedIds).Send(message);
|
return Clients.GroupExcept(groupName, excludedIds).Send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task SendToOthersInGroup(string groupName, string message)
|
||||||
|
{
|
||||||
|
return Clients.OthersInGroup(groupName).Send(message);
|
||||||
|
}
|
||||||
|
|
||||||
public Task BroadcastMethod(string message)
|
public Task BroadcastMethod(string message)
|
||||||
{
|
{
|
||||||
return Clients.All.Broadcast(message);
|
return Clients.All.Broadcast(message);
|
||||||
|
|
@ -2012,6 +2072,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
return Clients.GroupExcept(groupName, excludedIds).InvokeAsync("Send", message);
|
return Clients.GroupExcept(groupName, excludedIds).InvokeAsync("Send", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task SendToOthersInGroup(string groupName, string message)
|
||||||
|
{
|
||||||
|
return Clients.OthersInGroup(groupName).InvokeAsync("Send", message);
|
||||||
|
}
|
||||||
|
|
||||||
public Task BroadcastMethod(string message)
|
public Task BroadcastMethod(string message)
|
||||||
{
|
{
|
||||||
return Clients.All.InvokeAsync("Broadcast", message);
|
return Clients.All.InvokeAsync("Broadcast", message);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue