$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(); // global $xmpp_client; // $xmpp_client->set_status("available!", "dnd", 10); }); $xmpp_client->add_cb('on_headline_message', function ($stanza) { global $xmpp_client; // var_dump($stanza); processMessage($stanza); }); $xmpp_client->start(array('--with-unix-sock' => true), $pamiClient);
if (($x = $stanza->exists('x', NS_MUC . '#user')) !== false) { if (($status = $x->exists('status', null, array('code' => '110'))) !== false) { $item = $x->exists('item'); _info("xmlns #user exists with x " . $x->ns . " status " . $status->attrs['code'] . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role']); } else { _info("xmlns #user have no x child element"); } } else { _warning("=======> odd case 1"); } } else { if (strtolower($from->bare) == strtolower($room_full_jid->bare)) { if (($x = $stanza->exists('x', NS_MUC . '#user')) !== false) { $item = $x->exists('item'); echo "presence stanza of type " . ($stanza->type ? $stanza->type : "available") . " received from " . $from->resource . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role'] . PHP_EOL; } else { _warning("=======> odd case 2"); } } else { _warning("=======> odd case 3"); } } }); $client->add_cb('on_disconnect', function () { _info("got on_disconnect cb"); }); // // finally start configured xmpp stream // $client->start(); echo "done\n";
// 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();
$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"); }); // // finally start configured xmpp stream // $comp->start(); echo "done\n";
function on_chat_message_callback($stanza) { global $client; // echo back incoming chat message stanza $stanza->to = $stanza->from; $stanza->from = $client->full_jid->to_string(); $client->send($stanza); } $client->add_cb('on_chat_message', 'on_chat_message_callback'); function on_presence_stanza_callback($stanza) { global $client; $type = $stanza->type ? $stanza->type : "available"; $show = $stanza->show ? $stanza->show : "???"; JAXLLogger::info($stanza->from . " is now " . $type . " ({$show})"); if ($type == "available") { // fetch vcard $client->get_vcard($stanza->from); } } $client->add_cb('on_presence_stanza', 'on_presence_stanza_callback'); function on_disconnect_callback() { JAXLLogger::info("got on_disconnect cb"); } $client->add_cb('on_disconnect', 'on_disconnect_callback'); // // finally start configured xmpp stream // $client->start(array('--with-debug-shell' => true, '--with-unix-sock' => true)); echo "done" . PHP_EOL;
}); $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 chat message stanza $stanza->to = $stanza->from; $stanza->from = $client->full_jid->to_string(); $client->send($stanza); }); $client->add_cb('on_presence_stanza', function ($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); } }); $client->add_cb('on_disconnect', function () { _info("got on_disconnect cb"); }); // // finally start configured xmpp stream // $client->start(array()); echo "done\n";
/** * Starts the client */ private function startClient() { $this->client->start(); }