Commit 0cf6b62c authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

fix the error handler for load error (403), to use a different timer to try reconnection

parent f2ed355f
...@@ -146,7 +146,7 @@ ...@@ -146,7 +146,7 @@
EventSourceWrapper.prototype = { EventSourceWrapper.prototype = {
connect: function() { connect: function() {
this.disconnect(); this._closeCurrentConnection();
var url = getSubscriberUrl(this.pushstream, this.pushstream.urlPrefixEventsource); var url = getSubscriberUrl(this.pushstream, this.pushstream.urlPrefixEventsource);
this.connection = new window.EventSource(url); this.connection = new window.EventSource(url);
this.connection.onerror = linker(this.onerror, this); this.connection.onerror = linker(this.onerror, this);
...@@ -158,16 +158,22 @@ ...@@ -158,16 +158,22 @@
disconnect: function() { disconnect: function() {
if (this.connection) { if (this.connection) {
Log4js.debug("[EventSource] closing connection to:", this.connection.URL); Log4js.debug("[EventSource] closing connection to:", this.connection.URL);
this._closeCurrentConnection();
this.pushstream._onclose();
}
},
_closeCurrentConnection: function() {
if (this.connection) {
try { this.connection.close(); } catch (e) { /* ignore error on closing */ } try { this.connection.close(); } catch (e) { /* ignore error on closing */ }
this.connection = null; this.connection = null;
this.pushstream._onclose();
} }
}, },
onerror: function(event) { onerror: function(event) {
Log4js.info("[EventSource] error (disconnected by server):", event); Log4js.info("[EventSource] error (disconnected by server):", event);
this.disconnect(); this._closeCurrentConnection();
this.pushstream._onerror({type: "timeout"}); this.pushstream._onerror({type: (this.pushstream.readyState === PushStream.CONNECTING) ? "load" : "timeout"});
}, },
onopen: function() { onopen: function() {
...@@ -195,7 +201,7 @@ ...@@ -195,7 +201,7 @@
StreamWrapper.prototype = { StreamWrapper.prototype = {
connect: function() { connect: function() {
this.disconnect(); this._closeCurrentConnection();
var domain = extract_xss_domain(this.pushstream.host); var domain = extract_xss_domain(this.pushstream.host);
try { try {
document.domain = domain; document.domain = domain;
...@@ -211,13 +217,19 @@ ...@@ -211,13 +217,19 @@
disconnect: function() { disconnect: function() {
if (this.connection) { if (this.connection) {
Log4js.debug("[Stream] closing connection to:", this.url); Log4js.debug("[Stream] closing connection to:", this.url);
this._closeCurrentConnection();
this.pushstream._onclose();
}
},
_closeCurrentConnection: function() {
if (this.connection) {
try { this.connection.onload = null; this.connection.setAttribute("src", ""); } catch (e) { /* ignore error on closing */ } try { this.connection.onload = null; this.connection.setAttribute("src", ""); } catch (e) { /* ignore error on closing */ }
this.pingtimer = clearTimer(this.pingtimer); this.pingtimer = clearTimer(this.pingtimer);
this.frameloadtimer = clearTimer(this.frameloadtimer); this.frameloadtimer = clearTimer(this.frameloadtimer);
this.connection = null; this.connection = null;
this.transferDoc = null; this.transferDoc = null;
if (typeof window.CollectGarbage === 'function') window.CollectGarbage(); if (typeof window.CollectGarbage === 'function') window.CollectGarbage();
this.pushstream._onclose();
} }
}, },
...@@ -275,16 +287,14 @@ ...@@ -275,16 +287,14 @@
}, },
frameerror: function(event) { frameerror: function(event) {
var error = {}; Log4js.info("[Stream] " + (event && (event.type === "load")) ? "frame loaded whitout streaming" : "frame load timeout");
error.type = (event && (event.type === "load")) ? "load" : "timeout"; this._closeCurrentConnection();
Log4js.info("[Stream] " + (error.type === "load") ? "frame loaded whitout streaming" : "frame load timeout"); this.pushstream._onerror({type: (event && (event.type === "load")) ? "load" : "timeout"});
this.disconnect();
this.pushstream._onerror(error);
}, },
pingerror: function() { pingerror: function() {
Log4js.info("[Stream] ping timeout"); Log4js.info("[Stream] ping timeout");
this.disconnect(); this._closeCurrentConnection();
this.pushstream._onerror({type: "timeout"}); this.pushstream._onerror({type: "timeout"});
}, },
...@@ -312,7 +322,7 @@ ...@@ -312,7 +322,7 @@
LongPollingWrapper.prototype = { LongPollingWrapper.prototype = {
connect: function() { connect: function() {
this.disconnect(); this._closeCurrentConnection();
this.connectionEnabled = true; this.connectionEnabled = true;
this._listen(); this._listen();
this.onopen(); this.onopen();
...@@ -330,11 +340,17 @@ ...@@ -330,11 +340,17 @@
this.connectionEnabled = false; this.connectionEnabled = false;
if (this.connection) { if (this.connection) {
Log4js.debug("[LongPolling] closing connection to:", this.xhrSettings.url); Log4js.debug("[LongPolling] closing connection to:", this.xhrSettings.url);
this._closeCurrentConnection();
this.pushstream._onclose();
}
},
_closeCurrentConnection: function() {
if (this.connection) {
try { this.connection.abort(); } catch (e) { /* ignore error on closing */ } try { this.connection.abort(); } catch (e) { /* ignore error on closing */ }
this.connection = null; this.connection = null;
this.lastModified = null; this.lastModified = null;
this.xhrSettings.url = null; this.xhrSettings.url = null;
this.pushstream._onclose();
} }
}, },
...@@ -359,8 +375,8 @@ ...@@ -359,8 +375,8 @@
this._listen(); this._listen();
} else { } else {
Log4js.info("[LongPolling] error (disconnected by server):", status); Log4js.info("[LongPolling] error (disconnected by server):", status);
this.disconnect(); this._closeCurrentConnection();
this.pushstream._onerror({type: "timeout"}); this.pushstream._onerror({type: (status === 403) ? "load" : "timeout"});
} }
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment