[Pkg-javascript-commits] [sockjs-client] 299/434: Refactoring of ajax-based transports. All now use a common AjaxBasedTransport class.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:20 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 ff5368f83b483ddc8602060776893b3ad6f68b94
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Fri Jan 13 15:37:03 2012 +0000

    Refactoring of ajax-based transports. All now use a common AjaxBasedTransport class.
---
 lib/index.js                    |  1 -
 lib/trans-iframe-eventsource.js | 23 +++++--------------
 lib/trans-iframe-htmlfile.js    | 26 +++++-----------------
 lib/trans-iframe-xhr-polling.js | 20 ++++-------------
 lib/trans-polling.js            |  6 ++---
 lib/trans-receiver-xhr.js       |  7 +++---
 lib/trans-xhr-polling.js        | 21 ------------------
 lib/trans-xhr-streaming.js      | 49 +++++++++++++++++++++++++++++------------
 8 files changed, 57 insertions(+), 96 deletions(-)

diff --git a/lib/index.js b/lib/index.js
index 11595bd..560135d 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -14,7 +14,6 @@ SockJS = (function(){
 <!-- include lib/trans-jsonp-receiver.js -->
 <!-- include lib/trans-jsonp-polling.js -->
 <!-- include lib/trans-xhr-streaming.js -->
-<!-- include lib/trans-xhr-polling.js -->
 <!-- include lib/trans-iframe.js -->
 <!-- include lib/trans-iframe-within.js -->
 <!-- include lib/info.js -->
diff --git a/lib/trans-iframe-eventsource.js b/lib/trans-iframe-eventsource.js
index 100884c..a9309cf 100644
--- a/lib/trans-iframe-eventsource.js
+++ b/lib/trans-iframe-eventsource.js
@@ -14,21 +14,8 @@ EventSourceIframeTransport.need_body = true;
 EventSourceIframeTransport.roundTrips = 3; // html, javascript, eventsource
 
 
-var EventSourceTransport = FacadeJS['w-iframe-eventsource'] = function (ri, trans_url) {
-    var that = this;
-    that.ri = ri;
-    that.trans_url = trans_url;
-    that.send_constructor(ajaxSender);
-    that.poll = new Polling(ri, EventSourceReceiver, trans_url + '/eventsource');
-};
-
-// Inheritnace
-EventSourceTransport.prototype = new BufferedSender();
-
-EventSourceTransport.prototype.doCleanup = function() {
-    var that = this;
-    if (that.poll) {
-        that.poll.abort();
-        that.poll = null;
-    }
-};
+// w-iframe-eventsource
+var EventSourceTransport = FacadeJS['w-iframe-eventsource'] = function(ri, trans_url) {
+    this.run(ri, trans_url, '/eventsource', EventSourceReceiver, utils.XHRObject);
+}
+EventSourceTransport.prototype = new AjaxBasedTransport();
diff --git a/lib/trans-iframe-htmlfile.js b/lib/trans-iframe-htmlfile.js
index 45e376f..befe258 100644
--- a/lib/trans-iframe-htmlfile.js
+++ b/lib/trans-iframe-htmlfile.js
@@ -12,30 +12,16 @@ var HtmlFileIframeTransport = SockJS['iframe-htmlfile'] = function () {
 // Inheritance.
 HtmlFileIframeTransport.prototype = new IframeTransport();
 
-HtmlFileIframeTransport.enabled = function (options) {
-    // Development or IE  _and_  iframe postWindow working.
-    var ie = isIeHtmlfileCapable();
-    return (options.cookie !== false && IframeTransport.enabled());
+HtmlFileIframeTransport.enabled = function() {
+    return IframeTransport.enabled();
 };
 
 HtmlFileIframeTransport.need_body = true;
 HtmlFileIframeTransport.roundTrips = 3; // html, javascript, htmlfile
 
 
-var HtmlFileTransport = FacadeJS['w-iframe-htmlfile'] = function (ri, trans_url) {
-    var that = this;
-    that.trans_url = trans_url;
-    that.send_constructor(ajaxSender);
-    that.poll = new Polling(ri, HtmlfileReceiver, trans_url + '/htmlfile');
-};
-
-// Inheritnace
-HtmlFileTransport.prototype = new BufferedSender();
-
-HtmlFileTransport.prototype.doCleanup = function() {
-    var that = this;
-    if (that.poll) {
-        that.poll.abort();
-        that.poll = null;
-    }
+// w-iframe-htmlfile
+var HtmlFileTransport = FacadeJS['w-iframe-htmlfile'] = function(ri, trans_url) {
+    this.run(ri, trans_url, '/htmlfile', HtmlfileReceiver, utils.XHRObject);
 };
+HtmlFileTransport.prototype = new AjaxBasedTransport();
diff --git a/lib/trans-iframe-xhr-polling.js b/lib/trans-iframe-xhr-polling.js
index 0ada5b7..126e8e4 100644
--- a/lib/trans-iframe-xhr-polling.js
+++ b/lib/trans-iframe-xhr-polling.js
@@ -14,21 +14,9 @@ XhrPollingIframeTransport.need_body = true;
 XhrPollingIframeTransport.roundTrips = 3; // html, javascript, xhr
 
 
-var XhrPollingITransport = FacadeJS['w-iframe-xhr-polling'] = function (ri, trans_url) {
-    var that = this;
-    that.trans_url = trans_url;
-    that.send_constructor(ajaxSender);
-    that.poll = new Polling(ri, XhrReceiver, trans_url + '/xhr', {cors: false});
+// w-iframe-xhr-polling
+var XhrPollingITransport = FacadeJS['w-iframe-xhr-polling'] = function(ri, trans_url) {
+    this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRObject);
 };
 
-
-// Inheritnace
-XhrPollingITransport.prototype = new BufferedSender();
-
-XhrPollingITransport.prototype.doCleanup = function() {
-    var that = this;
-    if (that.poll) {
-        that.poll.abort();
-        that.poll = null;
-    }
-};
+XhrPollingITransport.prototype = new AjaxBasedTransport();
diff --git a/lib/trans-polling.js b/lib/trans-polling.js
index a2a663e..2236532 100644
--- a/lib/trans-polling.js
+++ b/lib/trans-polling.js
@@ -1,16 +1,16 @@
 
-var Polling = function(ri, Receiver, recv_url, opts) {
+var Polling = function(ri, Receiver, recv_url, AjaxObject) {
     var that = this;
     that.ri = ri;
     that.Receiver = Receiver;
     that.recv_url = recv_url;
-    that.opts = opts;
+    that.AjaxObject = AjaxObject;
     that._scheduleRecv();
 };
 
 Polling.prototype._scheduleRecv = function() {
     var that = this;
-    var poll = that.poll = new that.Receiver(that.recv_url, that.opts);
+    var poll = that.poll = new that.Receiver(that.recv_url, that.AjaxObject);
     var msg_counter = 0;
     poll.onmessage = function(e) {
         msg_counter += 1;
diff --git a/lib/trans-receiver-xhr.js b/lib/trans-receiver-xhr.js
index bb793ff..9a9f4ba 100644
--- a/lib/trans-receiver-xhr.js
+++ b/lib/trans-receiver-xhr.js
@@ -1,9 +1,9 @@
 
-var XhrReceiver = function(url, opts) {
+var XhrReceiver = function(url, AjaxObject) {
     var that = this;
     var buf_pos = 0;
 
-    that.xo = utils.createXHR(true, 'POST', url);
+    that.xo = new AjaxObject('POST', url, null);
     that.xo.onchunk = function(status, text) {
         if (status !== 200) return;
         while (1) {
@@ -15,7 +15,8 @@ var XhrReceiver = function(url, opts) {
             that.dispatchEvent(new SimpleEvent('message', {data: msg}));
         }
     };
-    that.xo.onfinish = function(status) {
+    that.xo.onfinish = function(status, text) {
+        that.xo.onchunk(status, text);
         that.xo = null;
         var reason = status === 200 ? 'network' : 'permanent';
         that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
diff --git a/lib/trans-xhr-polling.js b/lib/trans-xhr-polling.js
deleted file mode 100644
index f5070ad..0000000
--- a/lib/trans-xhr-polling.js
+++ /dev/null
@@ -1,21 +0,0 @@
-var XhrPollingTransport = SockJS['xhr-polling'] = function (ri, trans_url) {
-    var that = this;
-    that.ri = ri;
-    that.trans_url = trans_url;
-    that.send_constructor(xdrSender);
-    that.poll = new Polling(ri, XhrReceiver, trans_url + '/xhr', {cors: true});
-};
-
-// Inheritnace
-XhrPollingTransport.prototype = new BufferedSender();
-
-XhrPollingTransport.prototype.doCleanup = function() {
-    var that = this;
-    if (that.poll) {
-        that.poll.abort();
-        that.poll = null;
-    }
-};
-
-XhrPollingTransport.enabled = XhrStreamingTransport.enabled;
-
diff --git a/lib/trans-xhr-streaming.js b/lib/trans-xhr-streaming.js
index dd26efb..90aa203 100644
--- a/lib/trans-xhr-streaming.js
+++ b/lib/trans-xhr-streaming.js
@@ -1,17 +1,17 @@
-var XhrStreamingTransport = SockJS['xhr-streaming'] = function (ri, trans_url) {
+var AjaxBasedTransport = function() {};
+AjaxBasedTransport.prototype = new BufferedSender();
+
+AjaxBasedTransport.prototype.run = function(ri, trans_url,
+                                            url_suffix, Receiver, AjaxObject) {
     var that = this;
     that.ri = ri;
     that.trans_url = trans_url;
-    that.send_constructor(xdrSender);
-    that.poll = new Polling(ri, XhrReceiver,
-                            trans_url + '/xhr_streaming',
-                            {cors: true});
+    that.send_constructor(xdrSender, AjaxObject);
+    that.poll = new Polling(ri, Receiver,
+                            trans_url + url_suffix, AjaxObject);
 };
 
-// Inheritnace
-XhrStreamingTransport.prototype = new BufferedSender();
-
-XhrStreamingTransport.prototype.doCleanup = function() {
+AjaxBasedTransport.prototype.doCleanup = function() {
     var that = this;
     if (that.poll) {
         that.poll.abort();
@@ -19,12 +19,33 @@ XhrStreamingTransport.prototype.doCleanup = function() {
     }
 };
 
+
+// xhr-streaming
+var XhrStreamingTransport = SockJS['xhr-streaming'] = function(ri, trans_url) {
+    this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XHRObject);
+};
+
+XhrStreamingTransport.prototype = new AjaxBasedTransport();
+
+XhrStreamingTransport.enabled = function() {
+    return (_window.XMLHttpRequest &&
+            'withCredentials' in new XMLHttpRequest());
+};
+
 // According to:
 //   http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
 //   http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
-XhrStreamingTransport.enabled = function(options) {
-    if (options.cookie !== true && window.XDomainRequest) return true;
-    if (window.XMLHttpRequest &&
-        'withCredentials' in new XMLHttpRequest()) return true;
-    return false;
+
+
+};
+
+
+// xhr-polling
+var XhrPollingTransport = SockJS['xhr-polling'] = function(ri, trans_url) {
+    this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRObject);
 };
+
+XhrPollingTransport.prototype = new AjaxBasedTransport();
+
+XhrPollingTransport.enabled = XhrStreamingTransport.enabled;
+

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