[Pkg-javascript-commits] [sockjs-client] 29/434: Enable passing complex objects.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:46:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository sockjs-client.
commit 2ca838d78071d17ed41f49af9c8c24a26befe35f
Author: Marek Majkowski <majek04 at gmail.com>
Date: Thu Jul 28 14:03:47 2011 +0100
Enable passing complex objects.
---
lib/sockjs.js | 2 +-
lib/trans-iframe-within.js | 26 ++++++++++++++------------
lib/trans-iframe.js | 20 ++++++++------------
lib/trans-jsonp-sender.js | 4 +++-
lib/trans-websocket.js | 2 +-
tests-src/test-factory.coffee | 8 ++++++--
tests-src/test-run.coffee | 1 +
7 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/lib/sockjs.js b/lib/sockjs.js
index de063ec..cc2d847 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -134,7 +134,7 @@ SockJS.prototype.send = function(data) {
if (that.readyState === SockJS.CONNECTING)
throw Error('INVALID_STATE_ERR');
if (that.readyState === SockJS.OPEN) {
- that._transport.doSend(data);
+ that._transport.doSend(JSON.stringify(data));
}
return true;
};
diff --git a/lib/trans-iframe-within.js b/lib/trans-iframe-within.js
index c0fce64..b392c9d 100644
--- a/lib/trans-iframe-within.js
+++ b/lib/trans-iframe-within.js
@@ -1,17 +1,18 @@
-var postMessage = function (type, messages) {
- var msg = JSON.stringify(messages);
+var postMessage = function (type, data) {
if(parent !== _window) {
- parent.postMessage(type + msg, '*');
+ parent.postMessage(type + (data || ''), '*');
+ } else {
+ utils.log("Can't postMessage, no parent window.", type, data);
}
};
var FacadeJS = function() {};
FacadeJS.prototype._debug = function () {};
FacadeJS.prototype._didClose = function (status, reason) {
- postMessage('c', [''+status, reason]);
+ postMessage('t', utils.closeFrame(status, reason));
};
-FacadeJS.prototype._didMessage = function (data) {
- postMessage('m', [data]);
+FacadeJS.prototype._didMessage = function (frame) {
+ postMessage('t', frame);
};
FacadeJS.prototype.send = function (data) {
this._transport.doSend(data);
@@ -25,12 +26,13 @@ SockJS.bootstrap_iframe = function() {
var onMessage = function(e) {
if(e.source !== parent) return;
var type = e.data.slice(0, 1);
- var messages = JSON.parse(e.data.slice(1));
+ var data = e.data.slice(1);
switch(type) {
case 's':
- var version = messages[0];
- var protocol = messages[1];
- var trans_url = messages[2];
+ var p = JSON.parse(data);
+ var version = p[0];
+ var protocol = p[1];
+ var trans_url = p[2];
if (version !== SockJS.version) {
utils.log("Incompatibile SockJS! Main site uses:" +
" \"" + version + "\", the iframe:" +
@@ -40,7 +42,7 @@ SockJS.bootstrap_iframe = function() {
facade._transport = new FacadeJS[protocol](facade, trans_url);
break;
case 'm':
- facade.send(messages[0]);
+ facade.send(data);
break;
case 'c':
facade.close();
@@ -56,5 +58,5 @@ SockJS.bootstrap_iframe = function() {
utils.attachMessage(onMessage);
// Start
- postMessage('s', []);
+ postMessage('s');
};
diff --git a/lib/trans-iframe.js b/lib/trans-iframe.js
index 8ea1d41..a3cb88d 100644
--- a/lib/trans-iframe.js
+++ b/lib/trans-iframe.js
@@ -32,7 +32,7 @@ IframeTransport.prototype.doCleanup = function() {
if (that.iframeObj) {
utils.detachMessage(that.onmessage_cb);
if (that.iframeObj.iframe.contentWindow){
- that.postMessage('c', []);
+ that.postMessage('c');
}
that.iframeObj.cleanup();
that.onmessage_cb = that.iframeObj = null;
@@ -43,29 +43,25 @@ IframeTransport.prototype.onmessage = function(e) {
var that = this;
if (e.origin !== that.origin) return;
var type = e.data.slice(0, 1);
- var msg = JSON.parse(e.data.slice(1) || 'null');
+ var data = e.data.slice(1);
switch(type) {
case 's':
that.iframeObj.loaded();
- that.postMessage('s', [SockJS.version, that.protocol, that.trans_url]);
+ that.postMessage('s', JSON.stringify([SockJS.version, that.protocol, that.trans_url]));
break;
- case 'm':
- that.ri._didMessage(msg[0]);
- break;
- case 'c':
- that.ri._didClose(Number(msg[0]), msg[1]);
+ case 't':
+ that.ri._didMessage(data);
break;
}
};
-IframeTransport.prototype.postMessage = function(type, messages) {
+IframeTransport.prototype.postMessage = function(type, data) {
var that = this;
- var msg = JSON.stringify(messages);
- that.iframeObj.iframe.contentWindow.postMessage(type + msg, that.origin);
+ that.iframeObj.iframe.contentWindow.postMessage(type + (data || ''), that.origin);
};
IframeTransport.prototype.doSend = function (message) {
- this.postMessage('m', [message]);
+ this.postMessage('m', message);
};
IframeTransport.enabled = function() {
diff --git a/lib/trans-jsonp-sender.js b/lib/trans-jsonp-sender.js
index d6664ea..47b12b8 100644
--- a/lib/trans-jsonp-sender.js
+++ b/lib/trans-jsonp-sender.js
@@ -15,7 +15,9 @@ BufferedSender.prototype.doSend = function(message) {
BufferedSender.prototype.send_schedule = function(message) {
var that = this;
if (that.send_buffer.length > 0) {
- that.send_stop = that.sender(that.trans_url+'/send', JSON.stringify(that.send_buffer),
+ var payload = '[' + that.send_buffer.join(',') + ']';
+ that.send_stop = that.sender(that.trans_url+'/send',
+ payload,
function() {
that.send_stop = undefined;
that.send_schedule();
diff --git a/lib/trans-websocket.js b/lib/trans-websocket.js
index d2ce5b5..1364752 100644
--- a/lib/trans-websocket.js
+++ b/lib/trans-websocket.js
@@ -13,7 +13,7 @@ var WebSocketTransport = SockJS.websocket = function(ri, trans_url) {
that.ri._didMessage(e.data);
};
that.ws.onclose = function() {
- that.ri._didClose(1006, "WebSocket connection broken");
+ that.ri._didMessage(utils.closeFrame(1006, "WebSocket connection broken"));
};
};
diff --git a/tests-src/test-factory.coffee b/tests-src/test-factory.coffee
index a4a5dcb..77bb949 100644
--- a/tests-src/test-factory.coffee
+++ b/tests-src/test-factory.coffee
@@ -8,7 +8,7 @@ echo_factory_factory = (protocol, messages) ->
ok(true)
r.send(a[0])
r.onmessage = (e) ->
- equals(e.data, a[0])
+ deepEqual(e.data, a[0])
a.shift()
if typeof a[0] is 'undefined'
r.close()
@@ -19,7 +19,11 @@ echo_factory_factory = (protocol, messages) ->
start()
factor_echo_basic = (protocol) ->
- messages = ['data']
+ messages = [ 'data' ]
+ return echo_factory_factory(protocol, messages)
+
+factor_echo_rich = (protocol) ->
+ messages = [ [1,2,3,'data'], null, "data", 1, 12.0, {a:1, b:2} ]
return echo_factory_factory(protocol, messages)
factor_echo_unicode = (protocol) ->
diff --git a/tests-src/test-run.coffee b/tests-src/test-run.coffee
index 1f0e6c1..01bfe56 100644
--- a/tests-src/test-run.coffee
+++ b/tests-src/test-run.coffee
@@ -6,6 +6,7 @@ test_protocol = (protocol) ->
log('Unsupported protocol: "' + protocol + '"')
else
asyncTest("echo", factor_echo_basic(protocol))
+ asyncTest("echo2", factor_echo_rich(protocol))
asyncTest("unicode", factor_echo_unicode(protocol))
asyncTest("special_chars", factor_echo_special_chars(protocol))
asyncTest("large_message", factor_echo_large_message(protocol))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list