[Pkg-javascript-commits] [sockjs-client] 281/434: Use new ajax machinery for info, fake info response on ie7

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 7121b9ba121344bad360afb52bb41985ef8bc141
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Jan 11 13:00:59 2012 +0000

    Use new ajax machinery for info, fake info response on ie7
---
 lib/info.js | 40 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 23 deletions(-)

diff --git a/lib/info.js b/lib/info.js
index bf5c2a9..3782174 100644
--- a/lib/info.js
+++ b/lib/info.js
@@ -9,28 +9,18 @@ InfoReceiver.prototype = new EventEmitter(['finish']);
 
 InfoReceiver.prototype.doXhr = function() {
     var that = this;
-    var done = false;
-    var orsc = function(xhr, e, abort_reason) {
-        if (xhr.readyState === 4 && !done) {
-            if (xhr.status === 200) {
-                var data = xhr.responseText;
-                if (data) {
-                    var rtt = (new Date()).getTime() - that.t0;
-                    var info = JSON.parse(data);
-                    if (typeof info !== 'object') info = {};
-                    done = true;
-                    that.emit('finish', info, rtt);
-                }
-            };
-        }
-        if (abort_reason && !done) {
-            done = true;
+    var XHRObject = _window.XDomainRequest ? utils.XDRObject : utils.XHRObject;
+    var xo = new XHRObject('GET', that.base_url + '/info' , null);
+    xo.onfinish = function(status, text) {
+        if (status === 200) {
+            var rtt = (new Date()).getTime() - that.t0;
+            var info = JSON.parse(text);
+            if (typeof info !== 'object') info = {};
+            that.emit('finish', info, rtt);
+        } else {
             that.emit('finish');
         }
     };
-    var createXhr = _window.XDomainRequest ?
-                           utils.createXDR : utils.createXHR;
-    var xhr_close = createXhr('GET', that.base_url + '/info' , null, orsc);
 };
 
 var InfoReceiverIframe = function(base_url) {
@@ -66,9 +56,12 @@ InfoReceiverIframe.prototype = new EventEmitter(['finish']);
 
 
 var InfoReceiverFake = function() {
+    // It may not be possible to do cross domain AJAX to get the info
+    // data, for example for IE7. But we want to run JSONP, so let's
+    // fake the response, with rtt=2s (rto=6s).
     var that = this;
     utils.delay(function() {
-        that.emit('finish');
+        that.emit('finish', {}, 2000);
     });
 };
 InfoReceiverFake.prototype = new EventEmitter(['finish']);
@@ -76,9 +69,10 @@ InfoReceiverFake.prototype = new EventEmitter(['finish']);
 
 
 var createInfoReceiver = function(base_url) {
-    // 1. CORS
-    if (false && (_window.XDomainRequest ||
-                  (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()))) {
+    // 1. Local url or CORS
+    if (utils.isLocalUrl(base_url) ||
+        _window.XDomainRequest ||
+        (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest())) {
         return new InfoReceiver(base_url);
     }
     // 2. Iframe - Opera

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