Search code examples
phpxmppjaxl

How to IQ Query Action Protocol XMPP with JAXL PHP library


I want to send an iq query to xmpp and need a result that response from XMPP. For example:

<iq from='capulet.lit' to='[email protected]/balcony' id='s2c1' type='get'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>

Howerver i find all documents in http://jaxl.readthedocs.org/en/latest/users/xmpp_extensions.html and cant find the way to do that. So hope that someone can help me. Thanks


Solution

  • First off, their docs are almost entirely non-existent. File a bug, or better yet, send them a pull request.

    For pings in particular:

    $client->require_xep(array(
        '0199'  // XMPP Ping
    ));
    

    If you want to write your own protocols, look at their XEP-0199 implementation for an example:

    public function get_ping_pkt() {
        $attrs = array(
            'type'=>'get',
            'from'=>$this->jaxl->full_jid->to_string(),
            'to'=>$this->jaxl->full_jid->domain
        );
    
        return $this->jaxl->get_iq_pkt(
            $attrs,
            new JAXLXml('ping', NS_XMPP_PING)
        );
    }