Permalink
Browse files

Implemented buffering of calls made prior to onReady http://github.co…

  • Loading branch information...
oyvindkinsey committed Jun 19, 2010
1 parent e7c686d commit 2ee33a3c38509eb36b611b22b67953e21ac70d2f
Showing with 51 additions and 8 deletions.
  1. +2 −2 src/easyXDM.js
  2. +2 −1 src/stack/NixTransport.js
  3. +2 −1 src/stack/PostMessageTransport.js
  4. +16 −4 src/stack/QueueBehavior.js
  5. +29 −0 src/tests/tests.js
@@ -579,15 +579,15 @@ function prepareTransportStack(config){
})];
break;
case "1":
stackEls = [new easyXDM.stack.PostMessageTransport(config)];
stackEls = [new easyXDM.stack.PostMessageTransport(config), new easyXDM.stack.QueueBehavior()];
break;
case "2":
stackEls = [new easyXDM.stack.NameTransport(config), new easyXDM.stack.QueueBehavior(), new easyXDM.stack.VerifyBehavior({
initiate: config.isHost
})];
break;
case "3":
stackEls = [new easyXDM.stack.NixTransport(config)];
stackEls = [new easyXDM.stack.NixTransport(config), new easyXDM.stack.QueueBehavior()];
break;
}

@@ -21,8 +21,9 @@ easyXDM.stack.NixTransport = function(config){
frame, send, targetOrigin, proxy;

return (pub = {
outgoing: function(message, domain){
outgoing: function(message, domain, fn){
send(message);
fn();
},
destroy: function(){
// #ifdef debug
@@ -60,8 +60,9 @@ easyXDM.stack.PostMessageTransport = function(config){
}

return (pub = {
outgoing: function(message, domain){
outgoing: function(message, domain, fn){
callerWindow.postMessage(config.channel + " " + message, domain || targetOrigin);
fn();
},
destroy: function(){
// #ifdef debug
@@ -1,5 +1,5 @@
/*jslint evil: true, browser: true, immed: true, passfail: true, undef: true, newcap: true*/
/*global easyXDM, window, escape, unescape, debug*/
/*global easyXDM, window, escape, unescape, debug, undef*/

/**
* @class easyXDM.stack.QueueBehavior
@@ -17,7 +17,7 @@ easyXDM.stack.QueueBehavior = function(config){
var trace = debug.getTracer("easyXDM.stack.QueueBehavior");
trace("constructor");
// #endif
var pub, queue = [], waiting = false, incoming = "", destroying, maxLength = (config) ? config.maxLength : 0, encode = (config) ? (config.encode || false) : false;
var pub, queue = [], waiting = true, incoming = "", destroying, maxLength = 0;

function dispatch(){
if (waiting || queue.length === 0 || destroying) {
@@ -40,14 +40,26 @@ easyXDM.stack.QueueBehavior = function(config){
});
}
return (pub = {
init: function(){
if (undef(config)) {
config = {};
}
maxLength = config.maxLength ? config.maxLength : 0;
pub.down.init();
},
callback: function(success){
waiting = false;
dispatch();
pub.up.callback(success);
},
incoming: function(message, origin){
var indexOf = message.indexOf("_"), seq = parseInt(message.substring(0, indexOf), 10);
incoming += message.substring(indexOf + 1);
if (seq === 0) {
// #ifdef debug
trace("received the last fragment");
// #endif
if (encode) {
if (config.encode) {
incoming = decodeURIComponent(incoming);
}
pub.up.incoming(incoming, origin);
@@ -60,7 +72,7 @@ easyXDM.stack.QueueBehavior = function(config){
// #endif
},
outgoing: function(message, origin, fn){
if (encode) {
if (config.encode) {
message = encodeURIComponent(message);
}
var fragments = [], fragment;
@@ -431,6 +431,35 @@ function runTests(){
this.transport.postMessage(this.expectedMessage);
}
}]
}, {
name: "test easyXDM.Socket{} with buffering",
setUp: function(){
this.expectedMessage = "4abcd1234";
},
tearDown: function(){
this.transport.destroy();
if (document.getElementsByTagName("iframe").length !== 0) {
throw new Error("iframe still present");
}
},
steps: [{
name: "onReady is fired, and buffered message sent",
timeout: 5000,
run: function(){
var scope = this;
this.transport = new easyXDM.Socket({
local: "../name.html",
remote: REMOTE + "/test_transport.html",
onMessage: function(message, origin){
scope.notifyResult((scope.expectedMessage === message));
},
onReady: function(){
scope.notifyResult(true);
}
});
this.transport.postMessage(this.expectedMessage);
}
}]
}, {
name: "test easyXDM.Socket{} with query parameters",
setUp: function(){

0 comments on commit 2ee33a3

Please sign in to comment.