add_cb() public method

Add callback.
See also: JAXLEvent::add
public add_cb ( string $ev, callable $cb, integer $priority = 1 ) : string
$ev string Event to subscribe.
$cb callable
$priority integer
return string
示例#1
0
 /**
  * Handles disconnections
  */
 private function attachOnDisconnectListener()
 {
     $this->client->add_cb('on_disconnect', function () {
         $this->getContainer()->get('logger')->warn('Got disconnected from XMPP. Reconnecting.');
         $this->startClient();
     });
 }
 * "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";
// 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();
    $item->c('id')->t('tag:denmark.lit,2003:entry-32397')->up();
    $item->c('published')->t('2003-12-13T18:30:02Z')->up();
    $item->c('updated')->t('2003-12-13T18:30:02Z')->up();
    $client->xeps['0060']->publish_item('pubsub.localhost', 'dummy_node', $item);
});
$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_disconnect', function () {
    _info("got on_disconnect cb");
});
示例#4
0
//
// 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;
    $comp->send_end_stream();
    JAXLLogger::info("got on_auth_failure cb with reason {$reason}");
}
$comp->add_cb('on_auth_failure', 'on_auth_failure_callback');
function on_chat_message_callback($stanza)
{
    global $comp;
    // echo back incoming message stanza
    $stanza->to = $stanza->from;
    $stanza->from = $comp->jid->to_string();
    $comp->send($stanza);
}
$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 = (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' => JAXL_INFO));
$client->add_cb('on_auth_success', function () {
    global $client;
    _info("got on_auth_success cb, jid " . $client->full_jid->to_string());
    echo '<body xmlns="' . NS_HTTP_BIND . '" sid="' . $client->xeps['0206']->sid . '" rid="' . $client->xeps['0206']->rid . '" jid="' . $client->full_jid->to_string() . '"/>';
    exit;
});
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    _info("got on_auth_failure cb with reason {$reason}");
    $client->send_end_stream();
});
//
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
$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";
                }
            } 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);
});
$xmpp_client->add_cb('on_disconnect', function () {
    _info("disconnected!!");
    // _info("reconnecting");
    // global $xmpp_client;
    // $xmpp_client->con();
    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}");
});
$comp->add_cb('on_chat_message', function ($stanza) {
    global $comp;
    // echo back incoming message stanza
    $stanza->to = $stanza->from;
    $stanza->from = $comp->jid->to_string();
    $comp->send($stanza);
});
$comp->add_cb('on_disconnect', function () {
    _info("got on_disconnect cb");
// 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
    $client->set_status("available!", "dnd", 10);
});
// by default JAXL instance catches incoming roster list results and updates
// roster list is parsed/cached and an event 'on_roster_update' is emitted
$client->add_cb('on_roster_update', function () {
    //global $client;
    //print_r($client->roster);
});
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    _info("got on_auth_failure cb with reason {$reason}");
    $client->send_end_stream();
});
示例#10
0
} 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());
});
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    $client->send_end_stream();
    l("[JAXL] Auth failure: " . $reason, L_WARN);
});
// Where the magic happens. "Magic" "Happens". I dunno why I type this either.
$client->add_cb('on_groupchat_message', function ($stanza) {
    global $config, $client, $source, $nick;
示例#11
0
function on_presence_stanza($client, $stanza)
{
    global $client;
    $type = $stanza->type ? $stanza->type : "available";
    $show = $stanza->show ? $stanza->show : "???";
    _info($stanza->from . " is now " . $type . " ({$show})");
    if ($type == "available") {
        // fetch vcard
        $client->get_vcard($stanza->from);
    }
}
function on_disconnect($client)
{
    _info("got on_disconnect cb");
}
//
// bootstrap all account instances
//
foreach ($accounts as $account) {
    $client = new JAXL(array('jid' => $account[0], 'pass' => $account[1], 'log_level' => JAXL_DEBUG));
    $client->add_cb('on_auth_success', 'on_auth_success');
    $client->add_cb('on_auth_failure', 'on_auth_failure');
    $client->add_cb('on_chat_message', 'on_chat_message');
    $client->add_cb('on_presence_stanza', 'on_presence_stanza');
    $client->add_cb('on_disconnect', 'on_disconnect');
    $client->connect($client->get_socket_path());
    $client->start_stream();
}
// start core loop
JAXLLoop::run();
echo "done\n";
示例#12
0
            }
        }
    }
});
$status_types = array('available' => true, 'chat' => true, 'away' => false, 'dnd' => false, 'xa' => false, 'unavailable' => false);
$domain = FreePBX::Xmpp()->getOption('domain');
$roster = array();
$component_status = 'unavailable';
stream_set_timeout($astman->socket, 0, 30000);
$periodic_jobs = array();
require_once 'JAXL/jaxl.php';
while (true) {
    $comp = new JAXL(array('jid' => 'asterisk.' . $domain, 'pass' => 'asterisk', 'host' => 'localhost', 'port' => '5347', 'strict' => FALSE, 'priv_dir' => '/tmp/.jaxl', 'log_level' => 0));
    $comp->require_xep(array('0114'));
    $comp->add_cb('on_connect', function () {
        global $astman;
        JAXLLoop::watch($astman->socket, array('read' => 'manager_read'));
    });
    $comp->add_cb('on_disconnect', function () {
        global $astman;
        global $periodic_jobs;
        JAXLLoop::unwatch($astman->socket, array('read' => true));
        foreach ($periodic_jobs as $job) {
            JAXLLoop::$clock->cancel_fun_call($job);
        }
    });
    $comp->add_cb('on_auth_success', function () {
        global $periodic_jobs;
        global $astman;
        global $comp;
        global $domain;
        global $component_status;
示例#13
0
require_once 'jwt/src/SignatureInvalidException.php';
require_once 'classes/LCN.php';
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);
    $rooms = new \XMPPJid($config['LCN_control'] . '/' . 'loungeSimManager');
    l("[JAXL] Joining room " . $rooms->to_string());
    $client->xeps['0045']->join_room($rooms);
    l("[JAXL] Joined room " . $rooms->to_string());
    \JAXLLoop::$clock->call_fun_periodic(5000000, function ($w) {
        global $client, $config;
        $say = mt_rand(0, mt_getrandmax()) / mt_getrandmax();
        if ($say > 0.5) {
            // go on liz, declare war!
            $im = 'loungesim_' . $config['sim_prefix'] . $config['impersonate'][array_rand($config['impersonate'])];
            $p = array('aud' => $im, 'iat' => time());
            $lcn = new LCN($p);
            $client->xeps['0045']->send_groupchat($config['LCN_control'], $lcn->res);
        }
    });
});
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    $client->send_end_stream();
    l("[JAXL] Auth failure: " . $reason, L_WARN);
});
示例#14
0
文件: subscriber.php 项目: jaxl/JAXL
//
$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');
    // subscribe
    $client->xeps['0060']->subscribe('pubsub.localhost', 'dummy_node');
}
$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');
function on_headline_message_callback($stanza)
{
    global $client;
    if ($event = $stanza->exists('event', XEP0060::NS_PUBSUB . '#event')) {
        JAXLLogger::info("got pubsub event");
    } else {
        JAXLLogger::warning("unknown headline message rcvd");
    }
    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();
    _info("got on_auth_failure cb with reason {$reason}");
});
$client->add_cb('on_headline_message', function ($stanza) {
    global $client;
    if ($event = $stanza->exists('event', NS_PUBSUB . '#event')) {
        _info("got pubsub event");
    } else {
        _warning("unknown headline message rcvd");
    }
    if ($query) {
        $form = array();
        $instructions = $query->exists('instructions');
        if ($instructions) {
            echo $instructions->text . PHP_EOL;
        }
        foreach ($query->childrens as $k => $child) {
            if ($child->name != 'instructions') {
                $form[$child->name] = readline($child->name . ":");
            }
        }
        $client->xeps['0077']->set_form($stanza->attrs['from'], $form);
        return "wait_for_register_response";
    } else {
        $client->end_stream();
        return "logged_out";
    }
}
//
// 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";
});
//
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
示例#17
0
    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');
