Commit f6cf36f7 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

adding support to change keys names on template message

parent e3fca68a
...@@ -257,19 +257,19 @@ ...@@ -257,19 +257,19 @@
return (text) ? window.unescape(text) : ''; return (text) ? window.unescape(text) : '';
}; };
var parseMessage = function(messageText) { var parseMessage = function(messageText, keys) {
var msg = messageText; var msg = messageText;
if (isString(messageText)) { if (isString(messageText)) {
msg = parseJSON(messageText); msg = parseJSON(messageText);
} }
var message = { var message = {
id : msg.id, id : msg[keys.jsonIdKey],
channel: msg.channel, channel: msg[keys.jsonChannelKey],
data : unescapeText(msg.text), data : unescapeText(msg[keys.jsonDataKey]),
tag : msg.tag, tag : msg[keys.jsonTagKey],
time : msg.time, time : msg[keys.jsonTimeKey],
eventid: msg.eventid || "" eventid: msg[keys.jsonEventIdKey] || ""
}; };
return message; return message;
...@@ -338,7 +338,7 @@ ...@@ -338,7 +338,7 @@
/* common callbacks */ /* common callbacks */
var onmessageCallback = function(event) { var onmessageCallback = function(event) {
Log4js.info("[" + this.type + "] message received", arguments); Log4js.info("[" + this.type + "] message received", arguments);
var message = parseMessage(event.data); var message = parseMessage(event.data, this.pushstream);
this.pushstream._onmessage(message.data, message.id, message.channel, message.eventid); this.pushstream._onmessage(message.data, message.id, message.channel, message.eventid);
}; };
...@@ -672,7 +672,7 @@ ...@@ -672,7 +672,7 @@
var messages = isArray(responseText) ? responseText : responseText.split("\r\n"); var messages = isArray(responseText) ? responseText : responseText.split("\r\n");
for (var i = 0; i < messages.length; i++) { for (var i = 0; i < messages.length; i++) {
if (messages[i]) { if (messages[i]) {
lastMessage = parseMessage(messages[i]); lastMessage = parseMessage(messages[i], this.pushstream);
this.messagesQueue.push(lastMessage); this.messagesQueue.push(lastMessage);
if (!this.pushstream.longPollingByHeaders && lastMessage.time) { if (!this.pushstream.longPollingByHeaders && lastMessage.time) {
this.etag = lastMessage.tag; this.etag = lastMessage.tag;
...@@ -724,6 +724,13 @@ ...@@ -724,6 +724,13 @@
this.urlPrefixLongpolling = settings.urlPrefixLongpolling || '/lp'; this.urlPrefixLongpolling = settings.urlPrefixLongpolling || '/lp';
this.urlPrefixWebsocket = settings.urlPrefixWebsocket || '/ws'; this.urlPrefixWebsocket = settings.urlPrefixWebsocket || '/ws';
this.jsonIdKey = settings.jsonIdKey || 'id';
this.jsonChannelKey = settings.jsonChannelKey || 'channel';
this.jsonDataKey = settings.jsonDataKey || 'text';
this.jsonTagKey = settings.jsonTagKey || 'tag';
this.jsonTimeKey = settings.jsonTimeKey || 'time';
this.jsonEventIdKey = settings.jsonEventIdKey || 'eventid';
this.modes = (settings.modes || 'eventsource|websocket|stream|longpolling').split('|'); this.modes = (settings.modes || 'eventsource|websocket|stream|longpolling').split('|');
this.wrappers = []; this.wrappers = [];
this.wrapper = null; this.wrapper = null;
......
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