AllExcept for Dynamic and Typed Hubs (#796)

This commit is contained in:
Mikael Mengistu 2017-08-31 15:30:19 -07:00 committed by GitHub
parent f31e5ad42a
commit 8ec2848646
5 changed files with 24 additions and 15 deletions

View File

@ -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));

View File

@ -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> { }
}

View File

@ -11,6 +11,8 @@ namespace Microsoft.AspNetCore.SignalR
{
T All { get; }
T AllExcept(IReadOnlyList<string> excludedIds);
T Client(string connectionId);
T Group(string groupName);

View File

@ -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));

View File

@ -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