[APE Project] JSJS: joining a channel

30 views
Skip to first unread message

Stefan Sayer

unread,
Apr 16, 2010, 6:04:13 AM4/16/10
to ape-p...@googlegroups.com
Hello,

I'm writing a json-rpc 2.0/netstrings/tcp server in ape JSJS, and I
would like to write a function with which the client can subscribe to
a channel, and then every time something is posted into that channel,
a notification is sent over the json-rpc connection.

Now, how do I join a channel in JSJS, so that I get a callback when
something is posted into that channel?

I have found the ircserver.js, but there it looks like APE JSJS in
IRCApeclient.sendCmd creates a new connection to itself to port 6969
and posts messages through that connection. Which, I think, is pretty
weird, and can really not be the solution; in the jsjs we are already
in the server code space. Or is this the only method to interact with
a channel from inside APE?

Thanks!
Stefan

--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to ape-p...@googlegroups.com
To unsubscribe from this group, send email to
ape-project...@googlegroups.com
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/

Nicolas Trani

unread,
Apr 16, 2010, 6:43:27 PM4/16/10
to ape-p...@googlegroups.com
Hi,

if you want to make a user join a channel use this :

http://www.ape-project.org/docs/server/users/user.join.html

And IRApeclient.sendCmd is just an IRC client in SSJS, a demo ;)

Regards.

Stefan Sayer a écrit :

Stefan Sayer

unread,
Apr 17, 2010, 6:26:22 AM4/17/10
to ape-p...@googlegroups.com
Hi,

thanks for the response.

Nicolas Trani wrote:
> Hi,
>
> if you want to make a user join a channel use this :
>
> http://www.ape-project.org/docs/server/users/user.join.html
but I can't create a user from SSJS, right? so where do I get the user
from, if I connect from jsonrpc, I can't do
var u = new user();
u.join('mychannel');
At least it gives me an error, and in libape-spidermonkey.c there is
no user class defined, unfortunately.

>
> And IRApeclient.sendCmd is just an IRC client in SSJS, a demo ;)
yeah, right, I understand... just, I haven't found a suitable example
for what I'm trying to do, and the irc client seemed to be the closest
match on the provided examples.

The interim solution I have now is a hook on send command, but that
doesn't seem to me a very good solution.

Thanks
Stefan

>
> Regards.
>
> Stefan Sayer a écrit :
>> Hello,
>>
>> I'm writing a json-rpc 2.0/netstrings/tcp server in ape JSJS, and I
>> would like to write a function with which the client can subscribe to
>> a channel, and then every time something is posted into that channel,
>> a notification is sent over the json-rpc connection.
>>
>> Now, how do I join a channel in JSJS, so that I get a callback when
>> something is posted into that channel?
>>
>> I have found the ircserver.js, but there it looks like APE JSJS in
>> IRCApeclient.sendCmd creates a new connection to itself to port 6969
>> and posts messages through that connection. Which, I think, is pretty
>> weird, and can really not be the solution; in the jsjs we are already
>> in the server code space. Or is this the only method to interact with
>> a channel from inside APE?
>>
>> Thanks!
>> Stefan
>>
>


--
Stefan Sayer
VoIP Services Consulting and Development

Warschauer Str. 24
10243 Berlin

tel:+491621366449
sip:sa...@iptel.org
email/xmpp:stefan...@gmail.com

Nicolas Trani

unread,
Apr 17, 2010, 12:30:55 PM4/17/10
to ape-p...@googlegroups.com
Hi,

you can access to the user object in all command. For example if you want to make a user join a channel on connect just do it like that :

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

Or in a custom command [1] : 

Ape.registerCmd('yourCommand', true, function(params, cmd) {
    cmd.user.join('testChannel');
    return 1;
});

Or even on some events like adduser [2] : 

Ape.addEvent('adduser', function(user) {
    user.join('testChannel');
});

- [1] http://www.ape-project.org/docs/server/commands/registercmd.html
- [2] http://www.ape-project.org/docs/server/events/adduser.html

And no you can't create user on the server side.

Regards.
-- 
Nicolas Trani - Web engineer
Weelya - Improve the web
32 rue du faubourg boutonnet
34090 Montpellier
Tel: 04 67 169 778 - Fax: 09 57 91 99 91
http://www.weelya.com
http://www.ape-project.org

Stefan Sayer

unread,
Apr 20, 2010, 8:52:31 AM4/20/10
to ape-p...@googlegroups.com
Hi,

thanks for your help.

Nicolas Trani wrote:
> And no you can't create user on the server side.
that's a pity. To show why, I have attached my solution to the jsonrpc
server which enables an external client to subscribe to a channel: As
you can see, for each message posted to every channel (subscribed or
not) it needs to run through the list of all subscribed clients.

As written in another post, it would help tremendously if custom pipes
could be linked to existing pipes in SSJS, or users could be created
on the server side.

Best Regards
Stefan
jsonrpcserver.js
Reply all
Reply to author
Forward
0 new messages