>From what I've gathered it all boils down to getting their pubid.
Once you have that you simply
do:
var recipient = Ape.getUserByPubid(pubid);
recipient.pipe.sendRaw('someCommand', {
param1: 'value1',
param2: 'value2'
});
The thing you have to do yourself is store each user's pubid somewhere
and reference
it by something you know about the user so you can look it up later.
In other words sessions, which ape doesn't provide for you.
What I did was store each users pubid to mysql when they connect:
Ape.registerHookCmd("connect", function(params, cmd) {
Ape.log('--------------------------');
Ape.log('connect');
if (!$defined(params.sessionKey)) {
Ape.log("Can't connect, sessionKey not specified");
return 0;
}
cmd.user.setProperty('sessionKey', params.sessionKey);
return 1;
});
Ape.addEvent('adduser', function(user) {
Ape.log('--------------------------');
Ape.log('adduser');
var pubid = user.getProperty('pubid');
var sessionKey = user.getProperty('sessionKey');
Ape.log('Updating users pub id to '+pubid+' in the database');
sql.query("SELECT * FROM sessions WHERE id = '"+session+"' LIMIT
1", function(res){
var userId = res[0]['user_id'];
sql.query("UPDATE `users` SET `pubid` = '"+pubid+"' WHERE
`id` = "+userId);
});;
});
In the connect hook you store the users sessionKey and then use it in
the adduser event to fetch their session
from the database. That get's you their userId, and then you can
update their db record with their ape pubid. It essentially
ties their web session and their ape session together.
To send something out to a specific user you just have to know
something about them... like their username, session key, etc.
so you can grab their record from the database.
Also, to get the session key into ape from the client I just read
their session cookie from the browser and passed it as a param
on ape.core.start:
Another approach if you can't use mysql is to keep a hash of usernames/
nicknames to pubids directly in the javascript module.
Checkout the nickname example in the source, it gives the basics of
how to set that up.
ape.core.start({
sessionKey: $.cookie("SESSION_COOKIE")
});
--
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/