Commit f2ed355f authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

adding parameter to get old messages on long polling using PushStream javascript class

parent 36bab57a
......@@ -332,13 +332,18 @@
Log4js.debug("[LongPolling] closing connection to:", this.xhrSettings.url);
try { this.connection.abort(); } catch (e) { /* ignore error on closing */ }
this.connection = null;
this.lastModified = null;
this.xhrSettings.url = null;
this.pushstream._onclose();
}
},
beforeSend: function(xhr) {
if (this.lastModified == null) { this.lastModified = new Date().toUTCString(); }
if (this.lastModified == null) {
var date = new Date();
if (this.pushstream.secondsAgo) { date.setTime(date.getTime() - (this.pushstream.secondsAgo * 1000)); }
this.lastModified = date.toUTCString();
}
xhr.setRequestHeader("If-None-Match", this.etag);
xhr.setRequestHeader("If-Modified-Since", this.lastModified);
},
......@@ -366,10 +371,16 @@
},
onmessage: function(responseText) {
Log4js.info("[LongPolling] message received", arguments);
var match = responseText.match((responseText.indexOf('"eventid":"') > 0) ? PATTERN_MESSAGE_WITH_EVENT_ID : PATTERN_MESSAGE);
Log4js.info("[LongPolling] message received", responseText);
this._listen();
this.pushstream._onmessage(match[3], match[1], match[2], match[4]);
var messages = responseText.split("\r\n");
for ( var i = 0; i < messages.length; i++) {
var message = messages[i];
if (message) {
var match = message.match((message.indexOf('"eventid":"') > 0) ? PATTERN_MESSAGE_WITH_EVENT_ID : PATTERN_MESSAGE);
this.pushstream._onmessage(match[3], match[1], match[2], match[4]);
}
}
}
};
......@@ -387,6 +398,8 @@
this.reconnecttimeout = settings.reconnecttimeout || 3000;
this.checkChannelAvailabilityInterval = settings.checkChannelAvailabilityInterval || 60000;
this.secondsAgo = Number(settings.secondsAgo);
this.reconnecttimer = null;
this.urlPrefixStream = settings.urlPrefixStream || '/sub';
......
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