function sysMessage(ape, debug){
// we call this function once APE has finished loading
this.initialize = function(){
// once a new user joins (pipe created), call setup()
ape.addEvent('pipeCreate', this.setup);
// when a user joins, update the user list
ape.addEvent('userJoin', this.createUser);
// when a user leaves, destroy them with mighty thunder!
ape.addEvent('userLeft', this.deleteUser);
// when we want to send data
ape.onCmd('send', this.cmdSend);
// and when we recieve data
ape.onRaw('data', this.rawData);
// start the session with a random name!
// note: you'll need the chat plugin loaded
ape.start(String((new Date()).getTime()).replace(/D/gi,''));
}
this.setup = function(type, pipe, options){
// add an event listener on our selectbox
$("#button").click(function(){
// get the select box value
if ($("#chat").val())
{
// send the message to the APE server
pipe.send($("#chat").val());
}
});
}
this.cmdSend = function(pipe, sessid, pubid, message){
if(debug)
$(" " + ape.user.properties.name + " sent new message: " + message + "
").prependTo("#debug");
}
this.rawData = function(raw, pipe){
// data has been received by the APE server so do the following...
if(debug)
$(" Received message from " + raw.datas.sender.properties.name + " saying: " + raw.datas.msg + "
").prependTo("#debug");
// set the selectboxes value to match other clients
$('' + raw.datas.msg + '').prependTo("#wrapper");
}
this.createUser = function(user, pipe){
// a user has joined so prepend them to the debug window
user.element = $("" + user.properties.name + " has joined
").prependTo("#debug");
}
this.deleteUser = function(user, pipe){
// a user has left so update the debug window
$(user.element).text(user.properties.name + " has left").css("color", "#666666").prependTo("#debug");
}
}