AllExcept for Dynamic and Typed Hubs (#796)
This commit is contained in:
parent
f31e5ad42a
commit
8ec2848646
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public class DynamicHubClients
|
||||
|
|
@ -13,6 +15,7 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
}
|
||||
|
||||
public dynamic All => new DynamicClientProxy(_clients.All);
|
||||
public dynamic AllExcept(IReadOnlyList<string> excludedIds) => new DynamicClientProxy(_clients.AllExcept(excludedIds));
|
||||
public dynamic User(string userId) => new DynamicClientProxy(_clients.User(userId));
|
||||
public dynamic Group(string group) => new DynamicClientProxy(_clients.Group(group));
|
||||
public dynamic Client(string connectionId) => new DynamicClientProxy(_clients.Client(connectionId));
|
||||
|
|
|
|||
|
|
@ -5,16 +5,5 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public interface IHubClients
|
||||
{
|
||||
IClientProxy All { get; }
|
||||
|
||||
IClientProxy AllExcept(IReadOnlyList<string> excludedIds);
|
||||
|
||||
IClientProxy Client(string connectionId);
|
||||
|
||||
IClientProxy Group(string groupName);
|
||||
|
||||
IClientProxy User(string userId);
|
||||
}
|
||||
public interface IHubClients : IHubClients<IClientProxy> { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
{
|
||||
T All { get; }
|
||||
|
||||
T AllExcept(IReadOnlyList<string> excludedIds);
|
||||
|
||||
T Client(string connectionId);
|
||||
|
||||
T Group(string groupName);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
internal class TypedHubClients<T> : IHubClients<T>
|
||||
|
|
@ -14,6 +16,8 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
|
||||
public T All => TypedClientBuilder<T>.Build(hubClients.All);
|
||||
|
||||
public T AllExcept(IReadOnlyList<string> excludedIds) => TypedClientBuilder<T>.Build(hubClients.AllExcept(excludedIds));
|
||||
|
||||
public T Client(string connectionId)
|
||||
{
|
||||
return TypedClientBuilder<T>.Build(hubClients.Client(connectionId));
|
||||
|
|
|
|||
|
|
@ -512,12 +512,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendToAllExcept()
|
||||
[Theory]
|
||||
[MemberData(nameof(HubTypes))]
|
||||
public async Task SendToAllExcept(Type hubType)
|
||||
{
|
||||
var serviceProvider = CreateServiceProvider();
|
||||
|
||||
var endPoint = serviceProvider.GetService<HubEndPoint<MethodHub>>();
|
||||
dynamic endPoint = serviceProvider.GetService(GetEndPointType(hubType));
|
||||
|
||||
using (var firstClient = new TestClient())
|
||||
using (var secondClient = new TestClient())
|
||||
|
|
@ -945,6 +946,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
return Clients.All.Broadcast(message);
|
||||
}
|
||||
|
||||
public Task SendToAllExcept(string message, IReadOnlyList<string> excludedIds)
|
||||
{
|
||||
return Clients.AllExcept(excludedIds).Send(message);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Test
|
||||
|
|
@ -995,6 +1001,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
return Clients.All.Broadcast(message);
|
||||
}
|
||||
|
||||
public Task SendToAllExcept(string message, IReadOnlyList<string> excludedIds)
|
||||
{
|
||||
return Clients.AllExcept(excludedIds).Send(message);
|
||||
}
|
||||
}
|
||||
|
||||
public class StreamingHub : TestHub
|
||||
|
|
|
|||
Loading…
Reference in New Issue