Skip to content

Instantly share code, notes, and snippets.

@msarchet
Last active December 11, 2015 19:39
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/4650092 to your computer and use it in GitHub Desktop.
Save msarchet/4650092 to your computer and use it in GitHub Desktop.
This is the code required to reproduce a bug in SignalR where joining a Group will allow messges to be invoked on the server even if the hub is not conencted to
//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');
$('#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>
First Click the Click Me button, this shows that if you aren't in a group you won't get a message.
Then click the Join group button, and the Click Me button again, which will show the messages in the console.
<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