Skip to content

Commit

Permalink
Throw a nicer error when invoking hub method and connection hasn't st…
Browse files Browse the repository at this point in the history
…arted.
  • Loading branch information
davidfowl committed Aug 19, 2012
1 parent efb462b commit 4561f0f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion SignalR/Scripts/hubs.js
Expand Up @@ -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, ["_"]));

Expand Down
15 changes: 14 additions & 1 deletion samples/SignalR.Hosting.AspNet.Samples/Scripts/hubs.js
Expand Up @@ -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, ["_"]));

Expand Down

0 comments on commit 4561f0f

Please sign in to comment.