瀏覽代碼

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 年之前
父節點
當前提交
cf584f56e4
共有 2 個文件被更改,包括 9 次插入4 次删除
  1. 8
    3
      modules/xmpp/StropheLastSuccess.js
  2. 1
    1
      modules/xmpp/XmppConnection.js

+ 8
- 3
modules/xmpp/StropheLastSuccess.js 查看文件

@@ -12,13 +12,18 @@ export default class LastRequestTracker {
12 12
     /**
13 13
      * Starts tracking requests on the given connection.
14 14
      *
15
+     * @param {XmppConnection} xmppConnection - The XMPP connection which manages the given {@code stropheConnection}.
15 16
      * @param {Object} stropheConnection - Strophe connection instance.
16 17
      */
17
-    startTracking(stropheConnection) {
18
+    startTracking(xmppConnection, stropheConnection) {
18 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 27
             originalRawInput.apply(stropheConnection, args);
23 28
         };
24 29
     }

+ 1
- 1
modules/xmpp/XmppConnection.js 查看文件

@@ -65,7 +65,7 @@ export default class XmppConnection extends Listenable {
65 65
         this._stropheConn.maxRetries = 3;
66 66
 
67 67
         this._lastSuccessTracker = new LastSuccessTracker();
68
-        this._lastSuccessTracker.startTracking(this._stropheConn);
68
+        this._lastSuccessTracker.startTracking(this, this._stropheConn);
69 69
 
70 70
         /**
71 71
          * @typedef DeferredSendIQ Object

Loading…
取消
儲存