Skip to content

Commit

Permalink
API review changes for Microsoft.AspNetCore.SignalR (#2033)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Apr 16, 2018
1 parent 6eac704 commit b3a9011
Show file tree
Hide file tree
Showing 29 changed files with 84 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void GlobalSetup()
var hubConnection = new HubConnectionContext(connection, Timeout.InfiniteTimeSpan, NullLoggerFactory.Instance);
hubConnection.Protocol = protocol;
_hubLifetimeManager.OnConnectedAsync(hubConnection).GetAwaiter().GetResult();
_hubLifetimeManager.AddGroupAsync(connection.ConnectionId, TestGroupName).GetAwaiter().GetResult();
_hubLifetimeManager.AddToGroupAsync(connection.ConnectionId, TestGroupName).GetAwaiter().GetResult();

_ = ConsumeAsync(connection.Application);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.SignalR.Internal;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void GlobalSetup()
hubConnectionContext.Protocol = jsonHubProtocol;

_hubLifetimeManager.OnConnectedAsync(hubConnectionContext).GetAwaiter().GetResult();
_hubLifetimeManager.AddGroupAsync(connectionId, groupName);
_hubLifetimeManager.AddToGroupAsync(connectionId, groupName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public void GlobalSetup()
_manager1 = new RedisHubLifetimeManager<TestHub>(logger, options, resolver);
_manager2 = new RedisHubLifetimeManager<TestHub>(logger, options, resolver);

async Task ConnectClient(TestClient client, IHubProtocol protocol, string userId, string group)
async Task ConnectClient(TestClient client, IHubProtocol protocol, string userId, string groupName)
{
await _manager2.OnConnectedAsync(HubConnectionContextUtils.Create(client.Connection, protocol, userId));
await _manager2.AddGroupAsync(client.Connection.ConnectionId, "Everyone");
await _manager2.AddGroupAsync(client.Connection.ConnectionId, group);
await _manager2.AddToGroupAsync(client.Connection.ConnectionId, "Everyone");
await _manager2.AddToGroupAsync(client.Connection.ConnectionId, groupName);
}

// Connect clients
Expand Down
8 changes: 4 additions & 4 deletions samples/ChatSample/PresenceHubLifetimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ public override Task SendUserAsync(string userId, string methodName, object[] ar
return _wrappedHubLifetimeManager.SendUserAsync(userId, methodName, args);
}

public override Task AddGroupAsync(string connectionId, string groupName)
public override Task AddToGroupAsync(string connectionId, string groupName)
{
return _wrappedHubLifetimeManager.AddGroupAsync(connectionId, groupName);
return _wrappedHubLifetimeManager.AddToGroupAsync(connectionId, groupName);
}

public override Task RemoveGroupAsync(string connectionId, string groupName)
public override Task RemoveFromGroupAsync(string connectionId, string groupName)
{
return _wrappedHubLifetimeManager.RemoveGroupAsync(connectionId, groupName);
return _wrappedHubLifetimeManager.RemoveFromGroupAsync(connectionId, groupName);
}

public override Task SendGroupExceptAsync(string groupName, string methodName, object[] args, IReadOnlyList<string> excludedIds)
Expand Down
4 changes: 2 additions & 2 deletions samples/SignalRSamples/Hubs/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Task SendToOthersInGroup(string groupName, string message)

public async Task JoinGroup(string groupName)
{
await Groups.AddAsync(Context.ConnectionId, groupName);
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);

await Clients.Group(groupName).SendAsync("Send", $"{Context.ConnectionId} joined {groupName}");
}
Expand All @@ -55,7 +55,7 @@ public async Task LeaveGroup(string groupName)
{
await Clients.Group(groupName).SendAsync("Send", $"{Context.ConnectionId} left {groupName}");

await Groups.RemoveAsync(Context.ConnectionId, groupName);
await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
}

public Task Echo(string message)
Expand Down
4 changes: 2 additions & 2 deletions samples/SignalRSamples/Hubs/DynamicChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Task SendToOthersInGroup(string groupName, string message)

public async Task JoinGroup(string groupName)
{
await Groups.AddAsync(Context.ConnectionId, groupName);
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);

await Clients.Group(groupName).Send($"{Context.ConnectionId} joined {groupName}");
}
Expand All @@ -50,7 +50,7 @@ public async Task LeaveGroup(string groupName)
{
await Clients.Group(groupName).Send($"{Context.ConnectionId} left {groupName}");

await Groups.RemoveAsync(Context.ConnectionId, groupName);
await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
}

public Task Echo(string message)
Expand Down
4 changes: 2 additions & 2 deletions samples/SignalRSamples/Hubs/HubTChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Task SendToOthersInGroup(string groupName, string message)

public async Task JoinGroup(string groupName)
{
await Groups.AddAsync(Context.ConnectionId, groupName);
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);

await Clients.Group(groupName).Send($"{Context.ConnectionId} joined {groupName}");
}
Expand All @@ -50,7 +50,7 @@ public async Task LeaveGroup(string groupName)
{
await Clients.Group(groupName).Send($"{Context.ConnectionId} left {groupName}");

await Groups.RemoveAsync(Context.ConnectionId, groupName);
await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
}

