1 function sysMessage(ape, debug){
2 // we call this function once APE has finished loading
3 this.initialize = function(){
4 // once a new user joins (pipe created), call setup()
5 ape.addEvent('pipeCreate', this.setup);
7 // when a user joins, update the user list
8 ape.addEvent('userJoin', this.createUser);
10 // when a user leaves, destroy them with mighty thunder!
11 ape.addEvent('userLeft', this.deleteUser);
13 // when we want to send data
14 ape.onCmd('send', this.cmdSend);
16 // and when we recieve data
17 ape.onRaw('data', this.rawData);
19 // start the session with a random name!
20 // note: you'll need the chat plugin loaded
21 ape.start(String((new Date()).getTime()).replace(/D/gi,''));
24 this.setup = function(type, pipe, options){
25 // add an event listener on our selectbox
26 $("#button").click(function(){
27 // get the select box value
30 // send the message to the APE server
31 pipe.send($("#chat").val());
36 this.cmdSend = function(pipe, sessid, pubid, message){
38 $("<span> " + ape.user.properties.name + " sent new message: " + message + "</span><br />").prependTo("#debug");
41 this.rawData = function(raw, pipe){
42 // data has been received by the APE server so do the following...
44 $("<span> Received message from " + raw.datas.sender.properties.name + " saying: " + raw.datas.msg + "</span><br />").prependTo("#debug");
46 // set the selectboxes value to match other clients
47 $('<span>' + raw.datas.msg + '</span>').prependTo("#wrapper");
50 this.createUser = function(user, pipe){
51 // a user has joined so prepend them to the debug window
52 user.element = $("<span>" + user.properties.name + " has joined</span><br />").prependTo("#debug");
55 this.deleteUser = function(user, pipe){
56 // a user has left so update the debug window
57 $(user.element).text(user.properties.name + " has left").css("color", "#666666").prependTo("#debug");