瀏覽代碼

fix: Fixes ping options usage.

Due to no timeout value passed the disconnection was not detected.
dev1
damencho 4 年之前
父節點
當前提交
3516123210
共有 1 個檔案被更改,包括 3 行新增18 行删除
  1. 3
    18
      modules/xmpp/strophe.ping.js

+ 3
- 18
modules/xmpp/strophe.ping.js 查看文件

25
  */
25
  */
26
 const PING_DEFAULT_THRESHOLD = 2;
26
 const PING_DEFAULT_THRESHOLD = 2;
27
 
27
 
28
-/**
29
- * How often to send ping requests.
30
- */
31
-let pingInterval;
32
-
33
-/**
34
- * The time to wait for ping responses.
35
- */
36
-let pingTimeout;
37
-
38
-/**
39
- * How many ping failures will be tolerated before the connection is killed.
40
- */
41
-let pingThreshold;
42
-
43
 /**
28
 /**
44
  * XEP-0199 ping plugin.
29
  * XEP-0199 ping plugin.
45
  *
30
  *
143
                 this.failedPings += 1;
128
                 this.failedPings += 1;
144
                 const errmsg = `Ping ${error ? 'error' : 'timeout'}`;
129
                 const errmsg = `Ping ${error ? 'error' : 'timeout'}`;
145
 
130
 
146
-                if (this.failedPings >= pingThreshold) {
131
+                if (this.failedPings >= this.pingThreshold) {
147
                     GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));
132
                     GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));
148
                     logger.error(errmsg, error);
133
                     logger.error(errmsg, error);
149
                     this._onPingThresholdExceeded && this._onPingThresholdExceeded();
134
                     this._onPingThresholdExceeded && this._onPingThresholdExceeded();
150
                 } else {
135
                 } else {
151
                     logger.warn(errmsg, error);
136
                     logger.warn(errmsg, error);
152
                 }
137
                 }
153
-            }, pingTimeout);
138
+            }, this.pingTimeout);
154
         }, this.pingInterval);
139
         }, this.pingInterval);
155
         logger.info(`XMPP pings will be sent every ${this.pingInterval} ms`);
140
         logger.info(`XMPP pings will be sent every ${this.pingInterval} ms`);
156
     }
141
     }
213
         // remove the interval between the ping sent
198
         // remove the interval between the ping sent
214
         // this way in normal execution there is no suspend and the return
199
         // this way in normal execution there is no suspend and the return
215
         // will be 0 or close to 0.
200
         // will be 0 or close to 0.
216
-        maxInterval -= pingInterval;
201
+        maxInterval -= this.pingInterval;
217
 
202
 
218
         // make sure we do not return less than 0
203
         // make sure we do not return less than 0
219
         return Math.max(maxInterval, 0);
204
         return Math.max(maxInterval, 0);

Loading…
取消
儲存