|
@@ -14,14 +14,16 @@ const logger = getLogger(__filename);
|
14
|
14
|
const PING_INTERVAL = 10000;
|
15
|
15
|
|
16
|
16
|
/**
|
17
|
|
- * Ping timeout error after 15 sec of waiting.
|
|
17
|
+ * Ping timeout error after 5 sec of waiting.
|
18
|
18
|
*/
|
19
|
|
-const PING_TIMEOUT = 15000;
|
|
19
|
+const PING_TIMEOUT = 5000;
|
20
|
20
|
|
21
|
21
|
/**
|
22
|
|
- * Will close the connection after 3 consecutive ping errors.
|
|
22
|
+ * How many ping failures will be tolerated before the WebSocket connection is killed.
|
|
23
|
+ * The worst case scenario in case of ping timing out without a response is (25 seconds at the time of this writing):
|
|
24
|
+ * PING_THRESHOLD * PING_INTERVAL + PING_TIMEOUT
|
23
|
25
|
*/
|
24
|
|
-const PING_THRESHOLD = 3;
|
|
26
|
+const PING_THRESHOLD = 2;
|
25
|
27
|
|
26
|
28
|
/**
|
27
|
29
|
* The number of timestamps of send pings to keep.
|
|
@@ -38,14 +40,16 @@ const PING_TIMESTAMPS_TO_KEEP = 120000 / PING_INTERVAL;
|
38
|
40
|
export default class PingConnectionPlugin extends ConnectionPlugin {
|
39
|
41
|
/**
|
40
|
42
|
* Contructs new object
|
41
|
|
- * @param {XMPP} xmpp the xmpp module.
|
|
43
|
+ * @param {Object} options
|
|
44
|
+ * @param {Function} options.onPingThresholdExceeded - Callback called when ping fails too many times (controlled
|
|
45
|
+ * by the {@link PING_THRESHOLD} constant).
|
42
|
46
|
* @constructor
|
43
|
47
|
*/
|
44
|
|
- constructor(xmpp) {
|
|
48
|
+ constructor({ onPingThresholdExceeded }) {
|
45
|
49
|
super();
|
46
|
50
|
this.failedPings = 0;
|
47
|
|
- this.xmpp = xmpp;
|
48
|
51
|
this.pingExecIntervals = new Array(PING_TIMESTAMPS_TO_KEEP);
|
|
52
|
+ this._onPingThresholdExceeded = onPingThresholdExceeded;
|
49
|
53
|
}
|
50
|
54
|
|
51
|
55
|
/**
|
|
@@ -101,13 +105,7 @@ export default class PingConnectionPlugin extends ConnectionPlugin {
|
101
|
105
|
if (this.failedPings >= PING_THRESHOLD) {
|
102
|
106
|
GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));
|
103
|
107
|
logger.error(errmsg, error);
|
104
|
|
-
|
105
|
|
- // FIXME it doesn't help to disconnect when 3rd PING
|
106
|
|
- // times out, it only stops Strophe from retrying.
|
107
|
|
- // Not really sure what's the right thing to do in that
|
108
|
|
- // situation, but just closing the connection makes no
|
109
|
|
- // sense.
|
110
|
|
- // self.connection.disconnect();
|
|
108
|
+ this._onPingThresholdExceeded && this._onPingThresholdExceeded();
|
111
|
109
|
} else {
|
112
|
110
|
logger.warn(errmsg, error);
|
113
|
111
|
}
|