public Task Echo(string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.AspNetCore.SignalR
{
public static class IClientProxyExtensions
public static class ClientProxyExtensions
{
/// <summary>
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DefaultHubLifetimeManager(ILogger<DefaultHubLifetimeManager<THub>> logger
_logger = logger;
}

public override Task AddGroupAsync(string connectionId, string groupName)
public override Task AddToGroupAsync(string connectionId, string groupName)
{
if (connectionId == null)
{
Expand All @@ -46,7 +46,7 @@ public override Task AddGroupAsync(string connectionId, string groupName)
return Task.CompletedTask;
}

public override Task RemoveGroupAsync(string connectionId, string groupName)
public override Task RemoveFromGroupAsync(string connectionId, string groupName)
{
if (connectionId == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public HubConnectionContext(ConnectionContext connectionContext, TimeSpan keepAl

public virtual IDictionary<object, object> Items => _connectionContext.Items;

public virtual PipeReader Input => _connectionContext.Transport.Input;
// Used by HubConnectionHandler
internal PipeReader Input => _connectionContext.Transport.Input;

public string UserIdentifier { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNetCore.SignalR.Core/HubLifetimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public abstract class HubLifetimeManager<THub> where THub : Hub

public abstract Task SendUsersAsync(IReadOnlyList<string> userIds, string methodName, object[] args);

public abstract Task AddGroupAsync(string connectionId, string groupName);
public abstract Task AddToGroupAsync(string connectionId, string groupName);

public abstract Task RemoveGroupAsync(string connectionId, string groupName);
public abstract Task RemoveFromGroupAsync(string connectionId, string groupName);
}

}
4 changes: 2 additions & 2 deletions src/Microsoft.AspNetCore.SignalR.Core/IGroupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.SignalR
{
public interface IGroupManager
{
Task AddAsync(string connectionId, string groupName);
Task RemoveAsync(string connectionId, string groupName);
Task AddToGroupAsync(string connectionId, string groupName);
Task RemoveFromGroupAsync(string connectionId, string groupName);
}
}
4 changes: 2 additions & 2 deletions src/Microsoft.AspNetCore.SignalR.Core/IHubClients`T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IHubClients<T>
{
T All { get; }

T AllExcept(IReadOnlyList<string> excludedIds);
T AllExcept(IReadOnlyList<string> excludedConnectionIds);

T Client(string connectionId);

Expand All @@ -19,7 +19,7 @@ public interface IHubClients<T>

T Groups(IReadOnlyList<string> groupNames);

T GroupExcept(string groupName, IReadOnlyList<string> excludeIds);
T GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds);

T User(string userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.SignalR
namespace Microsoft.AspNetCore.SignalR.Internal
{
public class DefaultHubActivator<THub> : IHubActivator<THub> where THub: Hub
{
Expand All @@ -19,7 +19,7 @@ public DefaultHubActivator(IServiceProvider serviceProvider)
_serviceProvider = serviceProvider;
}

public THub Create()
public virtual THub Create()
{
Debug.Assert(!_created.HasValue, "hub activators must not be reused.");

Expand All @@ -34,7 +34,7 @@ public THub Create()
return hub;
}

public void Release(THub hub)
public virtual void Release(THub hub)
{
if (hub == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading;
using Microsoft.AspNetCore.Http.Features;

namespace Microsoft.AspNetCore.SignalR
namespace Microsoft.AspNetCore.SignalR.Internal
{
public class DefaultHubCallerContext : HubCallerContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public HubCallerClients(IHubClients hubClients, string connectionId)

public IClientProxy All => _hubClients.All;

public IClientProxy AllExcept(IReadOnlyList<string> excludedIds)
public IClientProxy AllExcept(IReadOnlyList<string> excludedConnectionIds)
{
return _hubClients.AllExcept(excludedIds);
return _hubClients.AllExcept(excludedConnectionIds);
}

public IClientProxy Client(string connectionId)
Expand All @@ -49,9 +49,9 @@ 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> excludedConnectionIds)
{
return _hubClients.GroupExcept(groupName, excludeIds);
return _hubClients.GroupExcept(groupName, excludedConnectionIds);
}

public IClientProxy User(string userId)
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.AspNetCore.SignalR.Core/Internal/HubClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public HubClients(HubLifetimeManager<THub> lifetimeManager)

public IClientProxy All { get; }

public IClientProxy AllExcept(IReadOnlyList<string> excludedIds)
public IClientProxy AllExcept(IReadOnlyList<string> excludedConnectionIds)
{
return new AllClientsExceptProxy<THub>(_lifetimeManager, excludedIds);
return new AllClientsExceptProxy<THub>(_lifetimeManager, excludedConnectionIds);
}

public IClientProxy Client(string connectionId)
Expand All @@ -32,9 +32,9 @@ public IClientProxy Group(string groupName)
return new GroupProxy<THub>(_lifetimeManager, groupName);
}

public IClientProxy GroupExcept(string groupName, IReadOnlyList<string> excludeIds)
public IClientProxy GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds)
{
return new GroupExceptProxy<THub>(_lifetimeManager, groupName, excludeIds);
return new GroupExceptProxy<THub>(_lifetimeManager, groupName, excludedConnectionIds);
}

public IClientProxy Clients(IReadOnlyList<string> connectionIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public HubClients(HubLifetimeManager<THub> lifetimeManager)

public T All { get; }

public T AllExcept(IReadOnlyList<string> excludedIds)
public T AllExcept(IReadOnlyList<string> excludedConnectionIds)
{
return TypedClientBuilder<T>.Build(new AllClientsExceptProxy<THub>(_lifetimeManager, excludedIds));
return TypedClientBuilder<T>.Build(new AllClientsExceptProxy<THub>(_lifetimeManager, excludedConnectionIds));
}

public virtual T Client(string connectionId)
Expand All @@ -37,9 +37,9 @@ public virtual T Group(string groupName)
return TypedClientBuilder<T>.Build(new GroupProxy<THub>(_lifetimeManager, groupName));
}

public T GroupExcept(string groupName, IReadOnlyList<string> excludeIds)
public T GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds)
{
return TypedClientBuilder<T>.Build(new GroupExceptProxy<THub>(_lifetimeManager, groupName, excludeIds));
return TypedClientBuilder<T>.Build(new GroupExceptProxy<THub>(_lifetimeManager, groupName, excludedConnectionIds));
}

public T Groups(IReadOnlyList<string> groupNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace Microsoft.AspNetCore.SignalR
namespace Microsoft.AspNetCore.SignalR.Internal
{
public class HubConnectionStore
{
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.AspNetCore.SignalR.Core/Internal/Proxies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ public GroupManager(HubLifetimeManager<THub> lifetimeManager)
_lifetimeManager = lifetimeManager;
}

public Task AddAsync(string connectionId, string groupName)
public Task AddToGroupAsync(string connectionId, string groupName)
{
return _lifetimeManager.AddGroupAsync(connectionId, groupName);
return _lifetimeManager.AddToGroupAsync(connectionId, groupName);
}

public Task RemoveAsync(string connectionId, string groupName)
public Task RemoveFromGroupAsync(string connectionId, string groupName)
{
return _lifetimeManager.RemoveGroupAsync(connectionId, groupName);
return _lifetimeManager.RemoveFromGroupAsync(connectionId, groupName);
}
}
}
6 changes: 3 additions & 3 deletions src/Microsoft.AspNetCore.SignalR.Core/TypedHubClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TypedHubClients(IHubCallerClients dynamicContext)

public T Others => TypedClientBuilder<T>.Build(_hubClients.Others);

public T AllExcept(IReadOnlyList<string> excludedIds) => TypedClientBuilder<T>.Build(_hubClients.AllExcept(excludedIds));
public T AllExcept(IReadOnlyList<string> excludedConnectionIds) => TypedClientBuilder<T>.Build(_hubClients.AllExcept(excludedConnectionIds));

public T Client(string connectionId)
{
Expand All @@ -32,9 +32,9 @@ public T Group(string groupName)
return TypedClientBuilder<T>.Build(_hubClients.Group(groupName));
}

public T GroupExcept(string groupName, IReadOnlyList<string> excludeIds)
public T GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds)
{
return TypedClientBuilder<T>.Build(_hubClients.GroupExcept(groupName, excludeIds));
return TypedClientBuilder<T>.Build(_hubClients.GroupExcept(groupName, excludedConnectionIds));
}

public T Clients(IReadOnlyList<string> connectionIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override Task OnDisconnectedAsync(HubConnectionContext connection)
if (groupNames != null)
{
// Copy the groups to an array here because they get removed from this collection
// in RemoveGroupAsync
// in RemoveFromGroupAsync
foreach (var group in groupNames.ToArray())
{
// Use RemoveGroupAsyncCore because the connection is local and we don't want to
Expand Down Expand Up @@ -165,7 +165,7 @@ public override Task SendUserAsync(string userId, string methodName, object[] ar
return PublishAsync(_channels.User(userId), message);
}

public override async Task AddGroupAsync(string connectionId, string groupName)
public override async Task AddToGroupAsync(string connectionId, string groupName)
{
if (connectionId == null)
{
Expand All @@ -188,7 +188,7 @@ public override async Task AddGroupAsync(string connectionId, string groupName)
await SendGroupActionAndWaitForAck(connectionId, groupName, GroupAction.Add);
}

public override async Task RemoveGroupAsync(string connectionId, string groupName)
public override async Task RemoveFromGroupAsync(string connectionId, string groupName)
{
if (connectionId == null)
{
Expand Down
5 changes: 0 additions & 5 deletions src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public HubRouteBuilder(ConnectionsRouteBuilder routes)
_routes = routes;
}

public void MapHub<THub>(string path) where THub : Hub
{
MapHub<THub>(new PathString(path), configureOptions: null);
}

public void MapHub<THub>(PathString path) where THub : Hub
{
MapHub<THub>(path, configureOptions: null);
Expand Down
Loading

0 comments on commit b3a9011

Please sign in to comment.