Skip to content

Commit

Permalink
Fix for #963
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Mar 18, 2013
1 parent 89e3e90 commit 340db0d
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions modules/jquery/src/main/webapp/jquery/jquery.atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,19 +682,21 @@ jQuery.atmosphere = function() {
_close();
};

_response.request = request;
var prevState = _response.state;
_response.state = state;
_response.status = 200;
var prevTransport = _response.transport;
_response.transport = transport;
if (_response.error == null) {
_response.request = request;
var prevState = _response.state;
_response.state = state;
_response.status = 200;
var prevTransport = _response.transport;
_response.transport = transport;

var _body = _response.responseBody;
_invokeCallback();
_response.responseBody = _body;
var _body = _response.responseBody;
_invokeCallback();
_response.responseBody = _body;

_response.state = prevState;
_response.transport = prevTransport;
_response.state = prevState;
_response.transport = prevTransport;
}
}

/**
Expand Down Expand Up @@ -729,10 +731,11 @@ jQuery.atmosphere = function() {
type : rq.method,
dataType: "jsonp",
error : function(jqXHR, textStatus, errorThrown) {
_response.error = true;
if (jqXHR.status < 300) {
_reconnect(_jqxhr, rq);
} else {
_prepareCallback(textStatus, "error", jqXHR.status, rq.transport);
_onError("Error: " + jqXHR.status);
}
},
jsonp : "jsonpTransport",
Expand Down Expand Up @@ -763,7 +766,7 @@ jQuery.atmosphere = function() {
}
} else {
jQuery.atmosphere.log(_request.logLevel, ["JSONP reconnect maximum try reached " + _request.requestCount]);
_onError();
_onError("maxRequest reached");
}
},
data : rq.data,
Expand Down Expand Up @@ -802,10 +805,11 @@ jQuery.atmosphere = function() {
url : url,
type : rq.method,
error : function(jqXHR, textStatus, errorThrown) {
_response.error = true;
if (jqXHR.status < 300) {
_reconnect(_jqxhr, rq);
} else {
_prepareCallback(textStatus, "error", jqXHR.status, rq.transport);
_onError("Error: " + jqXHR.status);
}
},
success: function(data, textStatus, jqXHR) {
Expand All @@ -824,7 +828,7 @@ jQuery.atmosphere = function() {
}
} else {
jQuery.atmosphere.log(_request.logLevel, ["AJAX reconnect maximum try reached " + _request.requestCount]);
_onError();
_onError("maxRequest reached");
}
},
beforeSend : function(jqXHR) {
Expand Down Expand Up @@ -983,7 +987,7 @@ jQuery.atmosphere = function() {
_response.responseBody = "";
} else {
jQuery.atmosphere.log(_request.logLevel, ["SSE reconnect maximum try reached " + _requestCount]);
_onError();
_onError("maxReconnectOnClose reached");
}
}
};
Expand Down Expand Up @@ -1156,7 +1160,7 @@ jQuery.atmosphere = function() {
} else {
jQuery.atmosphere.log(_request.logLevel, ["Websocket reconnect maximum try reached " + _requestCount]);
jQuery.atmosphere.warn("Websocket error, reason: " + message.reason);
_onError();
_onError("maxReconnectOnClose reached");
}
}
};
Expand All @@ -1174,12 +1178,12 @@ jQuery.atmosphere = function() {
return true;
}

function _onError() {
function _onError(message) {
_clearState();

_response.state = 'error';
_response.responseBody = "";
_response.status = 500;
_response.status = 500 + " Reason: " + message;
_invokeCallback();
}

Expand Down Expand Up @@ -1255,7 +1259,7 @@ jQuery.atmosphere = function() {
_execute();
}, _request.reconnectInterval);
} else if (!reconnect) {
_onError();
_onError("maxReconnectOnClose reached");
}
}

Expand Down Expand Up @@ -1395,6 +1399,7 @@ jQuery.atmosphere = function() {

if (!jQuery.browser.msie) {
ajaxRequest.onerror = function() {
_response.error = true;
try {
_response.status = XMLHttpRequest.status;
} catch(e) {
Expand All @@ -1406,10 +1411,10 @@ jQuery.atmosphere = function() {
}
_clearState();

if (rq.reconnect) {
if (rq.reconnect && _requestCount++ < rq.maxReconnectOnClose) {
_reconnect(ajaxRequest, rq, true);
} else {
_onError();
_onError("maxReconnectOnClose reached");
}
};
}
Expand All @@ -1418,7 +1423,7 @@ jQuery.atmosphere = function() {
if (_abordingConnection) {
return;
}

_response.error = null;
var skipCallbackInvocation = false;
var update = false;

Expand Down Expand Up @@ -1458,11 +1463,7 @@ jQuery.atmosphere = function() {

// MSIE status can be higher than 1000, Chrome can be 0
if (ajaxRequest.status >= 500 || ajaxRequest.status == 0) {
if (rq.reconnect) {
_reconnect(ajaxRequest, rq, true);
} else {
_onError();
}
_onError("Status code higher than 500 " + ajaxRequest.status);
return;
}

Expand Down Expand Up @@ -1607,7 +1608,7 @@ jQuery.atmosphere = function() {
if (rq.logLevel == 'debug') {
jQuery.atmosphere.log(rq.logLevel, ["Max re-connection reached."]);
}
_onError();
_onError("maxRequest reached");
}
}

Expand Down Expand Up @@ -1678,7 +1679,7 @@ jQuery.atmosphere = function() {
}, request.reconnectInterval);
}
} else if (!reconnect) {
_onError();
_onError("maxReconnectOnClose reached");
}
}

Expand Down Expand Up @@ -1748,10 +1749,8 @@ jQuery.atmosphere = function() {
xdr.onerror = function() {
// If the server doesn't send anything back to XDR will fail with polling
if (rq.transport != 'polling') {
_prepareCallback(xdr.responseText, "error", 500, transport);
_reconnect(xdr, rq, false);
}

_reconnect(xdr, rq, false);
};

// Handles close event
Expand Down Expand Up @@ -1919,6 +1918,7 @@ jQuery.atmosphere = function() {
var text = readResponse();
if (text.length > rq.lastIndex) {
_response.status = 200;
_response.error = null;

// Empties response every time that it is handled
res.innerText = "";
Expand All @@ -1939,12 +1939,13 @@ jQuery.atmosphere = function() {

return false;
} catch (err) {
_response.error = true;
if (_requestCount++ < rq.maxReconnectOnClose) {
rq.id = setTimeout(function() {
_ieStreaming(rq);
}, rq.reconnectInterval);
} else {
_onError();
_onError("maxReconnectOnClose reached");
}
doc.execCommand("Stop");
doc.close();
Expand Down

1 comment on commit 340db0d

@buildhive
Copy link

Choose a reason for hiding this comment

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

Atmosphere Framework » atmosphere #796 UNSTABLE
Looks like this commit caused a build failure
(what's this?)

Please sign in to comment.