client Class APE

Summary

File
<./src/Ape_Jsf/Source/Core/APE.js>

APE Class Detail

APE (options)
Create a new APE instance.

The constuctor only create a APE instance, to connect to the APE server you need to use the start(); method

If you want to use APE, do NOT start APE in this way, use APE.load() method instead.

File:
<./src/Ape_Jsf/Source/Core/APE.js>
Parameters:
{object} options Optional
An object with ape default options
{string} options.server Optional
APE server URL
{integer} options.pollTime Optional Default: 25000
Max time for a request in ms
{string} options.identifier Optional Default: 'ape'
Identifier used to differentiate two APE instance when you are using more than one application on your website and using Session.js
{integer} options.transport Optional Default: 1
Transport method used by APE,

1 : Long polling
2 : XHR streaming
3 : forever iframe
4 : JSONP
6 : Websocket

{integer} options.frequency Optional Default: 0
The frequency identifier
Returns:
  APE An Ape instance
Examples
var ape = new APE.Core({
	'server': 'ape.yourdomain.com'
});
var ape = new APE.Core({
	'server': 'ape.yourdomain.com',
	'pollTime': 35000, //if you set pollTime to 35sec you need to set it on the server side to 55sec
	'identifier': 'myApplicationIdentifier',
	'transport': 2,
	'frequency': 3
});
ape.start();
client.addEvent('load', function() {
	console.log(ape.user.pubid); //Show pubid of current user
	console.log(ape.user.properties); //Show properties of current user
}
See:
APE.client
APE.load
APE.start
APE.onError
APE.onRaw

Summary

Own
Attributes Type Name Description
  {APE.Client} client Client object
  {APE.Core} core Core object
  {APE.Request} request Request object
  {APE.Transport} transport Transport variant
  {string} version Version (e.g.

{string} version

Version (e.g. 1.1)

Summary

Own
Methods Attributes Methods Name Methods Description
<static>   APE. addEvent (eventName, fn, internal) Intercept an event.
<static>   APE. check () Send a CHECK cmd to the server.
<static>   APE. clearSession () Clear the sessions, clean timer, remove cookies, remove events, stop all running requests, reset sissd and pubid
<static>   APE. fireEvent (eventName, args, delay) Fire a event manually.
<static>   APE. getPipe (pubid) Get a pipe object
<static>   APE. getSession (key, fn) Retrieves a value from the session on the APE server.
<static>   APE. init (config) Ape initialiser
<static>   APE. join (channel, options) Join one or many channels.
<static>   APE. left (pubid) Leave (unsubscribe) a channel and fire the pipeDelete
<static>   APE. quit () Exit APE

Sends a QUIT CMD and clears the sessions

<static>   APE. removeEvent (eventName, fn) Stop watching a event
<static>   APE. setSession (key, value) Save a sesion variable on the APE server.
<static>   APE. start (args, options) Initiate a connection to a APE server.

<static> {APE} APE. addEvent (eventName, fn, internal)

Intercept an event.
File:
<./src/Ape_Jsf/Clients/MooTools.js>
Parameters:
{string} eventName Event to listen to.
{function} fn The function that will be executed upon this named event
{boolean} internal Optional Flag to hide the function
Returns:
{APE}
Example
//Initialize client
client = new APE.Client();
client.load({
	'domain': 'yourdomain.com',
	'server': 'ape.yourdomain.com',
	'baseUrl': 'yourdomain.com/APEJavaScript'
});
//Load event is fired when the client is loaded
client.addEvent('load', function() {
	console.log('APE is loaded');
	//Ok my client is loaded, now i can send data to my APE server
	//Connect to the APE server
	client.core.start();
});
//Init event is fired when the client is connected to APE server
client.addEvent('init', function() {
	console.log('APE is connected');
});
See:

<static> APE. check ()

Send a CHECK cmd to the server.

Note: this is automatically done and can be configured by the pollTime option parameter.

File:
<./src/Ape_Jsf/Source/Core/Core.js>
Example
var ape = new APE.Core({
'pollTime': 35000, //if you set pollTime to 35sec you need to set it on the server side to 55sec
'identifier': 'myApplicationIdentifier',
});
ape.start();
// obsessive check
setInterval(function(){
	ape.check();
}, 1000);
See:
APE

<static> APE. clearSession ()

Clear the sessions, clean timer, remove cookies, remove events, stop all running requests, reset sissd and pubid
File:
<./src/Ape_Jsf/Source/Core/Core.js>
Example
//ape var is a reference to APE instance
//Error 004 is fired when you sent a bad sessid (this can happen if the client experience some connection issue longer than 45sec)
ape.onError('004', function() {
	ape.clearSession();
	ape.initialize(ape.options); //Reinitialize APE class
});
See:

<static> {APE} APE. fireEvent (eventName, args, delay)

Fire a event manually.

Executes all events of the specified type present on the APE core and Pipes.

File:
<./src/Ape_Jsf/Clients/MooTools.js>
Parameters:
{string} eventName Event to launch (eg 'load').
{Array|object} args The arguments for the appropiate event callbacks
{integer} delay Optional Delay in ms before the event should be fired
Returns:
{APE}
Example
//ape var is a reference to APE instance
//fire the event "myEvent" with arguments "argument1" and "argument2" and delay it of 1sec
ape.fireEvent('myEvent', ['argument1', 'argument2'], 1000);
See:

<static> {object} APE. getPipe (pubid)

Get a pipe object
File:
<./src/Ape_Jsf/Source/Core/Core.js>
Parameters:
{string} pubid The pubid of the pipe
Returns:
{object} A. pipe object or null
Examples
//ape var is a reference to APE instance
//Get a pipe
var myPipe = ape.getPipe('a852c20b3e5c9889c16fe4ac88abe98f');
//Send a message on the pipe
myPipe.send('Hello world');
//ape var is a reference to APE instance
//getPipe on Multi Pipe
//ape var is a reference to APE instance
ape.join('testChannel');
//This sample is just here to show you how to intercept pipe pubid in pipeCreate event
ape.addEvent('multiPipeCreate', function(type, pipe, options) {
	//Get the pipe object
	var myPubid = ape.getPipe(pipe.getPubid());
	//Send a message on the pipe
	 myPipe.send('Hello world');
});
//ape var is a reference to APE instance
//ape var is a reference to APE instance
ape.join('testChannel');
ape.addEvent('userJoin', function(user, pipe) {
	//For performance purpose, user are not pipe in APE JSF. If you want to have a pipe from an user, use getPipe.
	//Transform all user into a pipe object
	var pipe = ape.getPipe(user.pubid);
	//Send 'Hello world' to the user
	pipe.send('Hello world');
});
See:

<static> {void} APE. getSession (key, fn)

Retrieves a value from the session on the APE server.
File:
<./src/Ape_Jsf/Source/Core/Core.js>
Parameters:
{string|Array} key The key(s) to retrieve
{function} fn Callback function to execute when the sessions is received. One arguments is passed to the callback function with the response of the server.
Returns:
{void}
Examples
//ape var is a reference to APE instance
	ape.setSession({'myKey1':'myValue','myKey2':'myValue2'});
	ape.getSession('myKey', function(resp) {
		console.log(resp.datas.sessions.myKey);
});
//ape var is a reference to APE instance
ape.setSession({'myKey':'["A Json array", "Value 2"]'});
ape.getSession('myKey', function(resp) {
	//decode the received data, and use eval to dedode the data
	console.log(eval(decodeURIComponent(resp.datas.sessions.myKey)));
});
See:

<static> APE. init (config)

Ape initialiser
File:
<./src/Ape_Jsf/Source/Core/Core.js>
Parameters:
{object} config Configuration object
See:

<static> {void} APE. join (channel, options)

Join one or many channels.
File:
<./src/Ape_Jsf/Source/Core/Core.js>
Parameters:
{string|Array} channel The channel(s) to join
{Array} options The parameters you want to pass to the channel
Returns:
{void}
Example
//ape var is a reference to APE instance
ape.join('testchannel'); //Join channel "testchannel"
//ape var is a reference to APE instance
ape.join(['channel1', 'channel2']); //Join channels "channel1" and "channel2"
See:

<static> {void} APE. left (pubid)

Leave (unsubscribe) a channel and fire the pipeDelete
File:
<./src/Ape_Jsf/Source/Core/Core.js>
Parameters:
{string} pubid The pubid of the channel
Returns:
{void}
Example
//ape var is a reference to APE instance
//Join testchannel
ape.join('testchannel');
//Intercept pipeCreate event (this event is fired when you join a channel)
ape.addEvent('multiPipeCreate', function(pipe, options) {
if (pipe.properties.name=='teschannel') {
	//If pipe is testchannel, left it :p
	ape.left(pipe.getPubid());
	}
});
See:

<static> {void} APE. quit ()

Exit APE

Sends a QUIT CMD and clears the sessions

File:
<./src/Ape_Jsf/Source/Core/Core.js>
Returns:
{void}
Example
//ape var is a reference to APE instance
ape.quit();
See:

<static> {APE} APE. removeEvent (eventName, fn)

Stop watching a event
File:
<./src/Ape_Jsf/Clients/MooTools.js>
Parameters:
{string} eventName The name of the event (e.g. 'login', 'data');
{function} fn Optional For internal functions?
Returns:
{APE}
Example
//ape var is a reference to APE instance
//Intercept login raw.
ape.onRaw('level10', function(param) {
	ape.removeEvent('level9');
});
See:

<static> {void} APE. setSession (key, value)

Save a sesion variable on the APE server.

Adds a key-value pair to the session on the APE server or replaces a previous value associated with the specified key.

File:
<./src/Ape_Jsf/Source/Core/Core.js>
Parameters:
{string} key The key
{string} value The value that will be associated with that key
Returns:
{void}
Examples
//ape var is a reference to APE instance
ape.setSession({'myKey1':'myValue','myKey2':'myValue2'});
ape.getSession('myKey', function() {
	console.log(resp.datas.sessions.myKey1);
});
//ape var is a reference to APE instance
ape.setSession({'myKey':'["A Json array", "Value 2"]'});
ape.getSession('myKey', function(response) {
//decode the received data, and use eval to dedode the data
console.log(eval(decodeURIComponent(response.datas.sessions.myKey)));
});
See:

<static> {void} APE. start (args, options)

Initiate a connection to a APE server.

If there is an instance of APE present (created via APE.Core()), it can be connected to the server with the start method. The prefered way is to make the connection with APE.load() method.

File:
<./src/Ape_Jsf/Source/Core/Core.js>
Parameters:
{object} args Connection arguments
{object} options Connection options (e.g. 'channel')
Returns:
{void}
Examples
//ape var is a reference to APE instance
 ape.start(); //Send CONNECT command to APE.
//ape var is a reference to APE instance
//If you use APE with libape-chat you need to send your nickname in the CONNECT request
ape.start('myNickname'); //Send CONNECT command with a nickname to APE and tries to join the optional channel
See:
APE.load
APE.restoreStart
APE.restoreEnd
APE.apeDisconnect
APE.apeReconnect
APE.ready

Summary

Own
Attributes Name Description
<static>   APE. apeDisconnect () Events sent when client apeDisconnect.
<static>   APE. apeReconnect () Events sent when client apeDisconnect.
<static>   APE. clearSession () Events sent when the session is cleared.
<static>   APE. load (options) Load the APE client.
<static>   APE. multiPipeCreate (pipe, options) Event fired when a new Multi Pipe is created.
<static>   APE. multiPipeDelete (pipe) Event fired when a Multi Pipe is deleted.
<static>   APE. onCmd (commandName, fn, internal) Intercept an server command (CMD).
<static>   APE. onError (errorCode, fn, internal) Intercept an error event.
<static>   APE. onRaw (rawName, fn, internal) Intercept an server raw (RAW).
<static>   APE. PipeDelete (pipeType) Event sent when a pipe is deleted
<static>   APE. progress () Progress on a XHRStreaming request
<static>   APE. proxyClose () Event sent when the proxy close the connection.
<static>   APE. proxyConnect () Event sent when the client is connected to the proxy.
<static>   APE. proxyPipeCreate (pipe, options) Event fired when a new Proxy Pipe is created.
<static>   APE. proxyRead () Event sent when the client received data from the proxy.
<static>   APE. ready () Event sent when the client is connected to the APE server.
<static>   APE. restoreEnd () Event sent when the session restore begin.
<static>   APE. restoreStart () Event sent when the session restore begin.
<static>   APE. uniPipeCreate (pipe, options) Event fired when a new Uni Pipe is created.
<static>   APE. userJoin (user, pipe) Event fired when a user joins a channel

This event is fired both on core and pipe the user joined

<static>   APE. userLeft (user, pipe) Event fired when a user left a channel

This event is fired both on core and pipe the user joined

<static> APE. apeDisconnect ()

Events sent when client apeDisconnect.

This events is sent when the client is apeDisconnect from the server in the case of connection timeout or request failure.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
See:
APE.load
APE.restoreStart
APE.restoreEnd
APE.apeDisconnect
APE.apeReconnect
APE.ready

<static> APE. apeReconnect ()

Events sent when client apeDisconnect.

This events is sent when the client is apeDisconnect from the server in the case of connection timeout or request fail

File:
<./src/Ape_Jsf/Source/Core/Events.js>
See:
APE.load
APE.restoreStart
APE.restoreEnd
APE.apeDisconnect
APE.apeReconnect
APE.ready

<static> APE. clearSession ()

Events sent when the session is cleared.

This events is sent when the clearSession(); method is called.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Requires:
Source/Core/Session.js

<static> {void} APE. load (options)

Load the APE client.
File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{object} options An object with ape default options
{string} options.server Optional APE server URL
{string} options.domain Optional Your domain, eg : yourdomain.com
{string} options.identifier Optional defaults to : ape identifier is used to differentiate two APE instance when you are using more than one application on your website and using Session.js
{Array} options.scripts Optional Javascript files to load
{string} options.channel Optional Initial channel to connect to upon loading
{object} options.connectOptions Optional An object with connect arguments to send to APE server on connect. If given, as soon as APE Core is loaded, it connect to APE server with arguments given in connectOptions.
Returns:
{void}
Examples
//Initialize client
client = new APE.Client();
client.load();
client.addEvent('load', function() {
	console.log('Your APE client is loaded');
	client.core.start({'name': 'apeUser'});
});
client.addEvent('start', function() {
	console.log('You are connected to APE server. Now you can takeover the world');
};
//Initialize client
client = new APE.Client();
//Load APE Core and connect to server
client.load({
	'domain': 'yourdomain.com',
	'server': 'ape.yourdomain.com',
	'scripts': ['yourdomain.com/APE_JSF/Build/uncompressed/apeCore.js'],
	'connectOptions': {'name': 'anotherApeUser'}
});
client.addEvent('start', function() {
	console.log('You are connected to APE server. Now you can takeover the world');
};
See:
APE.Core
APE.Core.start

<static> APE. multiPipeCreate (pipe, options)

Event fired when a new Multi Pipe is created.

A new Multi Pipe is created when you successfully joined a channel.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{APE.pipe} pipe The pipe object.
{object} options The options that were passed to the constructor of the pipe.
Example
//ape var is a reference to APE instance
ape.join('testChannel');
//Intercept multiPipeCreate event
ape.addEvent('multiPipeCreate', function(pipe, options) {
	console.log('A new Multi pipe is created. Pipe object : ', pipe);
});
See:
APE.uniPipeCreate
APE.proxyPipeCreate
APE.pipeDelete
APE.PipeMulti.getUser
APE.PipeMulti.left
APE.PipeMulti.users

<static> APE. multiPipeDelete (pipe)

Event fired when a Multi Pipe is deleted. A pipe is deleted when you leave it.
File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{APE.Pipe} pipe The pipe object
Example
//ape var is a reference to APE instance
//Join testchannel
ape.join('testchannel');
//Intercept pipeCreate event (this event is fired when you join a channel)
ape.addEvent('multiPipeCreate', function(pipe, options) {
	if (pipe.properties.name=='teschannel') {
		//If pipe is testchannel, left it :p
		pipe.left(pipe.getPubid());//This will fire the event multiPipeDelete
	}
});
ape.addEvent('multiPipeDelete', function(pipe) {
	console.log('pipe ' + pipe.properties.name + ' have been deleted')
});
See:
APE.left
APE.PipeDelete

<static> {APE} APE. onCmd (commandName, fn, internal)

Intercept an server command (CMD).

Execute a function when a command is sent and pass to the function the arguments sent to APE server.

If the sent raw is related to a pipe (e.g : you sent data to a channel) the first arguments will be a pipe object.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{string} commandName The name of the command (e.g. 'connect', 'send');
{function} fn The function to execute upon sending such a command to the server
{object} fn.args Optional An object containing all data that was send to the server
{object} fn.pipe Optional If the request is made on a pipe (e.g : you sent data to a channel) the second argument will be a pipe object.
{boolean} internal Optional Flag to hide the function
Returns:
{APE}
Examples
///client var is a reference to APE.Client instance
//start(); method is used to connect to APE.
client.core.start();
//Intercept connect command (connect command is used to initiate connection to APE server)
client.onCmd('connect', function() {
	console.log('Connect command sent');
});
//client var is a reference to APE.Client instance
//Intercept send command (send command is used to send data to a pipe)
client.onCmd('send', function(pipe, data) {
	console.log('You sent ' + data.msg + ' to pipe with pubid' + pipe.getPubid());
});
//Intercept pipeCreate event (when a new pipe is created)
client.addEvent('pipeCreate', function(type, pipe, options) {
	//send a message on the pipe ("complex" way)
	pipe.request.send('SEND', 'Hello');
	//Sending a message could also be done more easily with this code
	pipe.send('Hello again!');
});
See:
APE.Pipe.onCmd
APE.onRaw
APE.Pipe.onRaw
APE.onError

<static> {APE} APE. onError (errorCode, fn, internal)

Intercept an error event.
File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{integer} errorCode The errorCode that was received (e.g. 004);
{function} fn The function to execute upon receiving such an errorcode
{boolean} internal Optional Flag to hide the function
Returns:
{APE}
Example
//Instantiate APE Client.
var client = new APE.Client();
//Error 004 is when the user send a bad sessid
client.onError('004', function() {
	alert('Bad sessid');
});

<static> {APE} APE. onRaw (rawName, fn, internal)

Intercept an server raw (RAW).

Execute a function when a raw is received and pass to the function the data received from the server.

If the received raw is related to a pipe (e.g : you receive data from a channel) the second arguments will be a pipe object.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{string} rawName The name of the raw (e.g. 'login', 'data');
{function} fn The function to execute upon sending such a command to the server
{object} fn.args Optional An object containing all data that was send to the server
{object} fn.pipe Optional If the request is made on a pipe (e.g : you sent data to a channel) the second argument will be a pipe object.
{boolean} internal Optional Flag to hide the function
Returns:
{APE}
Example
//ape var is a reference to APE instance
//Intercept data raw (when you receive data from a channel)
ape.onRaw('data', function(param, pipe) {
	alert('You received : ' + param.data.msg + ' on pipe ' + pipe.properties.name);
	//Send some data to the channel
	pipe.send('Hey i just received ' + param.data.msg + '!');
});
See:
APE.Pipe.onRaw
APE.onCmd
APE.Pipe.onCmd
APE.onError

<static> APE. PipeDelete (pipeType)

Event sent when a pipe is deleted
File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{integer} pipeType The type of the pipe (can be uni / multi / proxy)
Example
//ape var is a reference to APE instance
//Join testchannel
ape.join('testchannel');
//Intercept pipeCreate event (this event is fired when you join a channel)
ape.addEvent('pipeCreate', function(type, pipe, options) {
	if (pipe.properties.name=='teschannel') {
		//If pipe is testchannel, left it :p
		pipe.left(pipe.getPubid());
	}
});
//Intercept the pipeDelete event
ape.addEvent('pipeDelete', function(type, pipe) {
	console.log('you just left the pipe ', pipe);
});
See:
APE.left
APE.multiPipeDelete

<static> APE. progress ()

Progress on a XHRStreaming request
File:
<./src/Ape_Jsf/Source/Transport/Transport.XHRStreaming.js>

<static> APE. proxyClose ()

Event sent when the proxy close the connection.

This is a global event.

File:
<./src/Ape_Jsf/Source/Core/Events.js>

<static> APE. proxyConnect ()

Event sent when the client is connected to the proxy.

This is a global event.

File:
<./src/Ape_Jsf/Source/Core/Events.js>

<static> APE. proxyPipeCreate (pipe, options)

Event fired when a new Proxy Pipe is created.

A new Proxy Pïpe is created in two cases :

  • If you use TCP socket interface, the Proxy Pipe is created when the socket is initialized.
  • When you explicitly create a new Proxy Pipe with new APE.ProxyPipe();

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{APE.pipe} pipe The pipe object.
{object} options The options that were passed to the constructor of the pipe.
See:
APE.uniPipeCreate
APE.proxyPipeCreate
APE.proxyClose
APE.proxyConnect
APE.pipeDelete

<static> APE. proxyRead ()

Event sent when the client received data from the proxy.

This is a global event.

File:
<./src/Ape_Jsf/Source/Core/Events.js>

<static> APE. ready ()

Event sent when the client is connected to the APE server.

This event is sent when the client is connected to the APE server, just after the login (start(); method);

File:
<./src/Ape_Jsf/Source/Core/Events.js>
See:
APE.load
APE.restoreStart
APE.restoreEnd
APE.apeDisconnect
APE.apeReconnect
APE.ready

<static> APE. restoreEnd ()

Event sent when the session restore begin.

This event sent when the session restore has finished.

The session restore is automatically handled by the JSF if you include Session.js in your APE JSF.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Requires:
Source/Core/Session.js

<static> APE. restoreStart ()

Event sent when the session restore begin.

This event sent when the session restore begin.

The session restore is automatically handled by the JSF if you include Session.js in your APE JSF.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Requires:
Source/Core/Session.js

<static> APE. uniPipeCreate (pipe, options)

Event fired when a new Uni Pipe is created.

This event is fired when a new Uni Pipe is created. A new Uni Pipe is created when you call getPipe with the pubid of an user.

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{APE.pipe} pipe The pipe object.
{object} options The options that were passed to the constructor of the pipe.
Example
//ape var is a reference to APE instance
ape.join('testChannel');
ape.addEvent('userJoin', function(user, pipe) {
	//For performance purpose, user are not pipe in APE JSF. If you want to have a pipe from an user, use getPipe.
	//Transform all user into a pipe object
	var pipe = ape.getPipe(user.pubid);
});
ape.addEvent('uniPipeCreate', function(pipe, options) {
//Send 'Hello world' to the user
	pipe.send('Hello world');
});
See:
APE.multiPipeCreate
APE.proxyPipeCreate
APE.pipeDelete

<static> APE. userJoin (user, pipe)

Event fired when a user joins a channel

This event is fired both on core and pipe the user joined

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{object} user The user that joined
{APE.Pipe} pipe The pipe that is involved
Examples
//ape var is a reference to APE instance
ape.addEvent('userJoin', function (user, pipe) {
	//An user join the channel
	console.log('the user ' + user.properties.name + ' join the channel ' + pipe.properties.name);
});
//ape var is a reference to APE instance
//Join two channel
ape.join(['channel1', 'channel2']);
ape.addEvent('pipeCreate', function(type, pipe, options) {
//Attach userJoin event only to pipe "channel1"
	if (type == 'multi' && pipe.properties.name =='channel1') {
	pipe.addEvent('userJoin', function(user, pipe) {
		console.log('New user on channel1');
		});
	}
});
See:
APE.userLeft
APE.MultiPipe.left
APE.Pipe.join

<static> APE. userLeft (user, pipe)

Event fired when a user left a channel

This event is fired both on core and pipe the user joined

File:
<./src/Ape_Jsf/Source/Core/Events.js>
Parameters:
{object} user The user that joined
{APE.Pipe} pipe The pipe that is involved
Examples
//ape var is a reference to APE instance
ape.addEvent('userJoin', function (user, pipe) {
	//An user join the channel
	console.log('the user ' + user.properties.name + ' join the channel ' + pipe.properties.name);
});
//ape var is a reference to APE instance
//Join two channel
ape.join(['channel1', 'channel2']);
ape.addEvent('pipeCreate', function(type, pipe, options) {
//Attach userJoin event only to pipe "channel1"
	if (type == 'multi' && pipe.properties.name =='channel1') {
	pipe.addEvent('userJoin', function(user, pipe) {
		console.log('New user on channel1');
		});
	}
});
See:
APE.userJoin
APE.join