Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Events list

ptejada edited this page Aug 8, 2012 · 21 revisions

There are a handful of built-in events in the framework. Some more useful and advance then others. This built-in commands should not be manually sent as it might brake the framework workflow. Below is a list of the events.

client: connect | ready | restored | error* | dead | quit

channel: joined | join | left | message | data


client

  • connect:

    This command is triggered right before the client sends the command to connect to the APE Server along with the user information/object client.user. This event is probably the must powerful and useful in the whole framework, it makes use of the smart trigger by holding the connect process when returned false.

    Take a look at this example where the connect event is used to get the user's name prior to connecting to the server without breaking your application workflow:

     //Create new client object
     var client = new APS("localhost:6969");
     
     //Adds the `connect` event to the client
     client.on("connect", function(){
     	//Check if the user's name is known
     	if(!!client.user.name){
     		//Simply ask for the user name
     		client.user.name = prompt("Which nick name would you like?", "Pablo");
     	}
     	//the framework continues connecting
     })
     
     //Subscribes to the channel `chat`
     client.sub("chat");

    Below is more advance and useful example. It uses jQuery to make an ajax request to get the user's info without breaking the workflow of your application still:

     //Create new client object
     var client = new APS("localhost:6969");
     
     //Adds the `connect` event to the client
     client.on("connect", function(){
     	//Check if the user's name is known
     	if(!!client.user.name){
     		//Ajax call to get the user info
     		$.get("script_to_get_user_info.php", function(data){
     			client.user = data.user;
     			//Resumes the connecting proccess
     			client.connect();
     		});
     		
     		//Holds the connecting process
     		return false;
     	}
     	//We have a name, continue connecting to the APE server
     })
     
     //Subscribes to the channel `chat`
     client.sub("chat");

    Please note that the client.connect() will re-trigger the connect events so if your ajax callback function does not sets a value to client.user.name you might create a infinity loop in this specific example.


Still developing...


Clone this wiki locally