Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added consistent way to get a strongly typed representation of the co…

…nnected clients.

- Added IClientProxy interface.
- Renamed *Agent classes to *Proxy
- Added test for interface that invokes a method based on the input.
  • Loading branch information...
commit fa6d0b533e7d0adb35374ce58d4cd74b7473537a 1 parent 64d83d7
David Fowler davidfowl authored
22 SignalR.Tests/HubFacts.cs
View
@@ -230,5 +230,27 @@ public void ComplexPersonState()
connection.Stop();
}
+
+ [Fact]
+ public void DynamicInvokeTest()
+ {
+ var host = new MemoryHost();
+ host.MapHubs();
+ var connection = new Client.Hubs.HubConnection("http://site/");
+ string callback = "!!!CallMeBack!!!";
+
+ var hub = connection.CreateProxy("demo");
+
+ var wh = new ManualResetEvent(false);
+
+ hub.On(callback, () => wh.Set());
+
+ connection.Start(host).Wait();
+
+ hub.Invoke("DynamicInvoke", callback).Wait();
+
+ Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
+ connection.Stop();
+ }
}
}
2  SignalR/ConnectionManager.cs
View
@@ -65,7 +65,7 @@ public IHubContext GetHubContext(string hubName)
var hubManager = _resolver.Resolve<IHubManager>();
HubDescriptor hubDescriptor = hubManager.EnsureHub(hubName);
- return new HubContext(new ClientAgent(connection, hubDescriptor.Name),
+ return new HubContext(new ClientProxy(connection, hubDescriptor.Name),
new GroupManager(connection, hubName));
}
6 SignalR/Hubs/ClientAgent.cs → SignalR/Hubs/ClientProxy.cs
View
@@ -3,12 +3,12 @@
namespace SignalR.Hubs
{
- public class ClientAgent : DynamicObject
+ public class ClientProxy : DynamicObject, IClientProxy
{
private readonly IConnection _connection;
private readonly string _hubName;
- public ClientAgent(IConnection connection, string hubName)
+ public ClientProxy(IConnection connection, string hubName)
{
_connection = connection;
_hubName = hubName;
@@ -18,7 +18,7 @@ public ClientAgent(IConnection connection, string hubName)
{
get
{
- return new SignalAgent(_connection, key, _hubName);
+ return new SignalProxy(_connection, key, _hubName);
}
}
4 SignalR/Hubs/HubDispatcher.cs
View
@@ -201,8 +201,8 @@ private IHub CreateHub(IRequest request, HubDescriptor descriptor, string connec
{
state = state ?? new TrackingDictionary();
hub.Context = new HubCallerContext(request, connectionId);
- hub.Caller = new StatefulSignalAgent(Connection, connectionId, descriptor.Name, state);
- hub.Clients = new ClientAgent(Connection, descriptor.Name);
+ hub.Caller = new StatefulSignalProxy(Connection, connectionId, descriptor.Name, state);
+ hub.Clients = new ClientProxy(Connection, descriptor.Name);
hub.Groups = new GroupManager(Connection, descriptor.Name);
}
18 SignalR/Hubs/IClientProxy.cs
View
@@ -0,0 +1,18 @@
+using System.Threading.Tasks;
+
+namespace SignalR.Hubs
+{
+ /// <summary>
+ /// A server side proxy for the client side hub.
+ /// </summary>
+ public interface IClientProxy
+ {
+ /// <summary>
+ /// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
+ /// </summary>
+ /// <param name="method">name of the method to invoke</param>
+ /// <param name="args">argumetns to pass to the client</param>
+ /// <returns>A task that represents when the data has been sent to the client.</returns>
+ Task Invoke(string method, params object[] args);
+ }
+}
4 SignalR/Hubs/SignalAgent.cs → SignalR/Hubs/SignalProxy.cs
View
@@ -3,13 +3,13 @@
namespace SignalR.Hubs
{
- public class SignalAgent : DynamicObject
+ public class SignalProxy : DynamicObject, IClientProxy
{
protected readonly IConnection _connection;
protected readonly string _signal;
protected readonly string _hubName;
- public SignalAgent(IConnection connection, string signal, string hubName)
+ public SignalProxy(IConnection connection, string signal, string hubName)
{
_connection = connection;
_signal = signal;
4 SignalR/Hubs/StatefulSignalAgent.cs → SignalR/Hubs/StatefulSignalProxy.cs
View
@@ -2,11 +2,11 @@
namespace SignalR.Hubs
{
- public class StatefulSignalAgent : SignalAgent
+ public class StatefulSignalProxy : SignalProxy
{
private readonly TrackingDictionary _state;
- public StatefulSignalAgent(IConnection connection, string signal, string hubName, TrackingDictionary state)
+ public StatefulSignalProxy(IConnection connection, string signal, string hubName, TrackingDictionary state)
: base(connection, signal, hubName)
{
_state = state;
7 SignalR/SignalR.csproj
View
@@ -61,11 +61,12 @@
<Compile Include="Hubs\HubRequest.cs" />
<Compile Include="Hubs\HubRequestParser.cs" />
<Compile Include="Hubs\HubResponse.cs" />
+ <Compile Include="Hubs\IClientProxy.cs" />
<Compile Include="Hubs\IHubContext.cs" />
<Compile Include="Hubs\IHubRequestParser.cs" />
<Compile Include="Json\IJsonValue.cs" />
<Compile Include="Json\JTokenValue.cs" />
- <Compile Include="Hubs\StatefulSignalAgent.cs" />
+ <Compile Include="Hubs\StatefulSignalProxy.cs" />
<Compile Include="Infrastructure\ConnectionExtensions.cs" />
<Compile Include="Hubs\Extensions\HubTypeExtensions.cs" />
<Compile Include="Hubs\Extensions\HubManagerExtensions.cs" />
@@ -116,11 +117,11 @@
<Compile Include="Hubs\DefaultJavaScriptProxyGenerator.cs" />
<Compile Include="Hubs\Lookup\ReflectedHubDescriptorProvider.cs" />
<Compile Include="Hubs\Hub.cs" />
- <Compile Include="Hubs\ClientAgent.cs" />
+ <Compile Include="Hubs\ClientProxy.cs" />
<Compile Include="Hubs\HubCallerContext.cs" />
<Compile Include="Hubs\HubDispatcher.cs" />
<Compile Include="Hubs\Lookup\IHubDescriptorProvider.cs" />
- <Compile Include="Hubs\SignalAgent.cs" />
+ <Compile Include="Hubs\SignalProxy.cs" />
<Compile Include="Hubs\NullJavaScriptMinifier.cs" />
<Compile Include="Infrastructure\IDependencyResolver.cs" />
<Compile Include="Hubs\IJavaScriptMinifier.cs" />
6 samples/SignalR.Hosting.AspNet.Samples/Hubs/DemoHub/DemoHub.cs
View
@@ -136,6 +136,12 @@ public void TestGuid()
Caller.TestGuid(new Guid());
}
+ public void DynamicInvoke(string method)
+ {
+ IClientProxy proxy = Caller;
+ proxy.Invoke(method);
+ }
+
public class Person
{
public string Name { get; set; }
6 samples/SignalR.Hosting.AspNet.Samples/Scripts/hubs.js
View
@@ -171,7 +171,7 @@
demo: {
_: {
hubName: 'demo',
- ignoreMembers: ['addToGroups', 'complexArray', 'complexType', 'doSomethingAndCallError', 'dynamicTask', 'genericTaskTypedAsPlain', 'genericTaskWithException', 'getValue', 'multipleCalls', 'overload', 'passingDynamicComplex', 'plainTask', 'readStateValue', 'setStateValue', 'simpleArray', 'taskWithException', 'unsupportedOverload', 'namespace', 'ignoreMembers', 'callbacks'],
+ ignoreMembers: ['addToGroups', 'complexArray', 'complexType', 'doSomethingAndCallError', 'dynamicTask', 'genericTaskTypedAsPlain', 'genericTaskWithException', 'getValue', 'multipleCalls', 'overload', 'passingDynamicComplex', 'plainTask', 'readStateValue', 'setStateValue', 'simpleArray', 'taskWithException', 'testGuid', 'unsupportedOverload', 'namespace', 'ignoreMembers', 'callbacks'],
connection: function () { return signalR.hub; }
},
@@ -241,6 +241,10 @@
unsupportedOverload: function (x, callback) {
return serverCall(this, "UnsupportedOverload", $.makeArray(arguments));
+ },
+
+ testGuid: function (callback) {
+ return serverCall(this, "TestGuid", $.makeArray(arguments));
}
},
drawingPad: {
Please sign in to comment.
Something went wrong with that request. Please try again.