/**
  * Attaches the stream reader that will write to the MUC
  */
 private function attachStreamReader()
 {
     /**
      * @var \JAXLClock $clock
      */
     $clock = \JAXLLoop::$clock;
     $clock->call_fun_periodic(self::READ_RATE, function () {
         $text = $this->ircStream->read();
         if (!empty($text)) {
             $messageParts = explode(' ', $text);
             $nickName = str_replace(['<', '>'], '', $messageParts[0]);
             if ($nickName != $this->getContainer()->get('config')['xmpp']['nickname'] && $nickName != $this->getContainer()->get('config')['irc']['nickname']) {
                 $message = new \XMPPStanza('message');
                 $message->type = 'groupchat';
                 $message->to = $this->getContainer()->get('config')['xmpp']['conference'];
                 $message->body = $text;
                 $this->getContainer()->get('logger')->debug('Found a message in the IRC socket. Writing it to the XMPP Channel');
                 $this->client->send($message);
             }
         }
     });
 }
//
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 () {
    _info("got on_disconnect cb");
});
//
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
$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";