#Pusher Titanium Android module
Pusher client library for Titanium Android
##Module Overview
Here is the module in a nutshell.
var pusher = require('uk.aplifi.pusher.android');
pusher.setup(key, authUrl);
pusher.addEventListener({
connected: function(e) {
//Successfully connected
}
});
pusher.connect();
var channel = pusher.subscribeChannel('channelName');
channel.addEventListener('channelEvent', function(event) {
//Received event
Ti.API.debug(JSON.stringify(event));
//Event data
Ti.API.debug(JSON.stringify(event.data));
});
pusher.disconnect();
More information in reference format can be found below.
##Configuration
The standard constructor take an application key which you can get from the app's API Access section in the Pusher dashboard at https://app.pusher.com.
You need to provide an authorization endpoint for using private or presence channels.
var pusher = require('uk.aplifi.pusher.android');
pusher.setup(key, authUrl);
##Connecting
In order to send and receive messages you need to connect to Pusher.
The Connected event listener is called once the connection has been successful, meaning it is now possible to connect to Channels.
pusher.addEventListener({
connected: function(e) {
//Successfully connected
}
});
pusher.connect();
##Disconnecting
pusher.disconnect();
##Subscribing to Channels
Connect to a Channel, then specify an event listener to subscribe to as follows.
var channel = pusher.subscribeChannel('channelName');
channel.addEventListener('channelEvent', function(event) {
//Received event
Ti.API.debug(JSON.stringify(event));
//Event data
Ti.API.debug(JSON.stringify(event.data));
});
##Publishing Channel events
Once you are subscribed to a Channel, you can publish events as follows.
channel.sendEvent('channelEvent', '{"myName": "Bob"}');
##Debug logging
Logging is there for debug purposes. It is automatically disabled for security reasons.
pusher.enableLogging(true);
#Licence