Skip to content

Instantly share code, notes, and snippets.

@msarchet
Created January 28, 2013 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msarchet/4651632 to your computer and use it in GitHub Desktop.
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
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");
}
}
}
@{
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