jaxl / JAXL

Asynchronous, non-blocking I/O, event based PHP library for writing custom TCP/IP client and server implementations. From it's previous versions, library inherits a full blown stable support for XMPP protocol stack. In v3.0, support for HTTP protocol stack was also added.
http://jaxl.readthedocs.org/
Other
379 stars 121 forks source link

JAXL XMPP script works, but never stops loading #58

Open lcyabcd opened 9 years ago

lcyabcd commented 9 years ago

I am implementing the Facebook Chat into my site so I used JAXL in order to implement the XMPP. It seems that the script posts the message that I wanted, but whenever I run it, the page just keeps loading and loading and never stops. In order to get back onto that site, I have to clear the cookies for it in my browser. Not sure what the problem could be, I am not seeing any errors in my log. Take a look at the code: Thanks!

$client = new JAXL(array( 'jid' => $user['facebookID']."@chat.facebook.com", 'fb_app_key' => "XXXX", 'fb_access_token' => $user['facebook_access_token'], 'force_tls' => true, 'auth_type' => 'X-FACEBOOK-PLATFORM', 'log_level' => JAXL_INFO, 'priv_dir' => "includes/lib/jaxl/tmp" ));

$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);

    $msg = new XMPPMsg(array('to'=>'-XXXX@chat.facebook.com'), 'test message');
    $client->send($msg);
});

$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();
calebtr commented 9 years ago

Is this code in your page? The process running JAXL will keep running until you tell JAXL to stop. That's why the page appears to be loading and loading and loading.

If you want to have an XMPP client on a web page, you need to use a BOSH client - something like what is described at http://abhinavsingh.com/jaxl-bosh-demo-im-chat-client-for-all-wordpress-blogs/ - though I don't see all of the code I am expecting to see.

abhinavsingh commented 9 years ago

@lcyabcd You probably want to close the client connection once it has sent out the message. Example, adding $client->send_end_stream() after $client->send($stanza) will terminate the client after it sends out the 1st message.

lcyabcd commented 9 years ago

I want to have a web client.