Browse Source

fix(StropheLastSuccess): refresh the timestamp in connected

An 'item-not-found' or other error on Websocket reconnect will refresh
the timestamp which will give misleading information about when
the last stanza was received.
master
paweldomas 4 years ago
parent
commit
cf584f56e4
2 changed files with 9 additions and 4 deletions
  1. 8
    3
      modules/xmpp/StropheLastSuccess.js
  2. 1
    1
      modules/xmpp/XmppConnection.js

+ 8
- 3
modules/xmpp/StropheLastSuccess.js View File

12
     /**
12
     /**
13
      * Starts tracking requests on the given connection.
13
      * Starts tracking requests on the given connection.
14
      *
14
      *
15
+     * @param {XmppConnection} xmppConnection - The XMPP connection which manages the given {@code stropheConnection}.
15
      * @param {Object} stropheConnection - Strophe connection instance.
16
      * @param {Object} stropheConnection - Strophe connection instance.
16
      */
17
      */
17
-    startTracking(stropheConnection) {
18
+    startTracking(xmppConnection, stropheConnection) {
18
         const originalRawInput = stropheConnection.rawInput;
19
         const originalRawInput = stropheConnection.rawInput;
19
 
20
 
20
-        stropheConnection.rawInput = function(...args) {
21
-            this._lastSuccess = Date.now();
21
+        stropheConnection.rawInput = (...args) => {
22
+            // It's okay to use rawInput callback only once the connection has been established, otherwise it will
23
+            // treat 'item-not-found' or other connection error on websocket reconnect as successful stanza received.
24
+            if (xmppConnection.connected) {
25
+                this._lastSuccess = Date.now();
26
+            }
22
             originalRawInput.apply(stropheConnection, args);
27
             originalRawInput.apply(stropheConnection, args);
23
         };
28
         };
24
     }
29
     }

+ 1
- 1
modules/xmpp/XmppConnection.js View File

65
         this._stropheConn.maxRetries = 3;
65
         this._stropheConn.maxRetries = 3;
66
 
66
 
67
         this._lastSuccessTracker = new LastSuccessTracker();
67
         this._lastSuccessTracker = new LastSuccessTracker();
68
-        this._lastSuccessTracker.startTracking(this._stropheConn);
68
+        this._lastSuccessTracker.startTracking(this, this._stropheConn);
69
 
69
 
70
         /**
70
         /**
71
          * @typedef DeferredSendIQ Object
71
          * @typedef DeferredSendIQ Object

Loading…
Cancel
Save