Skip to content

Commit

Permalink
issue #1653: WebSockets on Galaxy S3 Android Stock Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Armenta committed May 1, 2013
1 parent 1a10a06 commit fcabc6b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

supportsKeepAlive: true,

timeOut : 3000,

send: function (connection, data) {
connection.socket.send(data);
},
Expand All @@ -24,6 +26,8 @@
var url,
opened = false,
that = this,
initialSocket,
timeOutHandle,
reconnecting = !onSuccess,
$connection = $(connection);

Expand All @@ -44,7 +48,20 @@

connection.log("Connecting to websocket endpoint '" + url + "'");
connection.socket = new window.WebSocket(url);

// Issue #1653: Galaxy S3 Android Stock Browser fails silently to establish websocket connections.
if (onFailed) {
initialSocket = connection.socket;
timeOutHandle = window.setTimeout(function () {
if (initialSocket === connection.socket) {
connection.log("WebSocket timed out trying to connect");
onFailed();
}
}, that.timeOut);
}

connection.socket.onopen = function () {
window.clearTimeout(timeOutHandle);
opened = true;
connection.log("Websocket opened");

Expand All @@ -63,6 +80,8 @@
// Only handle a socket close if the close is from the current socket.
// Sometimes on disconnect the server will push down an onclose event
// to an expired socket.
window.clearTimeout(timeOutHandle);

if (this === connection.socket) {
if (!opened) {
if (onFailed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,22 @@ QUnit.asyncTimeoutTest("Default transports fall back and connect.", testUtilitie
return function () {
connection.stop();
};
});

QUnit.module("Fallback Facts", testUtilities.transports.webSockets.enabled);

QUnit.asyncTimeoutTest("WebSockets fall back to next transport.", testUtilities.defaultTestTimeout, function (end, assert, testName) {
var connection = testUtilities.createHubConnection(end, assert, testName);
var saveWebSocket = window.WebSocket;
window.WebSocket = function () { };
connection.start().done(function () {
assert.notEqual(connection.transport.name, "webSockets", "Connected using " + connection.transport.name);
end();
});

// Cleanup
return function () {
window.WebSocket = saveWebSocket;
connection.stop();
};
});

0 comments on commit fcabc6b

Please sign in to comment.