public function xmpp()
{
// The XMPP connection requires a sender ID (project number) and an API key
$senderId = \Config::get('gcm.senderId');
$apiKey = \Config::get('gcm.apiKeyDebug');
// initialize xmpp client
$xmpp = new \JAXL(array(
'jid' => $senderId . '@gcm.googleapis.com',
'pass' => $apiKey,
'auth_type' => 'PLAIN',
'host' => 'gcm.googleapis.com',
'port' => '5235',
'force_tls' => true,
'log_level' => JAXL_INFO
));
// register callbacks on required xmpp events
$xmpp->add_cb('on_auth_success', function() {
global $xmpp;
_info("got on_auth_success cb, jid ".$xmpp->full_jid->to_string());
});
require_once JAXL_CWD.'/http/http_server.php';
$http = new \HTTPServer();
// add generic callback
$http->cb = function($request) {
// For demo purposes we simply return xmpp client full jid
global $xmpp;
$request->ok($xmpp->full_jid->to_string());
};
// This will start main JAXLLoop, hence we don't need to call $http->start() explicitly
$xmpp->start();
}jaxl:222 - 2013-12-30 21:57:42 - strict mode enabled, adding exception handlers. Set 'strict'=>TRUE inside JAXL config to disable this
jaxl:167 - 2013-12-30 21:57:42 - created pid file /Library/WebServer/Documents/firestone/fuel/app/vendor/abhinavsingh/jaxl/.jaxl/run/jaxl_30090.pid
jaxl_socket_server:63 - 2013-12-30 21:57:42 - socket ready to accept on path tcp://127.0.0.1:9699
jaxl_socket_client:95 - 2013-12-30 21:57:42 - trying tcp://gcm.googleapis.com:5235
jaxl_socket_client:175 - 2013-12-30 21:57:42 - socket eof, disconnectingIt looks like I'm able to connect to the googleapis.com server, but then it immediately disconnects without authenticating. At that point, the script will just sit there until I hit control-C. When I press control-C, this is the output:
^Cjaxl:779 - 2013-12-30 22:06:11 - event 'end_stream' catched in handle_other with stanza name
xmpp_stream:112 - 2013-12-30 22:06:11 - got invalid return value from state handler 'wait_for_stream_start', sending end stream...
xmpp_stream:115 - 2013-12-30 22:06:11 - state handler 'logged_out' returned N;, kindly report this to developers
jaxl_exception:48 - 2013-12-30 22:06:11 - got jaxl exception construct with fclose() expects parameter 1 to be resource, null given, 2, /Library/WebServer/Documents/firestone/fuel/app/vendor/abhinavsingh/jaxl/core/jaxl_socket_client.php, 126
jaxl:214 - 2013-12-30 22:06:11 - cleaning up pid and unix sock files
jaxl_socket_server:75 - 2013-12-30 22:06:11 - shutting down socket server
jaxl_clock:55 - 2013-12-30 22:06:11 - shutting down clock server...So, it appears that I can connect, but I'm not authenticating for some reason. Why might that be?
Also, once I've established the server connection, how do I send new messages? Is there a run loop that I can access? I need to check a database for messages every five minutes, sending new messages as they arrive. In other daemon-type scripts in the past I've typically used something like:
while ($server->run())
{
// do whatever the server is supposed to do
$messages = Messages::new();
foreach ($messages as $message)
{
$server->send($message);
}
sleep(5 * 60) // wait 5 minutes before you do it again
}How does the loop work in JAXL? How do I get inside of it? How do I specify how long between iterations?
One last thing: what's with port 9699? Does that need to be opened?
Thanks,
Ben
jaxl:238 - 2014-04-08 10:53:24 - strict mode enabled, adding exception handlers. Set 'strict'=>TRUE inside JAXL config to disable thisjaxl:188 - 2014-04-08 10:53:24 - created pid file lib/JAXL-3.0.0/priv_dir/run/jaxl_11263.pidjaxl_socket_client:95 - 2014-04-08 10:53:24 - trying ssl://gcm.googleapis.com:5235jaxl:230 - 2014-04-08 10:53:24 - cleaning up pid and unix sock filesjaxl_clock:55 - 2014-04-08 10:53:24 - shutting down clock server...public function get_socket_path() { return ($this->cfg['port'] == 5223 ? "ssl" : "tcp")."://".$this->cfg['host'].":".$this->cfg['port'];}