diff --git a/SignalR/Scripts/hubs.js b/SignalR/Scripts/hubs.js index 7d69dc3ceb..9cd8453b3b 100644 --- a/SignalR/Scripts/hubs.js +++ b/SignalR/Scripts/hubs.js @@ -84,13 +84,26 @@ if ($.isFunction(userCallback)) { userCallback.call(hub, result); } - }; + }, + connection = hub._.connection(); if ($.isFunction(userCallback)) { // Replace user's callback with our own args = $.merge(args.splice(0, args.length - 1), [callback]); } + if (!hub._.proxy) { + if (connection.state === signalR.connectionState.disconnected) { + // Connection hasn't been started yet + throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()"; + } + + if (connection.state === signalR.connectionState.connecting) { + // Connection hasn't been started yet + throw "SignalR: Connection has not been fully initialized. Use .start().done() or .start().fail() to run logic after the connection has started."; + } + } + // Update proxy state from hub state $.extend(hub._.proxy.state, copy(hub, ["_"])); diff --git a/samples/SignalR.Hosting.AspNet.Samples/Scripts/hubs.js b/samples/SignalR.Hosting.AspNet.Samples/Scripts/hubs.js index 1046808b23..24c08ce4f7 100644 --- a/samples/SignalR.Hosting.AspNet.Samples/Scripts/hubs.js +++ b/samples/SignalR.Hosting.AspNet.Samples/Scripts/hubs.js @@ -84,13 +84,26 @@ if ($.isFunction(userCallback)) { userCallback.call(hub, result); } - }; + }, + connection = hub._.connection(); if ($.isFunction(userCallback)) { // Replace user's callback with our own args = $.merge(args.splice(0, args.length - 1), [callback]); } + if (!hub._.proxy) { + if (connection.state === signalR.connectionState.disconnected) { + // Connection hasn't been started yet + throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()"; + } + + if (connection.state === signalR.connectionState.connecting) { + // Connection hasn't been started yet + throw "SignalR: Connection has not been fully initialized. Use .start().done() or .start().fail() to run logic after the connection has started."; + } + } + // Update proxy state from hub state $.extend(hub._.proxy.state, copy(hub, ["_"]));