Skip to content

Instantly share code, notes, and snippets.

@jegade
Created July 29, 2010 21:13
Show Gist options
  • Save jegade/499254 to your computer and use it in GitHub Desktop.
Save jegade/499254 to your computer and use it in GitHub Desktop.
/***
* APE JSF Setup
*/
APE.Config.baseUrl = 'http://ape.internal:8000/static/ape-jsf'; //APE JSF
APE.Config.domain = 'ape.internal';
APE.Config.server = 'ape.internal:6969'; //APE server URL
window.addEvent('domready', function() {
im = new APE.IM(
{
'token' : 'sha1_hex_hash',
'time' : 'timestamp',
'user_id' : 'uniqe backend user identifier',
}
);
im.load({
'identifier': 'im',
'channel' : 'main',
});
});
(function() {
for (var i = 0; i < arguments.length; i++)
APE.Config.scripts.push(APE.Config.baseUrl + '/Source/' + arguments[i] + '.js');
})('mootools-core', 'Core/APE', 'Core/Events', 'Core/Core', 'Core/Session', 'Pipe/Pipe', 'Pipe/PipeProxy', 'Pipe/PipeMulti', 'Pipe/PipeSingle', 'Request/Request', 'Request/Request.Stack', 'Request/Request.CycledStack', 'Transport/Transport.longPolling', 'Transport/Transport.SSE', 'Transport/Transport.XHRStreaming', 'Transport/Transport.JSONP', 'Transport/Transport.WebSocket', 'Core/Utility', 'Core/JSON');
APE.IM = new Class({
Implements: [APE.Client, Options],
options: {
container: null,
logs_limit: 10,
debug: false
},
initialize: function(options) {
this.setOptions(options);
this.options.container = $(this.options.container) || document.body;
this.els = {};
this.currentPipe = null;
this.logging = true;
this.user = null;
this.state = null;
this.connectet = false;
this.addEvent('load', this.loaded);
this.addEvent('ready', this.ready);
this.onRaw('data', this.rawData);
this.onRaw('ident', this.ident);
this.onRaw('backident', this.backident );
this.onRaw('err', this.errorHandling);
},
errorHandling: function(raw, pipe) {
if (raw.data.value == 'BAD_SESSID') {
// restart Session
this.reset();
}
},
rawData: function(raw, pipe) {
var pipe_name = pipe.name;
var message = raw.data.msg;
var firstname = raw.data.from.properties.firstname;
if (this.options.debug) {
console.log("PIPE : " + pipe_name);
console.log("MSG : " + message);
console.log("FROm : " + firstname);
}
},
// ident - Auth-Response for the APE-Session
ident: function(args, pipe) {
if ( args.data.user && args.data.user.properties && args.data.user.properties.firstname ) {
this.user = args.data.user;
this.connectet = true;
this.setState(args.data.user.properties.state);
}
},
// backident - Auth-Response after Backend-Validation
backident: function(args,pipe) {
this.user = args.data.from;
this.connectet = true;
this.setState(args.data.from.properties.state);
},
loaded: function() {
this.core.start({
'token': this.options.token,
'time': this.options.time,
'user_id': this.options.user_id,
'rand': Math.random()
});
},
ready: function() {
if (this.options.debug) {
console.log("Ready");
}
this.connectet = true;
},
reset: function() {
this.core.clearSession();
this.core.initialize(this.core.options);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment