Author: abhinavsingh
Inheritance: extends XMPPStream
Example #1
0
 public function testProtocolOption()
 {
     $config = array('host' => 'domain.tld', 'port' => 5223, 'protocol' => 'tcp', 'strict' => false);
     $jaxl = new JAXL($config);
     $this->assertEquals('tcp://domain.tld:5223', $jaxl->get_socket_path());
     $this->assertInstanceOf('JAXLSocketClient', $jaxl->getTransport());
 }
Example #2
0
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
require dirname(__FILE__) . '/_bootstrap.php';
if ($argc < 3) {
    echo "Usage: {$argv['0']} jid pass" . PHP_EOL;
    exit;
}
//
// initialize JAXL object with initial config
//
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'log_level' => JAXLLogger::INFO));
$client->require_xep(array('0060'));
//
// add necessary event callbacks here
//
function on_auth_success_callback()
{
    global $client;
    JAXLLogger::info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    // create node
    //$client->xeps['0060']->create_node('pubsub.localhost', 'dummy_node');
    // publish
    $item = new JAXLXml('item', null, array('id' => time()));
    $item->c('entry', 'http://www.w3.org/2005/Atom');
    $item->c('title')->t('Soliloquy')->up();
    $item->c('summary')->t('To be, or not to be: that is the question')->up();
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
if ($argc < 5) {
    echo "Usage: {$argv['0']} jid pass room@service.domain.tld nickname\n";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'log_level' => JAXL_INFO));
$client->require_xep(array('0045', '0203'));
//
// add necessary event callbacks here
//
$_room_full_jid = $argv[3] . "/" . $argv[4];
$room_full_jid = new XMPPJid($_room_full_jid);
$client->add_cb('on_auth_success', function () {
    global $client, $room_full_jid;
    _info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    // join muc room
    $client->xeps['0045']->join_room($room_full_jid);
});
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    $client->send_end_stream();
Example #4
0
/**
 * Sample browser based one-to-one chat application using Jaxl library
 * Usage: Symlink or copy whole Jaxl library folder inside your web folder
 *        Edit "BOSHCHAT_POLL_URL" and "BOSHCHAT_ADMIN_JID" below to suit your environment
 *        Run this app file from the browser e.g. http://path/to/jaxl/app/boshchat.php
 *        View /var/log/jaxl.log for debug info
 * 
 * Read more: http://jaxl.net/example/boshchat.php
 */
// Ajax poll url
define('BOSHCHAT_POLL_URL', $_SERVER['PHP_SELF']);
if (isset($_REQUEST['jaxl'])) {
    // Valid bosh request
    // Initialize Jaxl Library
    require_once '/usr/share/php/jaxl/core/jaxl.class.php';
    $jaxl = new JAXL(array('domain' => 'localhost', 'port' => 5222, 'boshHost' => 'localhost', 'authType' => 'DIGEST-MD5', 'logLevel' => 4));
    // Admin jid who will receive all messages sent using this application ui
    define('BOSHCHAT_ADMIN_JID', 'admin@' . $jaxl->domain);
    // Include required XEP's
    $jaxl->requires(array('JAXL0115', 'JAXL0085', 'JAXL0092', 'JAXL0203', 'JAXL0202', 'JAXL0206'));
    // Sample Bosh chat application class
    class boshchat
    {
        public static function postAuth($payload, $jaxl)
        {
            $response = array('jaxl' => 'connected', 'jid' => $jaxl->jid);
            $jaxl->JAXL0206('out', $response);
        }
        public static function postRosterUpdate($payload, $jaxl)
        {
            $response = array('jaxl' => 'rosterList', 'roster' => $jaxl->roster);
                        if ($jid != null) {
                            $response = json_encode(array('Action' => 'IncomingCallEvent', 'Success' => 'True', 'From' => $from_caller_id, 'FromJid' => $from_jid, 'FromExt' => $from, 'Channel' => $event->getDestination()));
                            sendMessage($jid, $response);
                        }
                    }
                }
            } catch (Exception $e) {
                echo "Excepition in DialEvent: {$e}\n";
            }
        }
    }
});
// register_tick_function(array($pamiClient, 'process'));
$db = new Database();
$astdb = new AsteriskDB();
$xmpp_client = new JAXL(array('jid' => 'pbx', 'pass' => '123456', 'host' => 'avanpbx:5222'));
$xmpp_client->require_xep(array('0199'));
$connected = true;
$xmpp_client->add_cb('on_auth_failure', function ($reason) {
    global $xmpp_client;
    $xmpp_client->send_end_stream();
    _info("CALLBACK! got on_auth_failure cb with reason {$reason}");
});
$xmpp_client->add_cb('on_connect_error', function ($reason) {
    _info("connect error {$reason}");
});
$xmpp_client->add_cb('on_auth_success', function () {
    _info("connected!!");
    global $xmpp_client;
    $xmpp_client->set_status("available!", "dnd", 10);
});
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
if ($argc != 5) {
    echo "Usage: {$argv['0']} jid pass host port\n";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$comp = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'host' => @$argv[3], 'port' => $argv[4], 'log_level' => JAXL_INFO));
