Created
May 31, 2009 23:31
-
-
Save CrypticSwarm/121079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ar APE_Handler_Base = new Class({ | |
Implements: [APE.Client, Options], | |
options: { | |
userEvents: [], | |
userProps: {} | |
}, | |
initialize: function(core, userClass, options){ | |
this.userClass = userClass; | |
this.setOptions(options); | |
this.userEvents = this.options.userEvents; | |
this.addEvent('userJoin', this.createUser); | |
this.addEvent('userLeft', this.deleteUser); | |
this.userEvents.each(function(evName){ | |
this.userRawEventAdd(evName); | |
}, this); | |
this.addEvent('pipeCreate', function(type, pipe, options){ | |
if(type=='multi') this.pipe = pipe; | |
console.log("pipe created"); | |
}); | |
}, | |
userRawEventAdd: function(evName){ | |
var rawName = 'raw_' + evName.replace(/^set/, '').toLowerCase(); | |
this.addEvent(rawName, function(){ this.userRawEvent.apply(this, [name].extend(arguments)); }); | |
}, | |
userRawEvent: function(ev, raw){ | |
var user = this.pipe.getUser(raw.datas.sender.pubid); | |
var func = user.object[ev]; | |
var props = (raw.datas && raw.datas.sender.properties) || {}; | |
func ? func.call(user.object, props) : console.log(ev + " did not exist on user"); | |
}, | |
createUser: function(user, pipe){ | |
user.object = new this.userClass(user, pipe, $merge(this.options.userProps, user.properties)); | |
}, | |
deleteUser: function(user){ | |
user.object.deleteUser && user.object.deleteUser(); | |
}, | |
sendData: function(){ | |
var props = Array.slice(arguments, 1); | |
this.core.request(arguments[0].toUpperCase(),[this.pipe.getPubid()].extend(props) ); | |
var user = this.pipe.getUser(this.core.user.pubid).object; | |
user[arguments[0]].apply(user, props); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment