Commit 0a819f72 authored by Wandenberg's avatar Wandenberg

renamed some javascript client configurations

parent 28d810db
h1(#changelog). Changelog h1(#changelog). Changelog
* Unified longPollingTimeout and timeout configurations on javascript client
* Renamed some javascript client configurations
** jsonDataKey -> jsonTextKey
** longPollingUseJSONP -> useJSONP
** longPollingTagArgument -> tagArgument
** longPollingTimeArgument -> timeArgument
** longPollingByHeaders -> messagesControlByArgument (value must be changed appropriately)
** reconnecttimeout -> reconnectOnTimeoutInterval
** checkChannelAvailabilityInterval -> reconnectOnChannelUnavailableInterval
* Removed some javascript client configurations
** longPollingInterval
* Fix lazy reload * Fix lazy reload
* Normalize use of backtrack, last_event_id and if_modified_since/if_none_match values to get old messages on all subscriber modes * Normalize use of backtrack, last_event_id and if_modified_since/if_none_match values to get old messages on all subscriber modes
* Added push_stream_last_event_id directive to make possible pass the Last-Event-Id value without set header * Added push_stream_last_event_id directive to make possible pass the Last-Event-Id value without set header
......
...@@ -195,8 +195,8 @@ If needed you can change this behavior using some additional directives and chan ...@@ -195,8 +195,8 @@ If needed you can change this behavior using some additional directives and chan
port: window.location.port, port: window.location.port,
modes: "longpolling", modes: "longpolling",
longPollingByHeaders: false, longPollingByHeaders: false,
longPollingTagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive tagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive
longPollingTimeArgument: 'time' //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive timeArgument: 'time' //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive
}); });
pushstream.onmessage = messageReceived; pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1'); pushstream.addChannel('ch1');
...@@ -274,10 +274,10 @@ _The configuration in the example is the same used on long polling, just forcing ...@@ -274,10 +274,10 @@ _The configuration in the example is the same used on long polling, just forcing
port: window.location.port, port: window.location.port,
modes: "longpolling", modes: "longpolling",
longPollingByHeaders: false, longPollingByHeaders: false,
longPollingTagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive tagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive
longPollingTimeArgument: 'time', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive timeArgument: 'time', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive
longPollingUseJSONP: true, //this is used only to force jsonp usage on example, it is automatic true when the domains are different useJSONP: true, //this is used only to force jsonp usage on example, it is automatic true when the domains are different
longPollingTimeout: 30000 //this is the default value, you have to change it to be the same value used on push_stream_longpolling_connection_ttl directive in miliseconds timeout: 30000 //this is the default value, you have to change it to be the same value used on push_stream_longpolling_connection_ttl directive in miliseconds
}); });
pushstream.onmessage = messageReceived; pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1'); pushstream.addChannel('ch1');
......
...@@ -37,17 +37,15 @@ Example: ...@@ -37,17 +37,15 @@ Example:
| useSSL | false | boolean | if should use or not SSL on the connection | | useSSL | false | boolean | if should use or not SSL on the connection |
| host | current host name | string | the host name to connect and get messages | | host | current host name | string | the host name to connect and get messages |
| port | 80/443 (if using SSL) | number | the port number to connect and get messages | | port | 80/443 (if using SSL) | number | the port number to connect and get messages |
| timeout | 15000 | number | the amount of time to consider that a connection has some problem (in milliseconds) | | timeout | 30000 | number | the amount of time to consider that a connection has some problem (in milliseconds) |
| pingtimeout | 30000 | number | the amount of time to consider that a connection does not receive a ping message (in milliseconds) | | pingtimeout | 30000 | number | the amount of time to consider that a connection does not receive a ping message (in milliseconds) |
| reconnecttimeout | 3000 | number | the amount of time to do a new connection after a timeout happens (in milliseconds) | | reconnectOnTimeoutInterval | 3000 | number | the amount of time to do a new connection after a timeout happens (in milliseconds) |
| checkChannelAvailabilityInterval | 60000 | number | the amount of time to do a new connection after receives a 403, indicating that a channel is unavailable (in milliseconds) | | reconnectOnChannelUnavailableInterval | 60000 | number | the amount of time to do a new connection after receives a 403, indicating that a channel is unavailable (in milliseconds) |
| secondsAgo | - | number | get messages published at less than this time, on the first connection using long polling | | secondsAgo | - | number | get messages published at less than this time, on the first connection using long polling |
| longPollingByHeaders | true | boolean | when to use time and tag values by headers instead of arguments on long polling connections | | longPollingByHeaders | true | boolean | when to use time and tag values by headers instead of arguments on long polling connections |
| longPollingTagArgument | 'tag' | string | argument name to send tag value on long polling connections, specially used on JSONP mode | | tagArgument | 'tag' | string | argument name to send tag value on long polling connections, specially used on JSONP mode |
| longPollingTimeArgument | 'time' | string | argument name to send time value on long polling connections, specially used on JSONP mode | | timeArgument | 'time' | string | argument name to send time value on long polling connections, specially used on JSONP mode |
| longPollingUseJSONP | false | boolean | when to use JSONP mode on long polling connections, mandatorily true when current domain or port is different from the target server (cross domain restrictions) | | useJSONP | false | boolean | when to use JSONP mode on long polling connections, mandatorily true when current domain or port is different from the target server (cross domain restrictions) |
| longPollingTimeout | 30000 | number | the amount of time to consider that a long polling connection does not receive any data |
| longPollingInterval | 100 | number | the amount of time to do a new connection after receive a message or a timeout happens on long polling connections |
| urlPrefixPublisher | '/pub' | string | the location prefix used to post messages | | urlPrefixPublisher | '/pub' | string | the location prefix used to post messages |
| urlPrefixStream | '/sub' | string | the location prefix used to do Stream mode connections | | urlPrefixStream | '/sub' | string | the location prefix used to do Stream mode connections |
| urlPrefixEventsource | '/ev' | string | the location prefix used to do EventSource mode connections | | urlPrefixEventsource | '/ev' | string | the location prefix used to do EventSource mode connections |
...@@ -55,7 +53,7 @@ Example: ...@@ -55,7 +53,7 @@ Example:
| urlPrefixWebsocket | '/ws' | string | the location prefix used to do WebSocket mode connections | | urlPrefixWebsocket | '/ws' | string | the location prefix used to do WebSocket mode connections |
| jsonIdKey | 'id' | string | the key name to extract message id from received message | | jsonIdKey | 'id' | string | the key name to extract message id from received message |
| jsonChannelKey | 'channel' | string | the key name to extract channel id from received message | | jsonChannelKey | 'channel' | string | the key name to extract channel id from received message |
| jsonDataKey | 'text' | string | the key name to extract message data from received message | | jsonTextKey | 'text' | string | the key name to extract message text from received message |
| jsonTagKey | 'tag' | string | the key name to extract message tag from received message | | jsonTagKey | 'tag' | string | the key name to extract message tag from received message |
| jsonTimeKey | 'time' | string | the key name to extract message time from received message | | jsonTimeKey | 'time' | string | the key name to extract message time from received message |
| jsonEventIdKey | 'eventid' | string | the key name to extract message event id from received message | | jsonEventIdKey | 'eventid' | string | the key name to extract message event id from received message |
...@@ -83,4 +81,4 @@ Example: ...@@ -83,4 +81,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 | | 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 | | 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| | 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: data, 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. The isLastMessageFromBatch argument indicate when is, or not, the last message received on a batch when using long polling connections |
...@@ -321,7 +321,7 @@ ...@@ -321,7 +321,7 @@
var message = { var message = {
id : msg[keys.jsonIdKey], id : msg[keys.jsonIdKey],
channel: msg[keys.jsonChannelKey], channel: msg[keys.jsonChannelKey],
data : isString(msg[keys.jsonDataKey]) ? unescapeText(msg[keys.jsonDataKey]) : msg[keys.jsonDataKey], text : isString(msg[keys.jsonTextKey]) ? unescapeText(msg[keys.jsonTextKey]) : msg[keys.jsonTextKey],
tag : msg[keys.jsonTagKey], tag : msg[keys.jsonTagKey],
time : msg[keys.jsonTimeKey], time : msg[keys.jsonTimeKey],
eventid: msg[keys.jsonEventIdKey] || "" eventid: msg[keys.jsonEventIdKey] || ""
...@@ -410,7 +410,7 @@ ...@@ -410,7 +410,7 @@
var onmessageCallback = function(event) { var onmessageCallback = function(event) {
Log4js.info("[" + this.type + "] message received", arguments); Log4js.info("[" + this.type + "] message received", arguments);
var message = Utils.parseMessage(event.data, this.pushstream); var message = Utils.parseMessage(event.data, this.pushstream);
this.pushstream._onmessage(message.data, message.id, message.channel, message.eventid, true); this.pushstream._onmessage(message.text, message.id, message.channel, message.eventid, true);
}; };
var onopenCallback = function() { var onopenCallback = function() {
...@@ -424,7 +424,7 @@ ...@@ -424,7 +424,7 @@
(this.type === EventSourceWrapper.TYPE) && (this.type === EventSourceWrapper.TYPE) &&
(event.type === 'error') && (event.type === 'error') &&
(this.connection.readyState === EventSource.CONNECTING)) { (this.connection.readyState === EventSource.CONNECTING)) {
// EventSource already has a reconection function using the last-event-id header // EventSource already has a reconnection function using the last-event-id header
return; return;
} }
this._closeCurrentConnection(); this._closeCurrentConnection();
...@@ -609,10 +609,10 @@ ...@@ -609,10 +609,10 @@
Log4js.info("[Stream] frame registered"); Log4js.info("[Stream] frame registered");
}, },
process: function(id, channel, data, eventid) { process: function(id, channel, text, eventid) {
this.pingtimer = clearTimer(this.pingtimer); this.pingtimer = clearTimer(this.pingtimer);
Log4js.info("[Stream] message received", arguments); Log4js.info("[Stream] message received", arguments);
this.pushstream._onmessage(unescapeText(data), id, channel, eventid, true); this.pushstream._onmessage(unescapeText(text), id, channel, eventid, true);
this.setPingTimer(); this.setPingTimer();
}, },
...@@ -639,7 +639,7 @@ ...@@ -639,7 +639,7 @@
this.messagesQueue = []; this.messagesQueue = [];
this._linkedInternalListen = linker(this._internalListen, this); this._linkedInternalListen = linker(this._internalListen, this);
this.xhrSettings = { this.xhrSettings = {
timeout: this.pushstream.longPollingTimeout, timeout: this.pushstream.timeout,
data: {}, data: {},
url: null, url: null,
success: linker(this.onmessage, this), success: linker(this.onmessage, this),
...@@ -663,10 +663,10 @@ ...@@ -663,10 +663,10 @@
var currentDomain = Utils.extract_xss_domain(window.location.hostname); var currentDomain = Utils.extract_xss_domain(window.location.hostname);
var port = this.pushstream.port; var port = this.pushstream.port;
var currentPort = window.location.port || (this.pushstream.useSSL ? 443 : 80); var currentPort = window.location.port || (this.pushstream.useSSL ? 443 : 80);
this.useJSONP = (domain !== currentDomain) || (port !== currentPort) || this.pushstream.longPollingUseJSONP; this.useJSONP = (domain !== currentDomain) || (port !== currentPort) || this.pushstream.useJSONP;
this.xhrSettings.scriptId = "PushStreamManager_" + this.pushstream.id; this.xhrSettings.scriptId = "PushStreamManager_" + this.pushstream.id;
if (this.useJSONP) { if (this.useJSONP) {
this.pushstream.longPollingByHeaders = false; this.pushstream.messagesControlByArgument = true;
this.xhrSettings.data.callback = "PushStreamManager[" + this.pushstream.id + "].wrapper.onmessage"; this.xhrSettings.data.callback = "PushStreamManager[" + this.pushstream.id + "].wrapper.onmessage";
} }
this._internalListen(); this._internalListen();
...@@ -676,7 +676,7 @@ ...@@ -676,7 +676,7 @@
_listen: function() { _listen: function() {
if (this._internalListenTimeout) { clearTimer(this._internalListenTimeout); } if (this._internalListenTimeout) { clearTimer(this._internalListenTimeout); }
this._internalListenTimeout = window.setTimeout(this._linkedInternalListen, this.pushstream.longPollingInterval); this._internalListenTimeout = window.setTimeout(this._linkedInternalListen, 100);
}, },
_internalListen: function() { _internalListen: function() {
...@@ -716,21 +716,21 @@ ...@@ -716,21 +716,21 @@
this.lastModified = Utils.dateToUTCString(date); this.lastModified = Utils.dateToUTCString(date);
} }
if (!this.pushstream.longPollingByHeaders) { if (this.pushstream.messagesControlByArgument) {
this.xhrSettings.data[this.pushstream.longPollingTagArgument] = this.etag; this.xhrSettings.data[this.pushstream.tagArgument] = this.etag;
this.xhrSettings.data[this.pushstream.longPollingTimeArgument] = this.lastModified; this.xhrSettings.data[this.pushstream.timeArgument] = this.lastModified;
} }
}, },
beforeSend: function(xhr) { beforeSend: function(xhr) {
if (this.pushstream.longPollingByHeaders) { if (!this.pushstream.messagesControlByArgument) {
xhr.setRequestHeader("If-None-Match", this.etag); xhr.setRequestHeader("If-None-Match", this.etag);
xhr.setRequestHeader("If-Modified-Since", this.lastModified); xhr.setRequestHeader("If-Modified-Since", this.lastModified);
} }
}, },
afterReceive: function(xhr) { afterReceive: function(xhr) {
if (this.pushstream.longPollingByHeaders) { if (!this.pushstream.messagesControlByArgument) {
this.etag = xhr.getResponseHeader('Etag'); this.etag = xhr.getResponseHeader('Etag');
this.lastModified = xhr.getResponseHeader('Last-Modified'); this.lastModified = xhr.getResponseHeader('Last-Modified');
} }
...@@ -761,7 +761,7 @@ ...@@ -761,7 +761,7 @@
if (messages[i]) { if (messages[i]) {
lastMessage = Utils.parseMessage(messages[i], this.pushstream); lastMessage = Utils.parseMessage(messages[i], this.pushstream);
this.messagesQueue.push(lastMessage); this.messagesQueue.push(lastMessage);
if (!this.pushstream.longPollingByHeaders && lastMessage.time) { if (this.pushstream.messagesControlByArgument && lastMessage.time) {
this.etag = lastMessage.tag; this.etag = lastMessage.tag;
this.lastModified = lastMessage.time; this.lastModified = lastMessage.time;
} }
...@@ -772,7 +772,7 @@ ...@@ -772,7 +772,7 @@
while (this.messagesQueue.length > 0) { while (this.messagesQueue.length > 0) {
var message = this.messagesQueue.shift(); var message = this.messagesQueue.shift();
this.pushstream._onmessage(message.data, 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));
} }
} }
}; };
...@@ -790,18 +790,16 @@ ...@@ -790,18 +790,16 @@
this.host = settings.host || window.location.hostname; this.host = settings.host || window.location.hostname;
this.port = settings.port || (this.useSSL ? 443 : 80); this.port = settings.port || (this.useSSL ? 443 : 80);
this.timeout = settings.timeout || 15000; this.timeout = settings.timeout || 30000;
this.pingtimeout = settings.pingtimeout || 30000; this.pingtimeout = settings.pingtimeout || 30000;
this.reconnecttimeout = settings.reconnecttimeout || 3000; this.reconnectOnTimeoutInterval = settings.reconnectOnTimeoutInterval || 3000;
this.checkChannelAvailabilityInterval = settings.checkChannelAvailabilityInterval || 60000; this.reconnectOnChannelUnavailableInterval = settings.reconnectOnChannelUnavailableInterval || 60000;
this.secondsAgo = Number(settings.secondsAgo); this.secondsAgo = Number(settings.secondsAgo);
this.longPollingByHeaders = (settings.longPollingByHeaders === undefined) ? true : settings.longPollingByHeaders; this.messagesControlByArgument = settings.messagesControlByArgument || false;
this.longPollingTagArgument = settings.longPollingTagArgument || 'tag'; this.tagArgument = settings.tagArgument || 'tag';
this.longPollingTimeArgument = settings.longPollingTimeArgument || 'time'; this.timeArgument = settings.timeArgument || 'time';
this.longPollingUseJSONP = settings.longPollingUseJSONP || false; this.useJSONP = settings.useJSONP || false;
this.longPollingTimeout = settings.longPollingTimeout || 30000;
this.longPollingInterval = settings.longPollingInterval || 100;
this.reconnecttimer = null; this.reconnecttimer = null;
...@@ -813,7 +811,7 @@ ...@@ -813,7 +811,7 @@
this.jsonIdKey = settings.jsonIdKey || 'id'; this.jsonIdKey = settings.jsonIdKey || 'id';
this.jsonChannelKey = settings.jsonChannelKey || 'channel'; this.jsonChannelKey = settings.jsonChannelKey || 'channel';
this.jsonDataKey = settings.jsonDataKey || 'text'; this.jsonTextKey = settings.jsonTextKey || 'text';
this.jsonTagKey = settings.jsonTagKey || 'tag'; this.jsonTagKey = settings.jsonTagKey || 'tag';
this.jsonTimeKey = settings.jsonTimeKey || 'time'; this.jsonTimeKey = settings.jsonTimeKey || 'time';
this.jsonEventIdKey = settings.jsonEventIdKey || 'eventid'; this.jsonEventIdKey = settings.jsonEventIdKey || 'eventid';
...@@ -822,10 +820,10 @@ ...@@ -822,10 +820,10 @@
this.wrappers = []; this.wrappers = [];
this.wrapper = null; this.wrapper = null;
this.onchanneldeleted = null; this.onchanneldeleted = settings.onchanneldeleted || null;
this.onmessage = null; this.onmessage = settings.onmessage || null;
this.onerror = null; this.onerror = settings.onerror || null;
this.onstatuschange = null; this.onstatuschange = settings.onstatuschange || null;
this.channels = {}; this.channels = {};
this.channelsCount = 0; this.channelsCount = 0;
...@@ -847,7 +845,7 @@ ...@@ -847,7 +845,7 @@
} catch(e) { Log4js.info(e); } } catch(e) { Log4js.info(e); }
} }
this._setState(0); this.readyState = 0;
}; };
/* constants */ /* constants */
...@@ -959,21 +957,21 @@ ...@@ -959,21 +957,21 @@
_onclose: function() { _onclose: function() {
this.reconnecttimer = clearTimer(this.reconnecttimer); this.reconnecttimer = clearTimer(this.reconnecttimer);
this._setState(PushStream.CLOSED); this._setState(PushStream.CLOSED);
this._reconnect(this.reconnecttimeout); this._reconnect(this.reconnectOnTimeoutInterval);
}, },
_onmessage: function(data, id, channel, eventid, isLastMessageFromBatch) { _onmessage: function(text, id, channel, eventid, isLastMessageFromBatch) {
Log4js.debug("message", data, id, channel, eventid, isLastMessageFromBatch); Log4js.debug("message", text, id, channel, eventid, isLastMessageFromBatch);
if (id === -2) { if (id === -2) {
if (this.onchanneldeleted) { this.onchanneldeleted(channel); } if (this.onchanneldeleted) { this.onchanneldeleted(channel); }
} else if ((id > 0) && (typeof(this.channels[channel]) !== "undefined")) { } else if ((id > 0) && (typeof(this.channels[channel]) !== "undefined")) {
if (this.onmessage) { this.onmessage(data, id, channel, eventid, isLastMessageFromBatch); } if (this.onmessage) { this.onmessage(text, id, channel, eventid, isLastMessageFromBatch); }
} }
}, },
_onerror: function(error) { _onerror: function(error) {
this._setState(PushStream.CLOSED); this._setState(PushStream.CLOSED);
this._reconnect((error.type === "timeout") ? this.reconnecttimeout : this.checkChannelAvailabilityInterval); this._reconnect((error.type === "timeout") ? this.reconnectOnTimeoutInterval : this.reconnectOnChannelUnavailableInterval);
if (this.onerror) { this.onerror(error); } if (this.onerror) { this.onerror(error); }
}, },
......
...@@ -47,13 +47,21 @@ describe("PushStream", function() { ...@@ -47,13 +47,21 @@ describe("PushStream", function() {
expect(pushstream.useSSL).toBeFalsy(); expect(pushstream.useSSL).toBeFalsy();
}); });
it("should not use JSONP", function() {
expect(pushstream.useJSONP).toBeFalsy();
});
it("should set state as uninitialised", function() { it("should set state as uninitialised", function() {
expect(pushstream.readyState).toBe(PushStream.CLOSED); expect(pushstream.readyState).toBe(PushStream.CLOSED);
}); });
it("should set seconds ago as NaN", function() {
expect(isNaN(pushstream.secondsAgo)).toBeTruthy();
});
describe("for operation timeouts", function() { describe("for operation timeouts", function() {
it("should has a connection timeout", function() { it("should has a connection timeout", function() {
expect(pushstream.timeout).toBe(15000); expect(pushstream.timeout).toBe(30000);
}); });
it("should has a ping message timeout", function() { it("should has a ping message timeout", function() {
...@@ -61,11 +69,11 @@ describe("PushStream", function() { ...@@ -61,11 +69,11 @@ describe("PushStream", function() {
}); });
it("should has a reconnect interval, to be used when a timeout happens", function() { it("should has a reconnect interval, to be used when a timeout happens", function() {
expect(pushstream.reconnecttimeout).toBe(3000); expect(pushstream.reconnectOnTimeoutInterval).toBe(3000);
}); });
it("should has a reconnect interval, to be used when a channel is unavailable", function() { it("should has a reconnect interval, to be used when a channel is unavailable", function() {
expect(pushstream.checkChannelAvailabilityInterval).toBe(60000); expect(pushstream.reconnectOnChannelUnavailableInterval).toBe(60000);
}); });
}); });
...@@ -101,7 +109,7 @@ describe("PushStream", function() { ...@@ -101,7 +109,7 @@ describe("PushStream", function() {
}); });
it("should has a key for 'text'", function() { it("should has a key for 'text'", function() {
expect(pushstream.jsonDataKey).toBe('text'); expect(pushstream.jsonTextKey).toBe('text');
}); });
it("should has a key for 'tag'", function() { it("should has a key for 'tag'", function() {
...@@ -119,11 +127,11 @@ describe("PushStream", function() { ...@@ -119,11 +127,11 @@ describe("PushStream", function() {
describe("for arguments names", function() { describe("for arguments names", function() {
it("should has a argument for 'tag'", function() { it("should has a argument for 'tag'", function() {
expect(pushstream.longPollingTagArgument).toBe('tag'); expect(pushstream.tagArgument).toBe('tag');
}); });
it("should has a argument for 'time'", function() { it("should has a argument for 'time'", function() {
expect(pushstream.longPollingTimeArgument).toBe('time'); expect(pushstream.timeArgument).toBe('time');
}); });
it("should has a argument for 'channels'", function() { it("should has a argument for 'channels'", function() {
...@@ -146,6 +154,14 @@ describe("PushStream", function() { ...@@ -146,6 +154,14 @@ describe("PushStream", function() {
expect(pushstream.channels).toEqual({}); expect(pushstream.channels).toEqual({});
expect(pushstream.channelsCount).toBe(0); expect(pushstream.channelsCount).toBe(0);
}); });
it("should use the url path to send channels names instead of a query string parameter", function() {
expect(pushstream.channelsByArgument).toBeFalsy();
});
it("should use headers to set values to request old messages or indicate the last received message instead of a query string parameter", function() {
expect(pushstream.messagesControlByArgument).toBeFalsy();
});
}); });
describe("when manipulating channels", function() { describe("when manipulating channels", function() {
...@@ -217,4 +233,29 @@ describe("PushStream", function() { ...@@ -217,4 +233,29 @@ describe("PushStream", function() {
}); });
}); });
}); });
it("should define an id as a sequential number based on PushStreamManager size", function() {
var p1 = new PushStream();
var p2 = new PushStream();
expect(p1.id).toBe(p2.id - 1);
expect(p2.id).toBe(PushStreamManager.length - 1);
});
describe("when checking available modes", function() {
var eventsourceClass = null;
beforeEach(function() {
eventsourceClass = window.EventSource;
window.EventSource = null;
});
afterEach(function() { window.EventSource = eventsourceClass; });
it("should use only connection modes supported by the browser on the given order", function() {
var pushstream = new PushStream({modes: "stream|eventsource|longpolling"})
expect(pushstream.wrappers.length).toBe(2);
expect(pushstream.wrappers[0].type).toBe("Stream");
expect(pushstream.wrappers[1].type).toBe("LongPolling");
});
});
}); });
...@@ -2,7 +2,7 @@ describe("Utils", function() { ...@@ -2,7 +2,7 @@ describe("Utils", function() {
var jsonKeys = { var jsonKeys = {
jsonIdKey : 'id', jsonIdKey : 'id',
jsonChannelKey : 'channel', jsonChannelKey : 'channel',
jsonDataKey : 'text', jsonTextKey : 'text',
jsonTagKey : 'tag', jsonTagKey : 'tag',
jsonTimeKey : 'time', jsonTimeKey : 'time',
jsonEventIdKey : 'eventid' jsonEventIdKey : 'eventid'
...@@ -157,21 +157,21 @@ describe("Utils", function() { ...@@ -157,21 +157,21 @@ describe("Utils", function() {
describe("when parsing a message", function() { describe("when parsing a message", function() {
it("should accept a simple string as text", function() { it("should accept a simple string as text", function() {
var message = Utils.parseMessage('{"id":31,"channel":"54x19","text":"some simple string"}', jsonKeys); var message = Utils.parseMessage('{"id":31,"channel":"54x19","text":"some simple string"}', jsonKeys);
expect(message.data).toBe("some simple string"); expect(message.text).toBe("some simple string");
}); });
it("should accept a json as text", function() { it("should accept a json as text", function() {
var message = Utils.parseMessage('{"id":31,"channel":"54x19","text":{"id":"500516b7639e4029b8000001","type":"Player","change":{"loc":[54.34772390000001,18.5610535],"version":7}}}', jsonKeys); var message = Utils.parseMessage('{"id":31,"channel":"54x19","text":{"id":"500516b7639e4029b8000001","type":"Player","change":{"loc":[54.34772390000001,18.5610535],"version":7}}}', jsonKeys);
expect(message.data.id).toBe("500516b7639e4029b8000001"); expect(message.text.id).toBe("500516b7639e4029b8000001");
expect(message.data.type).toBe("Player"); expect(message.text.type).toBe("Player");
expect(message.data.change.loc[0]).toBe(54.34772390000001); expect(message.text.change.loc[0]).toBe(54.34772390000001);
expect(message.data.change.loc[1]).toBe(18.5610535); expect(message.text.change.loc[1]).toBe(18.5610535);
expect(message.data.change.version).toBe(7); expect(message.text.change.version).toBe(7);
}); });
it("should accept an escaped json as text", function() { it("should accept an escaped json as text", function() {
var message = Utils.parseMessage('{"id":31,"channel":"54x19","text":"%7B%22id%22%3A%22500516b7639e4029b8000001%22%2C%22type%22%3A%22Player%22%2C%22change%22%3A%7B%22loc%22%3A%5B54.34772390000001%2C18.5610535%5D%2C%22version%22%3A7%7D%7D"}', jsonKeys); var message = Utils.parseMessage('{"id":31,"channel":"54x19","text":"%7B%22id%22%3A%22500516b7639e4029b8000001%22%2C%22type%22%3A%22Player%22%2C%22change%22%3A%7B%22loc%22%3A%5B54.34772390000001%2C18.5610535%5D%2C%22version%22%3A7%7D%7D"}', jsonKeys);
expect(message.data).toBe('{"id":"500516b7639e4029b8000001","type":"Player","change":{"loc":[54.34772390000001,18.5610535],"version":7}}'); expect(message.text).toBe('{"id":"500516b7639e4029b8000001","type":"Player","change":{"loc":[54.34772390000001,18.5610535],"version":7}}');
}); });
}); });
}); });
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