Selaa lähdekoodia

fix: Updates ping logic around detecting xmpp activity.

Now stores the time of the raw input when ping is received. Before this change we were storing the Date.now and comparing to _getTimeSinceLastServerResponse and we needed small adjustment of values as it may lead to no pings sent.
dev1
damencho 4 vuotta sitten
vanhempi
commit
56351f89f2
1 muutettua tiedostoa jossa 8 lisäystä ja 6 poistoa
  1. 8
    6
      modules/xmpp/strophe.ping.js

+ 8
- 6
modules/xmpp/strophe.ping.js Näytä tiedosto

@@ -120,21 +120,23 @@ export default class PingConnectionPlugin extends ConnectionPlugin {
120 120
             // when there were some server responses in the interval since the last time we checked (_lastServerCheck)
121 121
             // let's skip the ping
122 122
 
123
-            // server response is measured on raw input and ping response time is measured after all the xmpp
124
-            // processing is done, and when the last server response is a ping there can be slight misalignment of the
125
-            // times, we give it 100ms for that processing.
126
-            if (this._getTimeSinceLastServerResponse() + 100 < new Date() - this._lastServerCheck) {
123
+            const now = Date.now();
124
+
125
+            if (this._getTimeSinceLastServerResponse() < now - this._lastServerCheck) {
127 126
                 // do this just to keep in sync the intervals so we can detect suspended device
128 127
                 this._addPingExecutionTimestamp();
129 128
 
130
-                this._lastServerCheck = new Date();
129
+                this._lastServerCheck = now;
131 130
                 this.failedPings = 0;
132 131
 
133 132
                 return;
134 133
             }
135 134
 
136 135
             this.ping(remoteJid, () => {
137
-                this._lastServerCheck = new Date();
136
+                // server response is measured on raw input and ping response time is measured after all the xmpp
137
+                // processing is done in js, so there can be some misalignment when we do the check above.
138
+                // That's why we store the last time we got the response
139
+                this._lastServerCheck = this._getTimeSinceLastServerResponse() + Date.now();
138 140
 
139 141
                 this.failedPings = 0;
140 142
             }, error => {

Loading…
Peruuta
Tallenna