Private rooms

18 views
Skip to first unread message

Thibaut

unread,
Dec 12, 2009, 5:39:47 AM12/12/09
to APE Project
Hi,

I'm trying to implement a private chat system with Ruby on Rails and
Ape. Before 1.0 came out I was using Juggernaut, a Flash plugin with a
push server.

Juggernaut makes it easy to have private rooms thanks to a particular
callback: subscription_url (login). When a user attempts to subscribe
to a channel, the push server sends a request to the Rails app and if
the response code is anything but 200 then the "subscribe" action is
canceled.

I've tried to implement this with Ape but I can't get "cmd.user.join
(params.channels)" to work properly (the channel variable is correct).

Ape.registerHookCmd("JOIN", function(params, cmd)
{
... // Initializing p variable

var request = new Http('http://127.0.0.1/ape/connect', 3000);
request.set('method', 'POST');
request.writeObject(p);

request.finish(function(result) {
if (result.status == 200) cmd.user.join(params.channels);
});

return ["209", "AUTH_IN_PROGRESS"];
});

The request is sent asynchronously (I tried to use Prototype or JQuery
to send a synchronous Ajax request with success / failure callbacks
but they wouldn't load) so the "return" is executed before the
"finish" callback is called. I'd expect it to subscribe the user to
the channel but it doesn't work.

However, if I change the "return" value to 1, then the user is
subscribed twice (the second subscription coming from the "finish"
callback).

I tried to understand how the join command works and tested this:
(with no other hook)

Ape.registerHookCmd("connect", function(params, cmd) {
cmd.user.join('testChannel');
return 1;
});

... but it doesn't work (I can verify it with a beforeJoin event or by
pushing data to the channel).

I'm running Mac OS X 10.5 and compiled APE Server from source.

Thanks for your help.

Thibaut

Anthony Catel

unread,
Dec 12, 2009, 10:19:15 PM12/12/09
to ape-p...@googlegroups.com
Hi Thibaut,

You forgot to create the channel first.
user.join() will fail if the channel doesn't exist.

What you can do is :

if (!$defined(Ape.getChannelByName(params.channels)))
Ape.mkChan(params.channels);
cmd.user.join(params.channels);

It's a little bit weird to have to create the channel yourself. I'll fix
that later ;)

Anthony

Le 12/12/09 11:39, Thibaut a �crit :

Thibaut

unread,
Dec 13, 2009, 4:33:39 AM12/13/09
to APE Project
Thanks! :)
Reply all
Reply to author
Forward
0 new messages