//
// finally start configured xmpp stream
//
$client->start();
echo "done" . PHP_EOL;
示例#18
0
}
//
// 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";
示例#19
0
文件: xmpp_rest.php 项目: jaxl/JAXL
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
    global $xmpp;
    $request->ok($xmpp->full_jid->to_string());
}
$http->cb = 'generic_callback';
// This will start main JAXLLoop,
// hence we don't need to call $http->start() explicitly
$xmpp->start();
示例#20
0
文件: echo_bot.php 项目: jaxl/JAXL
$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();
    // set status
    $client->set_status("available!", "dnd", 10);
}
$client->add_cb('on_auth_success', 'on_auth_success_callback');
// by default JAXL instance catches incoming roster list results and updates
// roster list is parsed/cached and an event 'on_roster_update' is emitted
function on_roster_update_callback()
{
    //global $client;
    //print_r($client->roster);
}
$client->add_cb('on_roster_update', 'on_roster_update_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');
 */
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;
    // echo back incoming message stanza
    $stanza->to = $stanza->from;
    $stanza->from = $client->full_jid->to_string();
    $client->send($stanza);
});
$client->add_cb('on_disconnect', function () {
示例#22
0
文件: http_bind.php 项目: jaxl/JAXL
 * 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.
 *
 */
require dirname(__FILE__) . '/_bootstrap.php';
if (!isset($_GET['jid']) || !isset($_GET['pass'])) {
    echo "invalid input";
    exit;
}
//
// initialize JAXL object with initial config
//
$client = new JAXL(array('jid' => $_GET['jid'], 'pass' => $_GET['pass'], 'bosh_url' => 'http://localhost:5280/http-bind', 'log_level' => JAXLLogger::DEBUG));
function on_auth_success_callback()
{
    global $client;
    JAXLLogger::info("got on_auth_success cb, jid " . $client->full_jid->to_string());
}
$client->add_cb('on_auth_success', 'on_auth_success_callback');
//
// finally start configured xmpp stream
//
$client->start();
echo "done" . PHP_EOL;
示例#23
0
    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();
    _info("got on_auth_failure cb with reason {$reason}");
});
$client->add_cb('on_groupchat_message', function ($stanza) {
    global $client;
    $from = new XMPPJid($stanza->from);
    $delay = $stanza->exists('delay', NS_DELAYED_DELIVERY);
    if ($from->resource) {
        echo "message stanza rcvd from " . $from->resource . " saying... " . $stanza->body . ($delay ? ", delay timestamp " . $delay->attrs['stamp'] : ", timestamp " . gmdate("Y-m-dTH:i:sZ")) . PHP_EOL;
    } else {
        $subject = $stanza->exists('subject');
示例#24
0
$db =& \MDB2::singleton($config['db']);
if (\PEAR::isError($db)) {
    die($db->getMessage());
}
$db->loadModule('Extended', null, false);
l("[JAXL] Loading JAXL and connecting...");
$client = new \JAXL($config['jaxl']);
$client->require_xep(array('0045', '0203', '0199'));
$rooms = array();
$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);
    foreach ($config['rooms'] as $id => $jid) {
        $rooms[$id] = new \XMPPJid($jid . '/' . $config['botname']);
        l("[JAXL] Joining room " . $rooms[$id]->to_string());
        $client->xeps['0045']->join_room($rooms[$id]);
        l("[JAXL] Joined room " . $rooms[$id]->to_string());
    }
});
$roster = new roster();
$decks = array();
$client->add_cb('on_auth_failure', function ($reason) {
    global $client;
    $client->send_end_stream();
    l("[JAXL] Auth failure: " . $reason, L_WARN);
});
// Where the magic happens. "Magic" "Happens". I dunno why I type this either.
$client->add_cb('on_groupchat_message', function ($stanza) {