Created
January 28, 2013 00:21
-
-
Save msarchet/4651632 to your computer and use it in GitHub Desktop.
An Example of binding to a proxy later and adding a user to a group allowing a method on a proxy to be invoked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNet.SignalR; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
namespace noproxySignalR | |
{ | |
//This is the code required for the hub | |
public class TestHub : Hub | |
{ | |
public void joinGroup() | |
{ | |
Groups.Add(Context.ConnectionId, "base"); | |
} | |
public void Send() | |
{ | |
//This is to show that send will not be invoked | |
Clients.Caller.Send("new message"); | |
//This is to show that the group will be invoked | |
Clients.Group("base").Send("group message"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
ViewBag.Title = "Index"; | |
} | |
@section scripts { | |
<script type="text/javascript" src="~/Scripts/jquery-1.9.0.js"></script> | |
<script type="text/javascript" src="~/Scripts/jquery.signalR-1.0.0-rc2.min.js"></script> | |
<script type="text/javascript"> | |
var connection = $.hubConnection(); | |
var proxy = null; | |
connection.start().done(function () { | |
proxy = connection.createHubProxy('testHub'); | |
latebind(); | |
}); | |
var latebind = function () { | |
$('#clicker').bind('click', function () { | |
proxy.invoke('send'); | |
}); | |
$('#joinGroup').bind('click', function () { | |
proxy.invoke('joinGroup'); | |
}); | |
proxy.on('send', function (message) { | |
console.log(message); | |
}); | |
}; | |
</script> | |
} | |
<h2>Index</h2> | |
The Click Me button will not send a message until you have joined a group | |
<button id="clicker">Click Me</button> | |
<button id="joinGroup">Join the Group</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment