]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
send a ping from the xmppdaemon
authorEvan Prodromou <evan@controlyourself.ca>
Thu, 9 Jul 2009 13:31:10 +0000 (09:31 -0400)
committerEvan Prodromou <evan@controlyourself.ca>
Thu, 9 Jul 2009 13:31:10 +0000 (09:31 -0400)
scripts/xmppdaemon.php

index bd1918ca98aa90b8fbe56e2cb29c75c3577bf348..488b4b514c46a8e997e5f14250380a49ad0fec42 100755 (executable)
@@ -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.");