/**
  * {@inheritdoc}
  */
 public function listen()
 {
     $this->xmpp->connectAndStartSession($this->timeout);
     // Add the message handler
     $this->xmpp->addXPathHandler('{jabber:client}message/{http://jabber.org/protocol/pubsub#event}event/{http://superfeedr.com/xmpp-pubsub-ext}status', 'handleMessage', $this);
     // Process messages repeatedly
     while (!$this->xmpp->isDisconnected()) {
         $results = $this->xmpp->processUntil('message', $this->timeout);
         if (count($results) === 0) {
             $this->logger->warn(sprintf('Superfeedr listener timed out (no messages for %d seconds).', $this->timeout));
             throw new Exception\TimeoutException(sprintf('No messages for %d seconds.  The connection may have been lost.', $this->timeout));
         }
     }
 }
 /**
  * Helper function to avoid repetition for subscription and unsubscription.
  * @param string $subscribeNode The name of the element describing a
  * subscribe or unsubscribe request, e.g. 'subscribe' or 'unsubscribe'.
  * @param array $urls The URLs to subscribe/unsubscribe.
  * @param bool $digest Whether to set the Superfeedr 'digest' attribute to
  * true on the subscription tags.
  */
 private function subscribeOrUnsubscribe($subscribeNode, array $urls, $digest)
 {
     $this->xmpp->connectAndStartSession($this->timeout);
     $jid = $this->xmpp->user . '@' . $this->xmpp->server;
     $id = $this->xmpp->getId();
     // Build up the IQ request
     $dom = new \DOMDocument();
     $iq = $dom->createElement('iq');
     $iq->setAttribute('type', 'set');
     $iq->setAttribute('to', $this->recipient);
     $iq->setAttribute('from', $jid);
     $iq->setAttribute('id', $id);
     $iq = $dom->appendChild($iq);
     // Create the top-level payload tag
     $pubsub = $dom->createElement('pubsub');
     $pubsub->setAttribute('xmlns', $this->pubSubXmlns);
     $pubsub->setAttribute('xmlns:superfeedr', $this->superfeedrXmlns);
     $pubsub = $iq->appendChild($pubsub);
     // Add subscription requests
     foreach ($urls as $url) {
         $subscribe = $dom->createElement($subscribeNode);
         $subscribe->setAttribute('node', $url);
         $subscribe->setAttribute('jid', $jid);
         if ($digest) {
             $subscribe->setAttribute('superfeedr:digest', 'true');
         }
         $pubsub->appendChild($subscribe);
     }
     $xml = $dom->saveXML($iq);
     // Send and wait for a response
     $this->xmpp->addIdHandler($id, 'handleResponse', $this);
     $this->xmpp->send($xml);
     $this->xmpp->processUntil('handle_subscription', $this->timeout);
     return $this->isSuccessful();
 }