I\'m using the VS2012 \"Fall\" Update with the Signalr 1.0.0 package. Calling server side functions works fine. However client functions are not called. Nothing seems to hap
So your issue lies in the fact that you're starting your connection before you have any client side methods registered with your hub proxy.
There are two ways to solve this.
So here's the two approaches in code.
1:
var rtcom = new RealtimeConnection();
rtcom.init({debug: true});
RealtimeConnection: function () {
var
_rtHub = $.connection.realtimeConnectionHub,
_initialized = false,
_init = function (options, cb) {
options = options || {};
$.connection.hub.logging = options.debug;
_rtHub.client.onBroadcastMessage = function() {
alert("message");
};
$.connection.hub.start().done(function () {
_initialized = true;
if (cb) { cb(); }
});
},
_broadcast = function (message) {
if (_initialized) {
_rtHub.server.broadcastMessage("testuser", message);
}
},
return {
initialized: _initialized,
broadcast: _broadcast,
init: _init
};
}
$("#container").on("click", "button.chat-btnSendMessage", function () {
rtcom.broadcast($(this).parent().find("input").val());
});
2:
var rtcom = new RealtimeConnection();
rtcom.init({debug: true}, function () {
rtcom.subscribe(function (sender, message) {
if (message) {
alert("message");
}
});
});
RealtimeConnection: function () {
var
_rtHub = $.connection.realtimeConnectionHub,
_initialized = false,
_init = function (options, cb) {
options = options || {};
// Need to have at least 1 function registered to be subscribed to hub
_rtHub.client.foo = function() {};
$.connection.hub.logging = options.debug;
$.connection.hub.start().done(function () {
_initialized = true;
if (cb) { cb(); }
});
},
_broadcast = function (message) {
if (_initialized) {
_rtHub.server.broadcastMessage("testuser", message);
}
},
_subscribe = function (cb) {
if (_initialized) {
_rtHub.on("onBroadcastMessage", cb);
}
};
return {
initialized: _initialized,
broadcast: _broadcast,
subscribe: _subscribe,
init: _init
};
}
$("#container").on("click", "button.chat-btnSendMessage", function () {
rtcom.broadcast($(this).parent().find("input").val());
});
Hope this helps!