Browse Source

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 years ago
parent
commit
56351f89f2
1 changed files with 8 additions and 6 deletions
  1. 8
    6
      modules/xmpp/strophe.ping.js

+ 8
- 6
modules/xmpp/strophe.ping.js View File

120
             // when there were some server responses in the interval since the last time we checked (_lastServerCheck)
120
             // when there were some server responses in the interval since the last time we checked (_lastServerCheck)
121
             // let's skip the ping
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
                 // do this just to keep in sync the intervals so we can detect suspended device
126
                 // do this just to keep in sync the intervals so we can detect suspended device
128
                 this._addPingExecutionTimestamp();
127
                 this._addPingExecutionTimestamp();
129
 
128
 
130
-                this._lastServerCheck = new Date();
129
+                this._lastServerCheck = now;
131
                 this.failedPings = 0;
130
                 this.failedPings = 0;
132
 
131
 
133
                 return;
132
                 return;
134
             }
133
             }
135
 
134
 
136
             this.ping(remoteJid, () => {
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
                 this.failedPings = 0;
141
                 this.failedPings = 0;
140
             }, error => {
142
             }, error => {

Loading…
Cancel
Save