//
// XEP's required (required)
//
$comp->require_xep(array('0114'));
//
// add necessary event callbacks here
//
$comp->add_cb('on_auth_success', function () {
    _info("got on_auth_success cb");
});
$comp->add_cb('on_auth_failure', function ($reason) {
    global $comp;
    $comp->send_end_stream();
    _info("got on_auth_failure cb with reason {$reason}");
});
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
if ($argc < 3) {
    echo "Usage: {$argv['0']} jid pass\n";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'log_level' => JAXL_INFO));
$client->require_xep(array('0060'));
//
// add necessary event callbacks here
//
$client->add_cb('on_auth_success', function () {
    global $client;
    _info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    // create node
    //$client->xeps['0060']->create_node('pubsub.localhost', 'dummy_node');
    // subscribe
    $client->xeps['0060']->subscribe('pubsub.localhost', 'dummy_node');
});
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    $client->send_end_stream();
Example #8
0
/*
 * Sample browser based one-to-one chat application using Jaxl library
 * Usage: Copy this application file (along with /path/to/jaxl/env/jaxl.js) into your web folder.
 *        Edit "BOSHCHAT_POLL_URL" below to suit your environment.
 *        Run this app file from the browser.
 * Read more: http://bit.ly/aMozMy
 */
// Ajax poll url
define('BOSHCHAT_POLL_URL', 'http://localhost/boshchat.php');
// Admin jid who will receive all messages sent using this application ui
define('BOSHCHAT_ADMIN_JID', 'admin@localhost');
if (isset($_REQUEST['jaxl'])) {
    // Valid bosh request
    // Initialize Jaxl Library
    require_once '/usr/share/php/jaxl/core/jaxl.class.php';
    $jaxl = new JAXL(array('host' => 'localhost', 'domain' => 'localhost', 'port' => 5222, 'boshHost' => 'localhost', 'authType' => 'DIGEST-MD5', 'logLevel' => 5));
    // Include required XEP's
    $jaxl->requires(array('JAXL0115', 'JAXL0085', 'JAXL0092', 'JAXL0203', 'JAXL0202', 'JAXL0206'));
    // Sample Bosh chat application class
    class boshchat
    {
        public static function postAuth($payload, $jaxl)
        {
            $response = array('jaxl' => 'connected', 'jid' => $jaxl->jid);
            $jaxl->JAXL0206('out', $response);
        }
        public static function handleRosterList($payload, $jaxl)
        {
            $roster = array();
            if (is_array($payload['queryItemJid'])) {
                foreach ($payload['queryItemJid'] as $key => $jid) {
Example #9
0
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
require dirname(__FILE__) . '/_bootstrap.php';
if ($argc < 5) {
    echo "Usage: {$argv['0']} host jid pass room@service.domain.tld nickname" . PHP_EOL;
    exit;
}
//
// initialize JAXL object with initial config
//
$client = new JAXL(array('jid' => $argv[2], 'pass' => $argv[3], 'host' => $argv[1], 'log_level' => JAXLLogger::INFO));
$client->require_xep(array('0045', '0203', '0199'));
//
// add necessary event callbacks here
//
$_room_full_jid = $argv[4] . "/" . $argv[5];
$room_full_jid = new XMPPJid($_room_full_jid);
function on_auth_success_callback()
{
    global $client, $room_full_jid;
    JAXLLogger::info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    // join muc room
    $client->xeps['0045']->join_room($room_full_jid);
}
$client->add_cb('on_auth_success', 'on_auth_success_callback');
function on_auth_failure_callback($reason)
Example #10
0
File: echobot.php Project: ZZB/JAXL
<?php

/*
 * Sample command line echobot using Jaxl library
 * Usage: php echobot.php
 * Read More: http://bit.ly/bz9KXb
 */
// Initialize Jaxl Library
require_once '../core/jaxl.class.php';
// Values passed to the constructor can also be defined as constants
// List of constants can be found inside "../../env/jaxl.ini"
// Note: Values passed to the constructor always overwrite defined constants
$jaxl = new JAXL(array('user' => '', 'pass' => '', 'host' => 'talk.google.com', 'domain' => 'gmail.com', 'authType' => 'PLAIN', 'pingInterval' => 60, 'logLevel' => 5));
// Include required XEP's
$jaxl->requires(array('JAXL0115', 'JAXL0092', 'JAXL0199', 'JAXL0203', 'JAXL0202'));
// Sample Echobot class
class echobot
{
    function postAuth($payload, $jaxl)
    {
        $jaxl->discoItems($jaxl->domain, array($this, 'handleDiscoItems'));
        $jaxl->getRosterList(array($this, 'handleRosterList'));
    }
    function handleDiscoItems($payload, $jaxl)
    {
        if (!is_array($payload['queryItemJid'])) {
            return $payload;
        }
        $items = array_unique($payload['queryItemJid']);
        foreach ($items as $item) {
            $jaxl->discoInfo($item, array($this, 'handleDiscoInfo'));
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
if ($argc < 2) {
    echo "Usage: {$argv['0']} domain\n";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array('jid' => $argv[1], 'log_path' => JAXL_CWD . '/.jaxl/log/jaxl.log'));
$client->require_xep(array('0077'));
//
// below are two states which become part of
// our client's xmpp_stream lifecycle
// consider as if these methods are directly
// inside xmpp_stream state machine
//
// Note: $stanza = $args[0] is an instance of
// JAXLXml in xmpp_stream state methods,
// it is yet not ready for easy access
// patterns available on XMPPStanza instances
//
function wait_for_register_response($event, $args)
{
    global $client;
Example #12
0
<?php

/**
 * Sample command line bot for sending a message
 * Usage: cd /path/to/jaxl
 * 	      Edit username/password below
 * 		  Run from command line: /path/to/php sendMessage.php "*****@*****.**" "Your message"
 * 		  View jaxl.log for detail
 * 
 * Read More: http://jaxl.net/examples/sendMessage.php
 */
// Initialize Jaxl Library
require_once '../core/jaxl.class.php';
// Values passed to the constructor can also be defined as constants
// List of constants can be found inside "../../env/jaxl.ini"
// Note: Values passed to the constructor always overwrite defined constants
$jaxl = new JAXL(array('user' => 'username', 'pass' => 'password', 'host' => 'talk.google.com', 'domain' => 'gmail.com', 'authType' => 'DIGEST-MD5', 'logLevel' => 5));
// Post successful auth send desired message
function postAuth($payload, $jaxl)
{
    global $argv;
    $jaxl->sendMessage($argv[1], $argv[2]);
    $jaxl->shutdown();
}
// Register callback on required hooks
$jaxl->addPlugin('jaxl_post_auth', 'postAuth');
// Fire start Jaxl core
$jaxl->startCore("stream");
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
// Run as:
// php examples/echo_bot.php root@localhost password
// php examples/echo_bot.php root@localhost password DIGEST-MD5
// php examples/echo_bot.php localhost "" ANONYMOUS
if ($argc < 3) {
    echo "Usage: {$argv['0']} jid pass auth_type\n";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'auth_type' => @$argv[3] ? $argv[3] : 'PLAIN', 'log_level' => JAXL_INFO));
//
// required XEP's
//
$client->require_xep(array('0199'));
//
// add necessary event callbacks here
//
$client->add_cb('on_auth_success', function () {
    global $client;
    _info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    // fetch roster list
    $client->get_roster();
    // fetch vcard
    $client->get_vcard();
    // set status
Example #14
0
$db =& \MDB2::singleton($config['db']);
if (\PEAR::isError($db)) {
    die($db->getMessage());
}
$db->loadModule('Extended', null, false);
l("Getting identity...");
if ($argc >= 2) {
    $source = $argv[1];
    $nick = $argv[2];
} else {
    l("No identity!", L_AAAA);
    die;
}
$config['sim_prefix'] .= $nick;
l("[JAXL] Loading JAXL and connecting...");
$client = new \JAXL($config['jaxl']);
$client->require_xep(array('0045', '0203', '0199'));
$client->add_cb('on_auth_success', function () {
    global $client, $config, $rooms;
    l("[JAXL] Connected with jid " . $client->full_jid->to_string());
    $client->get_vcard();
    $client->get_roster();
    $client->set_status("", "chat", 10);
    $ctrl = new \XMPPJid($config['LCN_control'] . '/' . $config['sim_prefix']);
    l("[JAXL] Joining room " . $ctrl->to_string());
    $client->xeps['0045']->join_room($ctrl);
    l("[JAXL] Joined room " . $ctrl->to_string());
    $rooms = new \XMPPJid($config['sim'] . '/' . $config['sim_prefix']);
    l("[JAXL] Joining room " . $rooms->to_string());
    $client->xeps['0045']->join_room($rooms);
    l("[JAXL] Joined room " . $rooms->to_string());
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
if ($argc < 3) {
    echo "Usage: {$argv['0']} jid pass\n";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'log_level' => JAXL_INFO));
$client->require_xep(array('0060'));
//
// add necessary event callbacks here
//
$client->add_cb('on_auth_success', function () {
    global $client;
    _info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    // create node
    //$client->xeps['0060']->create_node('pubsub.localhost', 'dummy_node');
    // publish
    $item = new JAXLXml('item', null, array('id' => time()));
    $item->c('entry', 'http://www.w3.org/2005/Atom');
    $item->c('title')->t('Soliloquy')->up();
    $item->c('summary')->t('To be, or not to be: that is the question')->up();
    $item->c('link', null, array('rel' => 'alternate', 'type' => 'text/html', 'href' => 'http://denmark.lit/2003/12/13/atom03'))->up();
Example #16
0
/**
 * Sample command line echobot client using Jaxl library
 * Usage: cd /path/to/jaxl/app
 * 		  Edit passed config array to Jaxl constructor below to suit your environment
 * 		  Run from command line as: /path/to/php componentbot.php
 * 		  View /var/log/jaxl.log for debug info
 * 
 * Read More: http://jaxl.net/examples/echobot.php
 */
// Initialize Jaxl Library
require_once '../core/jaxl.class.php';
// Values passed to the constructor can also be defined as constants
// List of constants can be found inside "../../env/jaxl.ini"
// Note: Values passed to the constructor always overwrite defined constants
$jaxl = new JAXL(array('user' => 'username', 'pass' => 'password', 'host' => 'talk.google.com', 'domain' => 'gmail.com', 'authType' => 'PLAIN', 'autoSubscribe' => true, 'pingInterval' => 60, 'logLevel' => 4));
// Include required XEP's
$jaxl->requires(array('JAXL0115', 'JAXL0092', 'JAXL0199', 'JAXL0203', 'JAXL0202'));
// Sample Echobot class
class echobot
{
    function postAuth($payload, $jaxl)
    {
        $jaxl->discoItems($jaxl->domain, array($this, 'handleDiscoItems'));
        $jaxl->getRosterList();
    }
    function handleDiscoItems($payload, $jaxl)
    {
        if (!is_array($payload['queryItemJid'])) {
            return $payload;
        }
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
if (!isset($_GET['jid']) || !isset($_GET['pass'])) {
    echo "invalid input";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once '../jaxl.php';
$client = new JAXL(array('jid' => $_GET['jid'], 'pass' => $_GET['pass'], 'bosh_url' => 'http://localhost:5280/http-bind', 'log_level' => JAXL_DEBUG));
$client->add_cb('on_auth_success', function () {
    global $client;
    _info("got on_auth_success cb, jid " . $client->full_jid->to_string());
});
//
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
}
//
// add necessary event callbacks here
//
$client->add_cb('on_stream_features', function ($stanza) {
    global $client, $argv;
    $client->xeps['0077']->get_form($argv[1]);
    return "wait_for_register_form";
});
$client->add_cb('on_disconnect', function () {
    global $form;
    _info("registration " . ($form['type'] == 'result' ? 'succeeded' : 'failed'));
});
//
// finally start configured xmpp stream
//
$client->start();
//
// if registration was successful
// try to connect with newly registered account
//
if ($form['type'] == 'result') {
    _info("connecting newly registered user account");
    $client = new JAXL(array('jid' => $form['username'] . '@' . $argv[1], 'pass' => $form['password'], 'log_level' => JAXL_DEBUG));
    $client->add_cb('on_auth_success', function () {
        global $client;
        $client->set_status('Available');
    });
    $client->start();
}
echo "done\n";
Example #19
0
<?php

/* Include Key file */
include_once "config.ini.php";
/* Include JAXL Class */
include_once "jaxl.class.php";
/* Create an instance of XMPP Class */
$jaxl = new JAXL();
try {
    /* Initiate the connection */
    $jaxl->connect();
    /* Communicate with Jabber Server */
    while ($jaxl->isConnected) {
        $jaxl->getXML();
    }
} catch (Exception $e) {
    die($e->getMessage());
}
Example #20
0
<?php

define('BOSHCHAT_POLL_URL', $_SERVER['PHP_SELF']);
require_once '../core/func.php';
require_once '../core/jaxl.class.php';
if (!isset($_REQUEST['jaxl'])) {
    $_REQUEST['jaxl'] = '';
}
$jaxl = new JAXL(array('domain' => SERVER, 'port' => 5222, 'boshHost' => SERVER, 'authType' => 'DIGEST-MD5', 'logLevel' => 4));
$jaxl->requires(array('JAXL0115', 'JAXL0085', 'JAXL0092', 'JAXL0203', 'JAXL0202', 'JAXL0206', 'JAXL0060'));
// Sample Bosh chat application class
class boshchat
{
    public static function thisistestfunction($payload, $jaxl)
    {
        $response = array('jaxl' => 'connected', 'hello' => 'world');
        $jaxl->JAXL0206('out', $response);
    }
    public static function postAuth($payload, $jaxl)
    {
        //$response = array('jaxl'=>'connected', 'jid'=>$jaxl->jid);
        $jaxl->requires('JAXL0060');
        $jaxl->JAXL0060('getNodeItems', 'pubsub.64.22.114.70', 'user3@64.22.114.70', 'test1223', array('boshchat', 'thisistestfunction'));
    }
    public static function postRosterUpdate($payload, $jaxl)
    {
        $response = array('jaxl' => 'rosterList', 'roster' => $jaxl->roster);
        $jaxl->JAXL0206('out', $response);
    }
    public static function postDisconnect($payload, $jaxl)
    {
Example #21
0
$body = file_get_contents("php://input");
$body = new SimpleXMLElement($body);
$attrs = $body->attributes();
if (!isset($attrs['to']) && !isset($attrs['rid']) && !isset($attrs['wait']) && !isset($attrs['hold'])) {
    echo "invalid input";
    exit;
}
//
// initialize JAXL object with initial config
//
$to = (string) $attrs['to'];
$rid = (int) $attrs['rid'];
$wait = (int) $attrs['wait'];
$hold = (int) $attrs['hold'];
list($host, $port) = JAXLUtil::get_dns_srv($to);
$client = new JAXL(array('domain' => $to, 'host' => $host, 'port' => $port, 'bosh_url' => 'http://localhost:5280/http-bind', 'bosh_rid' => $rid, 'bosh_wait' => $wait, 'bosh_hold' => $hold, 'auth_type' => 'ANONYMOUS', 'log_level' => JAXLLogger::INFO));
function on_auth_success_callback()
{
    global $client;
    JAXLLogger::info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    echo sprintf('<body xmlns="%s" sid="%s" rid="%s" jid="%s"/>', XEP0206::NS_HTTP_BIND, $client->xeps['0206']->sid, $client->xeps['0206']->rid, $client->full_jid->to_string());
    exit;
}
$client->add_cb('on_auth_success', 'on_auth_success_callback');
function on_auth_failure_callback($reason)
{
    global $client;
    $client->send_end_stream();
    JAXLLogger::info("got on_auth_failure cb with reason {$reason}");
}
$client->add_cb('on_auth_failure', 'on_auth_failure_callback');
Example #22
0
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
require dirname(__FILE__) . '/_bootstrap.php';
// Run as:
// php examples/echo_bot.php root@localhost password
// php examples/echo_bot.php root@localhost password DIGEST-MD5
// php examples/echo_bot.php localhost "" ANONYMOUS
if ($argc < 3) {
    echo "Usage: {$argv['0']} jid pass auth_type" . PHP_EOL;
    exit;
}
//
// initialize JAXL object with initial config
//
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'auth_type' => isset($argv[3]) ? $argv[3] : 'PLAIN', 'log_level' => JAXLLogger::INFO));
//
// required XEP's
//
$client->require_xep(array('0199'));
//
// add necessary event callbacks here
//
function on_auth_success_callback()
{
    global $client;
    JAXLLogger::info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    // fetch roster list
    $client->get_roster();
    // fetch vcard
    $client->get_vcard();
Example #23
0
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
require dirname(__FILE__) . '/_bootstrap.php';
// View explanation for this example here:
// https://groups.google.com/d/msg/jaxl/QaGjZP4A2gY/n6SYutrBVxsJ
if ($argc < 3) {
    echo "Usage: {$argv['0']} jid pass" . PHP_EOL;
    exit;
}
// initialize xmpp client
$xmpp = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'log_level' => JAXLLogger::INFO));
// register callbacks on required xmpp events
function on_auth_success_callback()
{
    global $xmpp;
    JAXLLogger::info("got on_auth_success cb, jid " . $xmpp->full_jid->to_string());
}
$xmpp->add_cb('on_auth_success', 'on_auth_success_callback');
// initialize http server
$http = new HTTPServer();
// add generic callback
// you can also dispatch REST style callback
// Refer: http://jaxl.readthedocs.org/en/latest/users/http_extensions.html#dispatch-rules
function generic_callback($request)
{
    // For demo purposes we simply return xmpp client full jid
Example #24
0
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
require dirname(__FILE__) . '/_bootstrap.php';
if ($argc != 3) {
    echo "Usage: {$argv['0']} jid access_token" . PHP_EOL;
    exit;
}
//
// initialize JAXL object with initial config
//
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'force_tls' => true, 'auth_type' => 'X-OAUTH2', 'log_level' => JAXLLogger::DEBUG));
//
// add necessary event callbacks here
//
function on_auth_success_callback()
{
    global $client;
    JAXLLogger::info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    $client->set_status("available!", "dnd", 10);
}
$client->add_cb('on_auth_success', 'on_auth_success_callback');
function on_auth_failure_callback($reason)
{
    global $client;
    $client->send_end_stream();
    JAXLLogger::info("got on_auth_failure cb with reason {$reason}");
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
if ($argc < 3) {
    echo "Usage: {$argv['0']} jid pass\n";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$client = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'bosh_url' => 'http://*****:*****@$argv[3] ? $argv[3] : 'PLAIN', 'log_level' => JAXL_INFO));
//
// add necessary event callbacks here
//
$client->add_cb('on_auth_success', function () {
    global $client;
    _info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    $client->set_status("available!", "dnd", 10);
});
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    $client->send_end_stream();
    _info("got on_auth_failure cb with reason {$reason}");
});
$client->add_cb('on_chat_message', function ($stanza) {
    global $client;
Example #26
0
<?php

/*
 * Sample command line XMPP component bot using Jaxl library
 * Usage: php componentbot.php
 * Read more: http://bit.ly/aGpYf8
 */
// Initialize Jaxl Library
require_once '../core/jaxl.class.php';
$jaxl = new JAXL(array('port' => 5559, 'compHost' => 'component.localhost', 'compPass' => '', 'logLevel' => 5));
// Include required XEP's
$jaxl->requires('JAXL0114');
// Jabber Component Protocol
// Sample Component class
class componentbot
{
    function postAuth($payload, $jaxl)
    {
        $jaxl->log("Component handshake completed ...");
    }
    function getMessage($payloads, $jaxl)
    {
        foreach ($payloads as $payload) {
            if (strlen($payload['body']) > 0) {
                $jaxl->sendMessage($payload['from'], $payload['body'], $payload['to']);
            }
        }
    }
}
// Add callbacks on various event handlers
$componentbot = new componentbot();
$body = file_get_contents("php://input");
$body = new SimpleXMLElement($body);
$attrs = $body->attributes();
if (!@$attrs['to'] && !@$attrs['rid'] && !@$attrs['wait'] && !@$attrs['hold']) {
    echo "invalid input";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$to = $attrs['to'];
$rid = $attrs['rid'];
$wait = $attrs['wait'];
$hold = $attrs['hold'];
echo $to . " " . $rid . " " . $wait . " " . $hold;
exit;
list($host, $port) = JAXLUtil::get_dns_srv($to);
$client = new JAXL(array('domain' => $to, 'host' => $host, 'port' => $port, 'bosh_url' => 'http://localhost:5280/http-bind', 'bosh_rid' => $rid, 'bosh_wait' => $wait, 'bosh_hold' => $hold, 'auth_type' => 'ANONYMOUS'));
$client->add_cb('on_auth_success', function () {
    global $client;
    _info($client->full_jid->to_string());
    _info($client->xeps['0206']->sid);
    _info($client->xeps['0206']->rid);
    exit;
});
//
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
Example #28
0
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
require dirname(__FILE__) . '/_bootstrap.php';
if ($argc != 5) {
    echo "Usage: {$argv['0']} jid pass host port" . PHP_EOL;
    exit;
}
//
// initialize JAXL object with initial config
//
$comp = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'host' => $argv[3], 'port' => $argv[4], 'log_level' => JAXLLogger::INFO));
//
// XEP's required (required)
//
$comp->require_xep(array('0114'));
//
// add necessary event callbacks here
//
function on_auth_success_callback()
{
    JAXLLogger::info("got on_auth_success cb");
}
$comp->add_cb('on_auth_success', 'on_auth_success_callback');
function on_auth_failure_callback($reason)
{
    global $comp;
Example #29
0
 * This sample application demonstrate how to pre-fetch XMPP data from the jabber server
 * Specifically, this app will fetch logged in user VCard from the jabber server
 * Pre-fetched data can later be htmlized and displayed on the webpage
 *
 * Usage:
 * ------
 * 1) Put this file under your web folder
 * 2) Edit user/pass/domain/host below for your account
 * 3) Hit this file in your browser
 *
 * View jaxl.log for detail
 */
// include JAXL core
require_once '/usr/share/php/jaxl/core/jaxl.class.php';
// initialize JAXL instance
$xmpp = new JAXL(array('user' => '', 'pass' => '', 'domain' => 'localhost', 'host' => 'localhost', 'boshHost' => 'localhost', 'boshPort' => 5280, 'boshSuffix' => 'http-bind', 'boshOut' => false, 'logLevel' => 5));
// Include required XEP's
$xmpp->requires(array('JAXL0054', 'JAXL0206'));
function doAuth($mechanism, $xmpp)
{
    $xmpp->auth('DIGEST-MD5');
}
function postAuth($payload, $xmpp)
{
    $xmpp->JAXL0054('getVCard', false, $xmpp->jid, 'handleVCard');
}
function handleVCard($payload, $xmpp)
{
    echo "<b>Successfully fetched VCard</b><br/>";
    print_r($payload);
    $xmpp->JAXL0206('endStream');
Example #30
0
<?php

/**
 * Sample command line bot for sending a message
 * Usage: php sendMessage.php "*****@*****.**" "Your message"
 */
// Initialize Jaxl Library
require_once '../core/jaxl.class.php';
// Values passed to the constructor can also be defined as constants
// List of constants can be found inside "../../env/jaxl.ini"
// Note: Values passed to the constructor always overwrite defined constants
$jaxl = new JAXL(array('user' => '', 'pass' => '', 'host' => 'talk.google.com', 'domain' => 'gmail.com', 'authType' => 'PLAIN', 'logLevel' => 5));
// Post successful auth send desired message
function postAuth($payload, $jaxl)
{
    global $argv;
    $jaxl->sendMessage($argv[1], $argv[2]);
    $jaxl->shutdown();
}
// Register callback on required hooks
JAXLPlugin::add('jaxl_post_auth', 'postAuth');
// Fire start Jaxl core
$jaxl->startCore("stream");