-
Notifications
You must be signed in to change notification settings - Fork 6
Events list
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
-
connect:
This event 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 theconnect
events so if your ajax callback function does not sets a value toclient.user.name
you might create a infinity loop in this specific example. -
ready: When this event is triggered the client object has been completely initiated and connected to the APE Server. No parameter are passed to this event.
-
restored: this event is triggered when the client has been restored from a session. When the client is restored from a session the connect event is never triggered. No parameters are passed to this event.
-
error: this event is triggered when an error is explicitly sent from the server. The error code and name are passed as parameter to this event. You can also add an error event for an specific error code, for example to add event for the error code 007 you would add the event error007. For a full list of error codes check Error codes.
Still developing...