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 <[email protected]> wrote: > That's an interesting point, Louis! > If i store a triple userID/roomID/pubid server-side i could have a > more flexible way to manage public AND private messaging. > When a user refreshes a page, the server will update the > corrensponding tuple with the new pubid. > Yeah, it's a bit complicated, but MAYBE this way i'll make it :-) > > On 8 Feb, 14:55, Louis Charette <[email protected]> wrote: > > > > > > > > > I should take a look again at that article, it's been a while! > > > The way I worked around to send private messages to a user (based on his > > CMS/forum user id), is to store this ID in the user object server side. > > When a private message need to be send to him, I call a custom server side > > command, loop thought all the ape clients, and send to the corresponding > > client. > > > Another way to handle private messaging on a chat, based on a CMS userID, > > is to have this user join a channel named after his ID. You the. Sed > > everything down this pipe. > > > - Louis > > > Envoyé de mon iPhone > > > Le 2012-02-08 à 06:55, Giuseppe Mastrandrea <[email protected]> > > a écrit : > > > > I read this, and i'm working on that very userlist. Maybe i'll be able > > > to post something useful in a few hours. Thanks :-) > > > > On 8 Feb, 12:48, Sergei Koba <[email protected]> wrote: > > >> Read this please http://www.xosofox.de/2010/10/ape-user-handling/ > > >> If someone hasn't posted this link already. It shows the way to store all > > >> pubids for a logged user. > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "APE Project" group. > > > To post to this group, send email to [email protected] > > > To unsubscribe from this group, send email to > > > [email protected] > > > For more options, visit this group at > > >http://groups.google.com/group/ape-project?hl=en > > > --- > > > APE Project (Ajax Push Engine) > > > Official website :http://www.ape-project.org/ > > > Git Hub :http://github.com/APE-Project/ -- You received this message because you are subscribed to the Google Groups "APE Project" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/ape-project?hl=en --- APE Project (Ajax Push Engine) Official website : http://www.ape-project.org/ Git Hub : http://github.com/APE-Project/
