In this blog post we will dig deep into the core of Jaxl 2.0 – An XMPP framework written in PHP. Specifically, we will go through Jaxl core directory structure. Towards the end we will get familiar with various core classes and their available methods (e.g. $jaxl->sendMessage()), that developers can use in their XMPP applications.
Core Directory Structure
Now that you have the source code, lets get familiar with the Jaxl directory structure. Downloaded source code consists of following 5 directories:
- xmpp: Contain core stack which implements XMPP rfc’s. All files follow naming convention like xmpp.*.php
- core: Contains core stack which manages the library workflow. Also provides an xpath based XML parser, an event mechanism and various other utilities to the framework. All files follow naming convention like jaxl.*.php
- xep: Contains implemented XMPP extensions (XEP’s). All files follow naming convention like jaxl.XEP-NUMBER.php
- env: Contains Jaxl main() file jaxl.php, Jaxl core configuration file jaxl.conf and application environment setup file jaxl.ini. For bosh application developers jaxl.js is a must include from this directory.
- app: Contains example applications which comes packed with Jaxl library
Core Classes and Available Methods
Below is a detailed list of all the core classes and available methods in developer land space:
JAXL
This class is located inside core/jaxl.class.php and extends base XMPP class. Following is a list of methods available:
- __construct($config=array()) : Constructor can accepts following configuration parameters:
$config = array( 'user' => 'username', // connecting username 'pass' => 'password', // connecting user password 'host' => 'chat.facebook.com', // connecting jabber host 'domain' => 'chat.facebook.com', // connecting jabber domain 'port' => 5222, // connecting jabber port 'streamTimeout' => 20, 'resource' => 'jaxl', 'component' => 'component.localhost' // connecting component bind host )Passed parameters overwrites the configuration options specified your application configuration file jaxl.ini
- auth($type) : Performs authentication with the jabber server. DIGEST-MD5, PLAIN, X-FACEBOOK-PLATFORM and ANONYMOUS are the supported auth
$type - setStatus($status=FALSE, $show=FALSE, $priority=FALSE, $caps=FALSE) : Update the status of connected jabber user. Pass
$caps=TRUEfor sending entity capability information while setting connected user status. - subscribe($toJid)
- subscribed($toJid)
- unsubscribe($toJid)
- unsubscribed($toJid)
- getRosterList($callback=FALSE) : Fetch roster list for the connected user. See example usage inside echobot application.
- addRoster($jid, $group, $name=FALSE)
- updateRoster($jid, $group, $name=FALSE, $subscription=FALSE)
- deleteRoster($jid)
- sendMessage($to, $message, $from=FALSE, $type=’chat’)
- $jaxl->requires($class) : It is an alternative for jaxl_require($class, $jaxl).
- $jaxl->xml->xmlize($xml) : Use this method to convert raw XML string into an array.
- $jaxl->log($log, $level) : Use this method for logging purposes
JAXLPlugin
This class is located inside core/jaxl.plugin.php. Following is a list of methods available:
- add($hook, $callback, $priority=10) : Register callback on available hooks
- remove($hook, $callback) : Un-register callback on a previously registered hooks using
addmethod
JAXLUtil
This class is located inside core/jaxl.util.php. Following is a list of methods available:
- isWin() : Window OS detection, return bool
- getTime()
- getBareJid($jid)
- splitJid($jid)
- curl($url, $type=’GET’, $headers=FALSE, $data=FALSE, $user=FALSE, $pass=FALSE)
More methods might get added in future and will be updated here.
Using available XEP methods
Once have included required XEP class inside your application code, either by using jaxl_require('JAXLxxxx', $jaxl) or by calling $jaxl->requires('JAXLxxxx'), you can start using the available methods inside included XEP class as follows:
$jaxl->JAXLxxxx('methodName', $param1, $param2, ....);
e.g. If you want to call joinRoom methods of Multi-User Chat XEP-0045, you can do so by calling
$jaxl->JAXL0045('joinRoom', $jid, $roomJid.'/'.$nick, $history, $seconds)
. DO-NOT call the method like JAXL0045::joinRoom(…)
Abhi's Weblog is a collection of blog articles written by
[...] Jaxl Core classes, available methods and directory structure [...]