Question

I want execute some code after a message has already sent in jaxl. which callback is appropriate for this situation?

    public function test() {

        require_once 'JAXL/jaxl.php';
        global $client;

        $client = new JAXL(array(
            'jid' => 'user@localhost',
            'pass' => 'password',
            'log_level' => JAXL_INFO
        ));

        $client->add_cb('on_stream_features', function($stanza)  {
            global $client,$thisObj;
            $client->send_chat_msg('otherUser@localhost','Message');  
        });

       $client->add_cb('on_message_send',function(){  //some thing like this
         //some code
       });
}
Was it helpful?

Solution

Jaxl library currently doesn't support such callbacks. This is because when you call $client->send_chat_msg(), XMPPStream queues XMPPMsg object in the output buffer of underlying JAXLSocketClient. Output buffers are flushed as and when socket is ready for write.

Before queuing all XMPPStanza's are serialised (to_string()) by XMPPStream, thus underlying JAXLSocketClient output buffers have no knowledge about which stanza is being flushed over the write ready socket. As a result no such callbacks are currently possible.

There are non-authoritative ways of performing check about delivery status of your message e.g. is the output buffer empty? But this is tricky and not a perfect solution.

Perfect way to implement such callbacks will be to maintain output buffers within the context of XMPPStream, which should then be notified about underlying socket write ready state, finally before flushing stanza's over the socket, XMPPStream can execute these callbacks. Unfortunately, this is not how the library is designed. Though, possibilities are that such callbacks might get supported in future version of the library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top