[Pkg-javascript-commits] [sockjs-client] 279/434: Make info working on Opera (ie: needs an iframe to do cross domain ajax)

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:19 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 544eba116bfbef92f2539ccd335766a0a5ac3898
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Jan 11 11:21:36 2012 +0000

    Make info working on Opera (ie: needs an iframe to do cross domain ajax)
---
 lib/info.js   | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 lib/sockjs.js |  8 +++----
 2 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/lib/info.js b/lib/info.js
index 711de6d..bf5c2a9 100644
--- a/lib/info.js
+++ b/lib/info.js
@@ -5,7 +5,7 @@ var InfoReceiver = function(base_url) {
     utils.delay(function(){that.doXhr();});
 };
 
-InfoReceiver.prototype = new REventTarget();
+InfoReceiver.prototype = new EventEmitter(['finish']);
 
 InfoReceiver.prototype.doXhr = function() {
     var that = this;
@@ -19,16 +19,13 @@ InfoReceiver.prototype.doXhr = function() {
                     var info = JSON.parse(data);
                     if (typeof info !== 'object') info = {};
                     done = true;
-                    that.dispatchEvent(new SimpleEvent('message',
-                                                       {info: info,
-                                                        rtt: rtt}));
+                    that.emit('finish', info, rtt);
                 }
             };
         }
         if (abort_reason && !done) {
             done = true;
-            that.dispatchEvent(new SimpleEvent('message',
-                                               {}));
+            that.emit('finish');
         }
     };
     var createXhr = _window.XDomainRequest ?
@@ -36,3 +33,69 @@ InfoReceiver.prototype.doXhr = function() {
     var xhr_close = createXhr('GET', that.base_url + '/info' , null, orsc);
 };
 
+var InfoReceiverIframe = function(base_url) {
+    var that = this;
+    var go = function() {
+        var ifr = new IframeTransport();
+        ifr.protocol = 'w-iframe-info-receiver';
+        var fun = function(r) {
+            if (typeof r === 'string' && r.substr(0,1) === 'm') {
+                var d = JSON.parse(r.substr(1));
+                var info = d[0], rtt = d[1];
+                that.emit('finish', info, rtt);
+            } else {
+                that.emit('finish');
+            }
+            ifr.doCleanup();
+            ifr = null;
+        };
+        var mock_ri = {
+            _options: {},
+            _didClose: fun,
+            _didMessage: fun
+        };
+        ifr.i_constructor(mock_ri, base_url, base_url);
+    }
+    if(!_document.body) {
+        utils.attachEvent('load', go);
+    } else {
+        go();
+    }
+};
+InfoReceiverIframe.prototype = new EventEmitter(['finish']);
+
+
+var InfoReceiverFake = function() {
+    var that = this;
+    utils.delay(function() {
+        that.emit('finish');
+    });
+};
+InfoReceiverFake.prototype = new EventEmitter(['finish']);
+
+
+
+var createInfoReceiver = function(base_url) {
+    // 1. CORS
+    if (false && (_window.XDomainRequest ||
+                  (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()))) {
+        return new InfoReceiver(base_url);
+    }
+    // 2. Iframe - Opera
+    if (IframeTransport.enabled()) {
+        return new InfoReceiverIframe(base_url);
+    }
+    // 3. IE 7
+    return new InfoReceiverFake();
+};
+
+
+var WInfoReceiverIframe = FacadeJS['w-iframe-info-receiver'] = function(ri, _trans_url, base_url) {
+    var ir = new InfoReceiver(base_url);
+    ir.onfinish = function(info, rtt) {
+        ri._didMessage('m'+JSON.stringify([info, rtt]));
+        ri._didClose();
+    }
+};
+WInfoReceiverIframe.prototype.doCleanup = function() {};
+
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 1181c1d..3b9bbc9 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -21,10 +21,10 @@ var SockJS = function(url, protocols, options) {
     that.protocol = null;
     that.readyState = SockJS.CONNECTING;
     if (!that._options.info) {
-        var ir = new InfoReceiver(that._base_url);
-        ir.onmessage = function(data) {
-            if (data.info) {
-                that._applyInfo(data);
+        var ir = createInfoReceiver(that._base_url);
+        ir.onfinish = function(info, rtt) {
+            if (info) {
+                that._applyInfo({info: info, rtt:rtt});
                 that._didClose();
             } else {
                 that._didClose(3000, 'Can\'t connect to server');

-- 
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