Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Reacts to consecutive ping failures by closing the connection.

paweldomas9a77ddc54c62
diff --git a/modules/xmpp/strophe.ping.js b/modules/xmpp/strophe.ping.js
index 05dd029cc2..b11f65119e 100644
--- a/modules/xmpp/strophe.ping.js
+++ b/modules/xmpp/strophe.ping.js
@@ -2,20 +2,33 @@
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
-var PING_INTERVAL = 15000;
+/**
+ * Ping every 20 sec
+ */
+var PING_INTERVAL = 20000;
+
+/**
+ * Ping timeout error after 15 sec of waiting.
+ */
+var PING_TIMEOUT = 15000;
-var PING_TIMEOUT = 10000;
+/**
+ * Will close the connection after 3 consecutive ping errors.
+ */
+var PING_THRESHOLD = 3;
/**
* XEP-0199 ping plugin.
*
* Registers "urn:xmpp:ping" namespace under Strophe.NS.PING.
*/
-module.exports = function () {
+module.exports = function (XMPP, eventEmitter) {
Strophe.addConnectionPlugin('ping', {
connection: null,
+ failedPings: 0,
+
/**
* Initializes the plugin. Method called by Strophe.
* @param connection Strophe connection instance.
@@ -59,11 +72,15 @@ module.exports = function () {
self.ping(remoteJid,
function (result) {
// Ping OK
+ self.failedPings = 0;
},
function (error) {
+ self.failedPings += 1;
console.error(
"Ping " + (error ? "error" : "timeout"), error);
- //FIXME: react
+ if (self.failedPings >= PING_THRESHOLD) {
+ self.connection.disconnect();
+ }
}, PING_TIMEOUT);
}, interval);
console.info("XMPP pings will be sent every " + interval + " ms");
@@ -76,6 +93,7 @@ module.exports = function () {
if (this.intervalId) {
window.clearInterval(this.intervalId);
this.intervalId = null;
+ this.failedPings = 0;
console.info("Ping interval cleared");
}
}
diff --git a/modules/xmpp/xmpp.js b/modules/xmpp/xmpp.js
index a904bdf639..4afd060c75 100644
--- a/modules/xmpp/xmpp.js
+++ b/modules/xmpp/xmpp.js
@@ -171,7 +171,7 @@ function initStrophePlugins()
require("./strophe.jingle")(XMPP, eventEmitter);
require("./strophe.moderate")(XMPP, eventEmitter);
require("./strophe.util")();
- require("./strophe.ping")();
+ require("./strophe.ping")(XMPP, eventEmitter);
require("./strophe.rayo")();
require("./strophe.logger")();
}