[Pkg-javascript-commits] [sockjs-client] 420/434: it is impossible to cancel JSONP polling request - comprehend that

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:30 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 c4900912773add550eb963140d6503499f51333f
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Jun 6 15:08:31 2012 +0100

    it is impossible to cancel JSONP polling request - comprehend that
---
 lib/trans-jsonp-polling.js  | 24 ++++++++++++++++++++++--
 lib/trans-jsonp-receiver.js |  2 ++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lib/trans-jsonp-polling.js b/lib/trans-jsonp-polling.js
index eb80992..bfb37b2 100644
--- a/lib/trans-jsonp-polling.js
+++ b/lib/trans-jsonp-polling.js
@@ -68,16 +68,36 @@ JsonPTransport.prototype.doCleanup = function() {
 var jsonPReceiverWrapper = function(url, constructReceiver, user_callback) {
     var id = 'a' + utils.random_string(6);
     var url_id = url + '?c=' + escape(WPrefix + '.' + id);
+
+    // Unfortunately it is not possible to abort loading of the
+    // script. We need to keep track of frake close frames.
+    var aborting = 0;
+
     // Callback will be called exactly once.
     var callback = function(frame) {
-        delete _window[WPrefix][id];
-        user_callback(frame);
+        switch(aborting) {
+        case 0:
+            // Normal behaviour - delete hook _and_ emit message.
+            delete _window[WPrefix][id];
+            user_callback(frame);
+            break;
+        case 1:
+            // Fake close frame - emit but don't delete hook.
+            user_callback(frame);
+            aborting = 2;
+            break;
+        case 2:
+            // Got frame after connection was closed, delete hook, don't emit.
+            delete _window[WPrefix][id];
+            break;
+        }
     };
 
     var close_script = constructReceiver(url_id, callback);
     _window[WPrefix][id] = close_script;
     var stop = function() {
         if (_window[WPrefix][id]) {
+            aborting = 1;
             _window[WPrefix][id](utils.closeFrame(1000, "JSONP user aborted read"));
         }
     };
diff --git a/lib/trans-jsonp-receiver.js b/lib/trans-jsonp-receiver.js
index 1fd4ff7..3e26998 100644
--- a/lib/trans-jsonp-receiver.js
+++ b/lib/trans-jsonp-receiver.js
@@ -21,6 +21,8 @@ var jsonPGenericReceiver = function(url, callback) {
         }
         if (script) {
             clearTimeout(tref);
+            // Unfortunately, you can't really abort script loading of
+            // the script.
             script.parentNode.removeChild(script);
             script.onreadystatechange = script.onerror =
                 script.onload = script.onclick = null;

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