JAXL::start PHP Method

start() public method

public start ( array $opts = [] )
$opts array
    public function start(array $opts = array())
    {
        // is bosh bot?
        if (isset($this->cfg['bosh_url'])) {
            $this->trans->session_start();
            for (;;) {
                // while any of the curl request is pending
                // keep receiving response
                while (count($this->trans->chs) != 0) {
                    $this->trans->recv();
                }
                // if no request in queue, ping bosh end point
                // and repeat recv
                $this->trans->ping();
            }
            $this->trans->session_end();
            return;
        }
        // is xmpp client or component?
        // if on_connect event have no callbacks
        // set default on_connect callback to $this->start_stream()
        // i.e. xmpp client mode
        if (!$this->ev->exists('on_connect')) {
            $this->add_cb('on_connect', array($this, 'start_stream'));
        }
        // connect to the destination host/port
        if ($this->connect($this->get_socket_path())) {
            // reset in case we connected back after retries
            $this->retry_attempt = 0;
            // emit
            $this->ev->emit('on_connect');
            // parse opts
            if (isset($opts['--with-debug-shell']) && $opts['--with-debug-shell']) {
                $this->enable_debug_shell();
            }
            if (isset($opts['--with-unix-sock']) && $opts['--with-unix-sock']) {
                $this->enable_unix_sock();
            }
            // run main loop
            JAXLLoop::run();
            // emit
            $this->ev->emit('on_disconnect');
        } else {
            // If connection to the destination fails.
            if ($this->trans->errno == 61 || $this->trans->errno == 110 || $this->trans->errno == 111) {
                JAXLLogger::debug("unable to connect with errno " . $this->trans->errno . " (" . $this->trans->errstr . ")");
                $this->retry();
            } else {
                $this->ev->emit('on_connect_error', array($this->trans->errno, $this->trans->errstr));
            }
        }
    }

Usage Example

コード例 #1
0
$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);
All Usage Examples Of JAXL::start