summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/xmppqueuehandler.php25
-rwxr-xr-xscripts/xmppdaemon.php21
2 files changed, 44 insertions, 2 deletions
diff --git a/lib/xmppqueuehandler.php b/lib/xmppqueuehandler.php
index c8b5ad1fb..9b1a6989e 100644
--- a/lib/xmppqueuehandler.php
+++ b/lib/xmppqueuehandler.php
@@ -30,6 +30,8 @@ require_once(INSTALLDIR.'/lib/queuehandler.php');
class XmppQueueHandler extends QueueHandler
{
+ var $pingid = 0;
+
function start()
{
# Low priority; we don't want to receive messages
@@ -44,6 +46,11 @@ class XmppQueueHandler extends QueueHandler
return !is_null($this->conn);
}
+ function timeout()
+ {
+ return 10;
+ }
+
function handle_reconnect(&$pl)
{
$this->conn->processUntil('session_start');
@@ -55,7 +62,9 @@ class XmppQueueHandler extends QueueHandler
# Process the queue for as long as needed
try {
if ($this->conn) {
+ $this->log(LOG_DEBUG, "Servicing the XMPP queue.");
$this->conn->processTime($timeout);
+ $this->sendPing();
}
} catch (XMPPHP_Exception $e) {
$this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
@@ -63,6 +72,22 @@ class XmppQueueHandler extends QueueHandler
}
}
+ function sendPing()
+ {
+ $jid = jabber_daemon_address().'/'.$this->_id.$this->transport();
+ $server = common_config('xmpp', 'server');
+
+ if (!isset($this->pingid)) {
+ $this->pingid = 0;
+ } else {
+ $this->pingid++;
+ }
+
+ $this->log(LOG_DEBUG, "Sending ping #{$this->pingid}");
+
+ $this->conn->send("<iq from='{$jid}' to='{$server}' id='ping_{$this->pingid}' type='get'><ping xmlns='urn:xmpp:ping'/></iq>");
+ }
+
function forward_message(&$pl)
{
if ($pl['type'] != 'chat') {
diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php
index bd1918ca9..488b4b514 100755
--- a/scripts/xmppdaemon.php
+++ b/scripts/xmppdaemon.php
@@ -60,7 +60,9 @@ class XMPPDaemon extends Daemon
$this->resource = common_config('xmpp', 'resource') . 'daemon';
}
- $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}");
+ $this->jid = $this->user.'@'.$this->server.'/'.$this->resource;
+
+ $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->jid}");
}
function connect()
@@ -106,10 +108,25 @@ class XMPPDaemon extends Daemon
$this->log(LOG_DEBUG, "Beginning processing loop.");
- $this->conn->process();
+ while ($this->conn->processTime(60)) {
+ $this->sendPing();
+ }
}
}
+ function sendPing()
+ {
+ if (!isset($this->pingid)) {
+ $this->pingid = 0;
+ } else {
+ $this->pingid++;
+ }
+
+ $this->log(LOG_DEBUG, "Sending ping #{$this->pingid}");
+
+ $this->conn->send("<iq from='{$this->jid}' to='{$this->server}' id='ping_{$this->pingid}' type='get'><ping xmlns='urn:xmpp:ping'/></iq>");
+ }
+
function handle_reconnect(&$pl)
{
$this->log(LOG_DEBUG, "Got reconnection callback.");