Explorar o código

converse-core: Call _tearDown when initialized again

When it's clear that a previous teardown didn't happen.
So that objects can be garbage collected and that obsolete event handlers don't
fire anymore.
JC Brand %!s(int64=8) %!d(string=hai) anos
pai
achega
008c07596a
Modificáronse 1 ficheiros con 9 adicións e 0 borrados
  1. 9 0
      src/converse-core.js

+ 9 - 0
src/converse-core.js

@@ -134,6 +134,15 @@
         settings = typeof settings !== "undefined" ? settings : {};
         var init_deferred = new $.Deferred();
         var converse = this;
+
+        if (typeof converse.chatboxes !== 'undefined') {
+            // Looks like converse.initialized was called again without logging
+            // out or disconnecting in the previous session.
+            // This happens in tests.
+            // We therefore first clean up.
+            converse._tearDown();
+        }
+
         var unloadevent;
         if ('onpagehide' in window) {
             // Pagehide gets thrown in more cases than unload. Specifically it