Commit fbcb6222 authored by simion's avatar simion Committed by Wandenberg

Send message time to onmessage callback

parent 2e663203
......@@ -83,4 +83,4 @@ Example:
| onerror | implement this function to be notified when an error happens, the argument received is an object with a key named 'type' indicating if was a 'load' or a 'timeout' error |
| onstatuschange | implement this function to receive the new connection status as argument, which can be PushStream.CLOSED, PushStream.CONNECTING or PushStream.OPEN |
| onchanneldeleted | implement this function to be notified when a channel was deleted on the server. The channel id will be the given argument|
| onmessage | implement this function to receive the messages from server, the arguments are, in order: text, id, channel, eventid, isLastMessageFromBatch. The isLastMessageFromBatch argument indicate when is, or not, the last message received on a batch when using long polling connections |
| onmessage | implement this function to receive the messages from server, the arguments are, in order: text, id, channel, eventid, isLastMessageFromBatch, time. The isLastMessageFromBatch argument indicate when is, or not, the last message received on a batch when using long polling connections |
......@@ -517,7 +517,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
if (message.tag) { this.pushstream._etag = message.tag; }
if (message.time) { this.pushstream._lastModified = message.time; }
if (message.eventid) { this.pushstream._lastEventId = message.eventid; }
this.pushstream._onmessage(message.text, message.id, message.channel, message.eventid, true);
this.pushstream._onmessage(message.text, message.id, message.channel, message.eventid, true, message.time);
};
var onopenCallback = function() {
......@@ -725,7 +725,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
if (time) { this.pushstream._lastModified = time; }
if (eventid) { this.pushstream._lastEventId = eventid; }
}
this.pushstream._onmessage(unescapeText(text), id, channel, eventid || "", true);
this.pushstream._onmessage(unescapeText(text), id, channel, eventid || "", true, time);
this.setPingTimer();
},
......@@ -866,7 +866,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
while (this.messagesQueue.length > 0) {
var message = this.messagesQueue.shift();
this.pushstream._onmessage(message.text, message.id, message.channel, message.eventid, (this.messagesQueue.length === 0));
this.pushstream._onmessage(message.text, message.id, message.channel, message.eventid, (this.messagesQueue.length === 0), message.time);
}
}
};
......@@ -1080,12 +1080,12 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
this._reconnect(this.reconnectOnTimeoutInterval);
},
_onmessage: function(text, id, channel, eventid, isLastMessageFromBatch) {
Log4js.debug("message", text, id, channel, eventid, isLastMessageFromBatch);
_onmessage: function(text, id, channel, eventid, isLastMessageFromBatch, time) {
Log4js.debug("message", text, id, channel, eventid, isLastMessageFromBatch, time);
if (id === -2) {
if (this.onchanneldeleted) { this.onchanneldeleted(channel); }
} else if (id > 0) {
if (this.onmessage) { this.onmessage(text, id, channel, eventid, isLastMessageFromBatch); }
if (this.onmessage) { this.onmessage(text, id, channel, eventid, isLastMessageFromBatch, time); }
}
},
......
......@@ -335,8 +335,9 @@ describe("PushStream", function() {
port: port,
useJSONP: jsonp,
urlPrefixLongpolling: urlPrefixLongpolling,
onmessage: function(text, id, channel, eventid, isLastMessageFromBatch) {
onmessage: function(text, id, channel, eventid, isLastMessageFromBatch, time) {
expect([text, id, channel, eventid, isLastMessageFromBatch]).toEqual(["a test message", 1, channelName, "", true]);
expect(new Date(time).getTime()).toBeLessThan(new Date().getTime());
receivedMessage = true;
}
});
......@@ -572,8 +573,8 @@ describe("PushStream", function() {
extraParams: function() {
return {"qs":"on"};
},
onmessage: function(text, id, channel, eventid, isLastMessageFromBatch) {
messages.push([text, id, channel, eventid, isLastMessageFromBatch]);
onmessage: function(text, id, channel, eventid, isLastMessageFromBatch, time) {
messages.push([text, id, channel, eventid, isLastMessageFromBatch, time]);
if (messages.length == 1) {
receivedMessage = true;
pushstream.disconnect();
......@@ -615,8 +616,9 @@ describe("PushStream", function() {
function() {
setTimeout(function() {
expect(messages[0]).toEqual(["a test message", 1, channelName, "", true]);
expect(messages[1]).toEqual(["another test message", 2, channelName, "", true]);
expect(messages[0].slice(0, -1)).toEqual(["a test message", 1, channelName, "", true]);
expect(messages[1].slice(0, -1)).toEqual(["another test message", 2, channelName, "", true]);
expect(new Date(messages[0][messages[0].length - 1]).getTime()).toBeLessThan(new Date(messages[1][messages[1].length - 1]).getTime());
finished = true;
}, 500);
},
......
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