Commit ec7b6648 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

inprovement on LongPolling javascript client to change connection status earlier

parent 40dd8cdc
...@@ -372,6 +372,7 @@ ...@@ -372,6 +372,7 @@
this.lastModified = null; this.lastModified = null;
this.etag = 0; this.etag = 0;
this.connectionEnabled = false; this.connectionEnabled = false;
this.opentimer = null;
this.xhrSettings = { this.xhrSettings = {
url: null, url: null,
success: linker(this.onmessage, this), success: linker(this.onmessage, this),
...@@ -388,6 +389,7 @@ ...@@ -388,6 +389,7 @@
this._closeCurrentConnection(); this._closeCurrentConnection();
this.connectionEnabled = true; this.connectionEnabled = true;
this._listen(); this._listen();
this.opentimer = setTimeout(linker(onopenCallback, this), 5000);
Log4js.info("[LongPolling] connecting to:", this.xhrSettings.url); Log4js.info("[LongPolling] connecting to:", this.xhrSettings.url);
}, },
...@@ -408,6 +410,7 @@ ...@@ -408,6 +410,7 @@
}, },
_closeCurrentConnection: function() { _closeCurrentConnection: function() {
this.opentimer = clearTimer(this.opentimer);
if (this.connection) { 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;
...@@ -435,7 +438,6 @@ ...@@ -435,7 +438,6 @@
if (this.connectionEnabled) { /* abort(), called by disconnect(), call this callback, but should be ignored */ if (this.connectionEnabled) { /* abort(), called by disconnect(), call this callback, but should be ignored */
if (status === 304) { if (status === 304) {
this._listen(); this._listen();
if (this.pushstream.readyState === PushStream.CONNECTING) onopenCallback.apply(this);
} else { } else {
Log4js.info("[LongPolling] error (disconnected by server):", status); Log4js.info("[LongPolling] error (disconnected by server):", status);
this._closeCurrentConnection(); this._closeCurrentConnection();
...@@ -446,7 +448,6 @@ ...@@ -446,7 +448,6 @@
onmessage: function(responseText) { onmessage: function(responseText) {
Log4js.info("[LongPolling] message received", responseText); Log4js.info("[LongPolling] message received", responseText);
if (this.pushstream.readyState === PushStream.CONNECTING) onopenCallback.apply(this);
this._listen(); this._listen();
var messages = responseText.split("\r\n"); var messages = responseText.split("\r\n");
for ( var i = 0; i < messages.length; i++) { for ( var i = 0; i < messages.length; i++) {
...@@ -615,7 +616,7 @@ ...@@ -615,7 +616,7 @@
Log4js.debug("message", data, id, channel, eventid); Log4js.debug("message", data, id, channel, eventid);
if (id == -2) { if (id == -2) {
if (this.onchanneldeleted) { this.onchanneldeleted(channel); } if (this.onchanneldeleted) { this.onchanneldeleted(channel); }
} else if (typeof(this.channels[channel]) !== "undefined") { } else if ((id > 0) && (typeof(this.channels[channel]) !== "undefined")) {
if (this.onmessage) { this.onmessage(data, id, channel, eventid); } if (this.onmessage) { this.onmessage(data, id, channel, eventid); }
} }
}, },
......
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