Hello guys,
However, by using user channel we can not send broadcast message to all user
in a domain.
For example, I want to create chat like application where a user can see all
the other users status, receiving user status change from server, receiving
message directly from other user, and in the same application, I would like
to enable message push if there is any notification directly from the server
to a particular user.
The scenario will be:
1. User login using authentication system and will receive session ID.
2. The session ID will be assigned to user property as parameter when user
is connecting to APE server
// Client script
client.core.start({'name':'Username', 'sessionID':sessionID});
3. Force the user to connect to broadcast channel
// Client script
client.addEvent('ready', function() { client.core.join('broadcast'); })
4. Create on connect hook on the server side to assign the sessionID (and
name) as user property
// Server script
Ape.registerHookCmd("connect", function(params, cmd) {
cmd.user.key = params.key;
cmd.user.sessionID = params.sessionID;
}
5. When we want to send inline push to a user, it should send to the
particular user using the session ID, and APE server module need to find the
user with corresponding sessionID inside the broadcast channel
// Server script
var chan = Ape.getChannelByName(params.channel); // params.channel
should be set = 'broadcast'
var userArray = chan.userslist.some(function(user) {
if (user.getProperty('sessionID') == sessionID) {
user.pipe.sendRaw(params.raw, params.data);
return true; // to satisfy the search
}
});
I am not sure if this scenario will work or not since I haven't tested it
yet. anyone have opinion?
Cheers,
Eko
On Sat, Mar 13, 2010 at 9:40 AM, bruno.braga <[email protected]> wrote:
> Hi Timo,
>
> Thanks a lot for the insights... I will try that approach well and get
> back to you.
>
> Once you post it on your blog, please place the link here to for
> reference to us...
>
> Thank you again for all the help.
>
> Bruno
>
> On Mar 13, 3:48 am, Timo Michna <[email protected]> wrote:
> > Hi!
> > Could we send more data to APE then to be processed? Let's say, like a
> > hash for the authentication key plus something that APE could decode
> > and verify?
> > I thought about this, too.
> > The one solution I have for now:
> > If the user authenticates through the system a unique key will be
> generated(one could use the session key) which is passed to the Client.The
> key has to be stored in the system to be later referenced by the push
> script.The client now connects to APE with this key. Something like this:
> > client.core.start({"name": 'UserName',
> "key":"321"}); client.addEvent('ready', function()
> { client.core.join('UserChannel');}
> > On the server side you create a connect hook
> > Ape.registerHookCmd("connect", function(params, cmd) { [...see
> APE_Server/scripts/examples/nickname.js] // this makes the
> key a private property on user cmd.user.key = params.key
> > return 1;});
> > So still anyone could connect to the channel, but we have to makesure,
> that only the valid user gets our message. So the script to dothe push also
> sends the secret key of the user.Something like this (again like the
> Controller demo)
> > var chan =
> Ape.getChannelByName(params.channel);chan.userlist.each(function(user){
> if(user.key == params.key){ user.pipe.sendRaw(params.raw, params.data);
> } });
> > While I have not tested it, this approach should work. (Another solution
> would be, not to do the channel connection througha client call but also in
> the connection hook. This will not prevent someonefrom connecting to the
> channel, but makes guessing a bit harder)
> > I hope I can do a proper test over the weekend and then Iwill do a blog
> post so more people can find it.
> > Please, tell me when you might find a reasonable mistake in the solution.
> > have a nice weekend :o)Timo
> >
>
--
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/