Ok, after a couple of days full of pain, i think i'm able to post some
useful code. In this snippets i build an hash for each user connected
to ape; this hash substantially implements a "dummy" session system.
This hash is formed by an array of arrays, each formed by the user's
pubid and the room he's logged in. If a user refresh a page, the pubid
is updated in the proper array entry; if a user connects to another
room (i remind you that my system is formed by N rooms that you can
reach from your URL
http://localhost/chat/1,
http://localhost/chat/2,
... ,
http://localhost/chat/N) a couple pubid/room is added to this
array. If a user closes a window, the corrensponding pubid/room array
entry is deleted ("deluser" event is fired). If a user wants to start
a private session, it simply passes the username to the application
server (in my case, that's Django), and then the application server
uses a custom inlinepush to create the session. The ape server, in
this case, checks for the presence of the username in the global
hashlist, and sends a signal to the corrensponding pubids. To achieve
these results, i've customized the xosofox's "nickname.js" to this
one:
var userlist = new $H;
Ape.registerHookCmd("connect", function(params, cmd) {
if (!$defined(
params.name)) return 0;
cmd.user.setProperty('name',
params.name);
cmd.user.setProperty('room', params.room);
return 1;
});
function listUserNames()
{
Ape.log("--------Current Userlist-------------------------");
userlist.each(function(v,k){
Ape.log(k + ": ");
v.each(function(infoAr, key){
infoAr.each(function(item, index){
//Ape.log(index + ': ' +item);
item.each(function(ob, ind){
Ape.log(ind + ': ' +ob);
});
});
});
});
Ape.log("--------Current Userlist End---------------------");
}
function getPubIdFromName(nickname){
var uis = userlist.get(nickname);
if(!$defined(uis)){
return 0;
}
else return uis;
}
Ape.addEvent("adduser", function(user) {
var name =user.getProperty('name');
var room = user.getProperty('room');
var pubid=user.getProperty('pubid');
var logged = false;
var uis=userlist.get(name);
//if no user instance hash, create one
if (!$defined(uis))
{
var singleInfoAr = new Array(pubid, room);
var infoContainer = new Array(singleInfoAr);
uis= new $H;
uis.set('infoAr', infoContainer);
userlist.set(name, uis);
}else{
infoAr = uis.get('infoAr');
infoAr.each(function(v, k){
if(v[1]==room){
v[0] = pubid;
Ape.log('Updated Pubid!');
logged=true;
}
});
if(!logged){
var singleInfoAr = new Array(pubid, room);
infoAr.extend(Array(singleInfoAr));
uis.set('infoAr', infoAr);
}
userlist.set(name, uis);
}
listUserNames();
});
Ape.addEvent("deluser", function(user) {
var name=user.getProperty('name');
var pubid=user.getProperty('pubid');
Ape.log("Timeout: " + name + ": " + pubid);
var uis=userlist.get(name);
infoAr=uis.get('infoAr');
infoAr.each(function(v, k){
if(v[0]==pubid){
//delete the corrensponding array entry
infoAr.splice(k, 1);
}
});
uis.set('infoAr', infoAr);
if(infoAr.length == 0){
userlist.erase(name);
}
//if last instance left, erase hash
else userlist.set(name, uis);
listUserNames();
});
Please note the "room" parameter in the registerHookCmd function; this
is the room id coming directly from the URL. I pass it to the server
this way:
this.core.start({'name':String(nickname), 'room':room});
Hope this can help someone else, i've worked around it for two days,
and -yeah- i know it's a "raw" solution, but well... it works!
On 8 Feb, 15:20, Giuseppe Mastrandrea <
mastrandreagiuse...@gmail.com>
wrote: