[Pkg-javascript-commits] [sockjs-client] 320/434: Drop document_guard. Use onunload instead.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:22 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 2de45a443dec0f9422c888dfdd72613863facce3
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Tue Jan 17 12:42:43 2012 +0000

    Drop document_guard. Use onunload instead.
---
 lib/dom.js             | 32 --------------------------------
 lib/trans-websocket.js | 20 +++++++++-----------
 2 files changed, 9 insertions(+), 43 deletions(-)

diff --git a/lib/dom.js b/lib/dom.js
index 0157265..b7da8b4 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -163,35 +163,3 @@ utils.createHtmlfile = function (iframe_url, error_callback) {
         loaded: unattach
     };
 };
-
-var DocumentGuard = function() {
-    var that = this;
-    var emit = function(state_name) {
-        that.state = DocumentGuard[state_name];
-        var e = {state: that.state, name: state_name};
-        that.dispatchEvent(new SimpleEvent('change', e));
-        that.dispatchEvent(new SimpleEvent(state_name, e));
-    };
-    emit('init');
-    if(!!_document.body) {
-        emit('load');
-    } else {
-        utils.attachEvent('load', function() {
-            emit('load');
-        });
-    }
-    utils.attachEvent('beforeunload', function() {
-        emit('beforeunload');
-    });
-    utils.attachEvent('unload', function() {
-        emit('unload');
-    });
-};
-
-DocumentGuard.prototype = new REventTarget();
-DocumentGuard.init = 0;
-DocumentGuard.load = 1;
-DocumentGuard.beforeunload = 2;
-DocumentGuard.unload = 3;
-
-var _document_guard = new DocumentGuard();
diff --git a/lib/trans-websocket.js b/lib/trans-websocket.js
index 6ad01df..1571868 100644
--- a/lib/trans-websocket.js
+++ b/lib/trans-websocket.js
@@ -10,20 +10,17 @@ var WebSocketTransport = SockJS.websocket = function(ri, trans_url) {
     that.url = url;
     var Constructor = _window.WebSocket || _window.MozWebSocket;
 
-    if(_document_guard.state >= DocumentGuard.beforeunload) {
-        // Firefox has an interesting bug. If a websocket connection
-        // is created after onbeforeunload, it stays alive even when
-        // user navigates away from the page. In such situation let's
-        // lie - let's not open the ws connection at all. See:
-        // https://github.com/sockjs/sockjs-client/issues/28
-        utils.log("Can't open a WebSocket connection after onbeforeunload!");
-        return;
-    }
-
     that.ws = new Constructor(that.url);
     that.ws.onmessage = function(e) {
         that.ri._didMessage(e.data);
     };
+    // Firefox has an interesting bug. If a websocket connection is
+    // created after onbeforeunload, it stays alive even when user
+    // navigates away from the page. In such situation let's lie -
+    // let's not open the ws connection at all. See:
+    // https://github.com/sockjs/sockjs-client/issues/28
+    // https://bugzilla.mozilla.org/show_bug.cgi?id=696085
+    that.unload_ref = utils.unload_add(function(){that.ws.close()});
     that.ws.onclose = function() {
         that.ri._didMessage(utils.closeFrame(1006, "WebSocket connection broken"));
     };
@@ -39,7 +36,8 @@ WebSocketTransport.prototype.doCleanup = function() {
     if (ws) {
         ws.onmessage = ws.onclose = null;
         ws.close();
-        that.ri = that.ws = null;
+        utils.unload_del(that.unload_ref);
+        that.unload_ref = that.ri = that.ws = 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