Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append "/poll" to polling attempts in case the URL ends with "/hubs" #1767

Merged
merged 4 commits into from Mar 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -355,7 +355,7 @@
if (index >= transports.length) {
if (!connection.transport) {
// No transport initialized successfully
$(connection).triggerHandler(events.onError, "SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
$(connection).triggerHandler(events.onError, ["SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization."]);
deferred.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
// Stop the connection if it has connected and move it into the disconnected state
connection.stop();
Expand Down Expand Up @@ -445,7 +445,7 @@
}

if (!res.ProtocolVersion || res.ProtocolVersion !== "1.2") {
$(connection).triggerHandler(events.onError, "You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
$(connection).triggerHandler(events.onError, ["You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + "."]);
deferred.reject("You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
return;
}
Expand Down Expand Up @@ -797,11 +797,15 @@
}

if (!reconnecting) {
url = url + "/connect";
url += "/connect";
} else {
if (appendReconnectUrl) {
url = url + "/reconnect";
url += "/reconnect";
} else {
// A silent reconnect should only ever occur with the longPolling transport
url += "/poll";
}

if (connection.messageId) {
qs += "&messageId=" + window.encodeURIComponent(connection.messageId);
}
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -355,7 +355,7 @@
if (index >= transports.length) {
if (!connection.transport) {
// No transport initialized successfully
$(connection).triggerHandler(events.onError, "SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
$(connection).triggerHandler(events.onError, ["SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization."]);
deferred.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
// Stop the connection if it has connected and move it into the disconnected state
connection.stop();
Expand Down Expand Up @@ -445,7 +445,7 @@
}

if (!res.ProtocolVersion || res.ProtocolVersion !== "1.2") {
$(connection).triggerHandler(events.onError, "You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
$(connection).triggerHandler(events.onError, ["You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + "."]);
deferred.reject("You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
return;
}
Expand Down Expand Up @@ -797,11 +797,15 @@
}

if (!reconnecting) {
url = url + "/connect";
url += "/connect";
} else {
if (appendReconnectUrl) {
url = url + "/reconnect";
url += "/reconnect";
} else {
// A silent reconnect should only ever occur with the longPolling transport
url += "/poll";
}

if (connection.messageId) {
qs += "&messageId=" + window.encodeURIComponent(connection.messageId);
}
Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.SignalR.Client.JS/jquery.signalR.core.js
Expand Up @@ -354,7 +354,7 @@
if (index >= transports.length) {
if (!connection.transport) {
// No transport initialized successfully
$(connection).triggerHandler(events.onError, "SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
$(connection).triggerHandler(events.onError, ["SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization."]);
deferred.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
// Stop the connection if it has connected and move it into the disconnected state
connection.stop();
Expand Down Expand Up @@ -444,7 +444,7 @@
}

if (!res.ProtocolVersion || res.ProtocolVersion !== "1.2") {
$(connection).triggerHandler(events.onError, "You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
$(connection).triggerHandler(events.onError, ["You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + "."]);
deferred.reject("You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
return;
}
Expand Down
Expand Up @@ -134,11 +134,15 @@
}

if (!reconnecting) {
url = url + "/connect";
url += "/connect";
} else {
if (appendReconnectUrl) {
url = url + "/reconnect";
url += "/reconnect";
} else {
// A silent reconnect should only ever occur with the longPolling transport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent reconnect... sigh

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to sneak it in somewhere!

url += "/poll";
}

if (connection.messageId) {
qs += "&messageId=" + window.encodeURIComponent(connection.messageId);
}
Expand Down
Expand Up @@ -108,6 +108,10 @@ public override bool SupportsKeepAlive
{
url += "reconnect";
}
else
{
url += "poll";
}

url += GetReceiveQueryString(connection, data);

Expand Down
Expand Up @@ -355,7 +355,7 @@
if (index >= transports.length) {
if (!connection.transport) {
// No transport initialized successfully
$(connection).triggerHandler(events.onError, "SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
$(connection).triggerHandler(events.onError, ["SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization."]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triggerHandler expects an array.

It came up when I was trying to figure out why my JS test was failing in Chutzpah but not in normal browsers.

I made this change in its own commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing this in other cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope

deferred.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");
// Stop the connection if it has connected and move it into the disconnected state
connection.stop();
Expand Down Expand Up @@ -445,7 +445,7 @@
}

if (!res.ProtocolVersion || res.ProtocolVersion !== "1.2") {
$(connection).triggerHandler(events.onError, "You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
$(connection).triggerHandler(events.onError, ["You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + "."]);
deferred.reject("You are using a version of the client that isn't compatible with the server. Client version 1.2, server version " + res.ProtocolVersion + ".");
return;
}
Expand Down Expand Up @@ -801,7 +801,11 @@
} else {
if (appendReconnectUrl) {
url = url + "/reconnect";
} else {
// A silent reconnect should only ever occur with the longPolling transport
url = url + "/poll";
}

if (connection.messageId) {
qs += "&messageId=" + window.encodeURIComponent(connection.messageId);
}
Expand Down
Expand Up @@ -65,16 +65,17 @@

return defaultTestTimeout;
})(),
createHubConnection: function (end, assert, testName) {
createHubConnection: function (end, assert, testName, url) {
var connection,
qs = (testName ? "test=" + window.encodeURIComponent(testName) : "");
qs = (testName ? "test=" + window.encodeURIComponent(testName) : ""),
urlSet = !!url;

url = url ? url : 'signalr';
if (window.document.testUrl !== 'auto') {
connection = $.hubConnection(window.document.testUrl, { qs: qs });
} else {
connection = $.hubConnection('signalr', { useDefaultPath: false, qs: qs });
url = window.document.testUrl + url;
}

connection = $.hubConnection(url, { useDefaultPath: false, qs: qs })
connection.logging = true;
wrapConnectionStart(connection, end, assert);

Expand All @@ -85,11 +86,10 @@
qs = (testName ? "test=" + window.encodeURIComponent(testName) : "");

if (window.document.testUrl !== 'auto') {
connection = $.connection(window.document.testUrl + '/' + url, qs);
} else {
connection = $.connection(url, qs);
url = window.document.testUrl + url;
}

connection = $.connection(url, qs);
connection.logging = true;
wrapConnectionStart(connection, end, assert);

Expand Down
Expand Up @@ -180,4 +180,41 @@ QUnit.asyncTimeoutTest("Clears stop reconnecting timeout on stop inside of state
connection.stop();
$.network.connect();
};
});
});

QUnit.asyncTimeoutTest("Can remain connected to /signalr/hubs.", testUtilities.defaultTestTimeout, function (end, assert, testName) {
var connection = testUtilities.createHubConnection(end, assert, testName, "signalr/hubs"),
demo = connection.createHubProxies().demo,
testGuidInvocations = 0;

demo.client.TestGuid = function () {
testGuidInvocations++;
if (testGuidInvocations < 2) {
assert.ok(true, "First testGuid invocation succeeded.");
demo.server.testGuid();
} else {
assert.ok(true, "Second testGuid invocation succeeded.");
end();
}
};

connection.error(function (e) {
assert.ok(false, "Connection error: " + e);
end();
});

connection.reconnecting(function () {
assert.ok(false, "Reconnecting should not be triggered");
end();
});

connection.start({ transport: "longPolling" }).done(function () {
assert.ok(true, "Connected");
demo.server.testGuid();
});

// Cleanup
return function () {
connection.stop();
};
});
Expand Up @@ -600,6 +600,47 @@ public void GuidTest(HostType hostType, TransportType transportType)
}
}

[Theory]
[InlineData(HostType.IISExpress, TransportType.LongPolling)]
[InlineData(HostType.IISExpress, TransportType.ServerSentEvents)]
[InlineData(HostType.IISExpress, TransportType.Websockets)]
public void RemainsConnectedWithHubsAppendedToUrl(HostType hostType, TransportType transportType)
{
using (var host = CreateHost(hostType, transportType))
{
host.Initialize();
var connection = CreateHubConnection(host, host.Url + "/signalr/hubs", useDefaultUrl: false);

var hub = connection.CreateHubProxy("demo");

var tcs = new TaskCompletionSource<object>();
var testGuidInvocations = 0;

hub.On<Guid>("TestGuid", id =>
{
testGuidInvocations++;
if (testGuidInvocations < 2)
{
hub.Invoke("TestGuid").ContinueWithNotComplete(tcs);
}
else
{
tcs.SetResult(null);
}
});

connection.Error += e => tcs.SetException(e);
connection.Reconnecting += () => tcs.SetCanceled();

connection.Start(host.Transport).Wait();

hub.InvokeWithTimeout("TestGuid");

Assert.True(tcs.Task.Wait(TimeSpan.FromSeconds(10)));
connection.Stop();
}
}

[Fact]
public void HubHasConnectionEvents()
{
Expand Down
Expand Up @@ -140,12 +140,12 @@ protected HubConnection CreateHubConnection(string url)
return connection;
}

protected HubConnection CreateHubConnection(ITestHost host)
protected HubConnection CreateHubConnection(ITestHost host, string url = null, bool useDefaultUrl = true)
{
var query = new Dictionary<string, string>();
query["test"] = GetTestName();
SetHostData(host, query);
var connection = new HubConnection(host.Url, query);
var connection = new HubConnection(url ?? host.Url, query, useDefaultUrl);
connection.TraceWriter = host.ClientTraceOutput ?? connection.TraceWriter;
return connection;
}
Expand Down