Преглед на файлове

Emit a `reconnecting` event.

JC Brand преди 8 години
родител
ревизия
0b22b5a6e0
променени са 3 файла, в които са добавени 14 реда и са изтрити 9 реда
  1. 2 1
      docs/CHANGES.md
  2. 6 0
      docs/source/events.rst
  3. 6 8
      src/converse-core.js

+ 2 - 1
docs/CHANGES.md

@@ -4,7 +4,7 @@
 - #721 keepalive not working with anonymous authentication [jcbrand]
 - Enable new rooms to be configured automatically, with a default config, via `rooms.open`.
   For details, refer to the [relevant documentation](https://conversejs.org/docs/html/developer_api.html#the-rooms-grouping) [jcbrand]
-- Bugfix: Arrays in configuration settings were ignored. [jcbrand]
+- #723 Bugfix: Arrays in configuration settings were ignored. [jcbrand]
 - Bugfix: Chatboxes aren't closed when logging out. [jcbrand]
 - Bugfix: Trying to save data on the `ControlBox` model before `ChatBoxes`
   collection has its `browserStorage` configured.
@@ -15,6 +15,7 @@
 - Remove (undocumented) `callback` config parameter for `converse.initialize`.
   Instead, `converse.initialize` returns a promise which will resolve once
   initialization is complete. [jcbrand]
+- New event ['reconnecting'](https://conversejs.org/docs/html/development.html#reconnecting) [jcbrand]
 
 ## 2.0.1 (2016-11-07)
 - #203 New configuration setting [muc_domain](https://conversejs.org/docs/html/configuration.html#muc_domain) [jcbrand]

+ 6 - 0
docs/source/events.rst

@@ -159,6 +159,12 @@ is in `converse-notifications.js <https://github.com/jcbrand/converse.js/blob/ma
 
 ``converse.listen.on('pluginsInitialized', function (event) { ... });``
 
+reconnecting
+~~~~~~~~~~~~
+
+Fired once converse.js has determined that it will attempt to reconnect (and
+each subsequent time, if it attempts repeatedly).
+
 reconnected
 ~~~~~~~~~~~
 

+ 6 - 8
src/converse-core.js

@@ -400,19 +400,17 @@
         }, 1000);
 
         this.onDisconnected = function (condition) {
-            if (converse.disconnection_cause !== converse.LOGOUT) {
-                if (converse.disconnection_cause === Strophe.Status.CONNFAIL && converse.auto_reconnect) {
+            if (converse.disconnection_cause !== converse.LOGOUT && converse.auto_reconnect) {
+                if (converse.disconnection_cause === Strophe.Status.CONNFAIL) {
                     converse.reconnect(condition);
                     converse.log('RECONNECTING');
-                    return 'reconnecting';
-                } else if (
-                        (converse.disconnection_cause === Strophe.Status.DISCONNECTING ||
-                        converse.disconnection_cause === Strophe.Status.DISCONNECTED) &&
-                            converse.auto_reconnect) {
+                } else if (converse.disconnection_cause === Strophe.Status.DISCONNECTING ||
+                           converse.disconnection_cause === Strophe.Status.DISCONNECTED) {
                     window.setTimeout(_.partial(converse.reconnect, condition), 3000);
                     converse.log('RECONNECTING IN 3 SECONDS');
-                    return 'reconnecting';
                 }
+                converse.emit('reconnecting');
+                return 'reconnecting';
             }
             delete converse.connection.reconnecting;
             converse._tearDown();