I was previously using an older ver of the signalR.js and everything is fine except it is intermittently causing my page to hang therefore I want to test it out with a newer ver from downloaded from the SignalR github site.
I tried following the client side example of SignalR but I get this error when inspecting element in chrome,
Uncaught TypeError: Object # has no method 'sending'. Anyone came across this error?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script>
<script src="/Scripts/jquery.signalR.js" type="text/javascript"> </script>
<script src="signalr/hubs" type="text/javascript"> </script>
var hub = $.connection.testHub;
hub.showMessage = function() {
$("#inboxcount").show();
};
$.connection.hub.start()
.done(function() {
hub.subscribe($('#<%= hdnUserId.ClientID %>').val());
})
.fail(function() {
alert("Could not Connect!");
});
TestHub.cs:
using System.Threading;
{
/// <summary>
/// Test Hub used to demonstrate the key concepts of SignalR
/// </summary>
[SignalR.Hubs.HubName("testHub")]
public class TestHub : SignalR.Hubs.Hub
{
/// <summary>
/// Broadcast the message to all clients
/// </summary>
/// <param name="message">message to be broadcasted</param>
public void Broadcast(string message)
{
this.Clients.showMessage(message);
}
/// <summary>
/// Return a string with the formate, Hello [current user name]
/// </summary>
/// <returns></returns>
public string SayHello()
{
//Context property can be used to retreive HTTP attributes like User
return "Hello " + Context.User.Identity.Name;
}
/// <summary>
/// Simulates a long running process that updates its progress
/// </summary>
public void LongRunningMethod()
{
Thread.Sleep(1000);
this.Caller.showMessage("25% Completed");
Thread.Sleep(1000);
this.Caller.showMessage("50% Completed");
Thread.Sleep(1000);
this.Caller.showMessage("75% Completed");
Thread.Sleep(1000);
this.Caller.showMessage("Done");
}
/// <summary>
/// Subscribe to a given message category
/// </summary>
/// <param name="category">the category to subscribe</param>
public void Subscribe(string category)
{
//Add current connection to a connection group with the name 'category'
this.AddToGroup(category);
}
/// <summary>
/// Publish a message to the given mmessage category
/// </summary>
/// <param name="category">the category to send the message</param>
/// <param name="message">the message to be sent</param>
public void Publish(string category, string message)
{
//Broadcast the message to all connections registered under the group 'category'
this.Clients[category].showMessage(message);
}
}