Hi, I saw there is already some answer to your issue, but the reason
why you do not have context in the function called with onSend.

I do not know Mootools as well as I do prototype, so here is the way
to make it work using prototype:

var MyClass = new Class({
    //Your vars
    initialize: function(options) { try {
        this.setOptions(options);
        this.instanceId = this.options.instanceId;
        this.channel = Ape.mkChan("*mychannel"+this.instanceId);

        this.channel.pipe.onSend = this.onSend.bind(this); //<=== this
uses prototype

    } catch(e) { Ape.log("[MyClass] initialize() EXCEPTION: "+e); } },


    onSend: function(user, params){
                //When onSend happens on the pipe, this function will
be called and you can refer to "this" inside of it to access your
instance of MyClass
                Ape.log("[MyClass] onSend()...");
    }

});

I am sure that Mootools has something to provide the same behavior.

I apologize if your issue has already been answered, just tought I
would share ;)


On Mar 15, 2:50 pm, nouknouk <[email protected]> wrote:
> Hi,
>
> 1) I have some code on server side (latest APE Git version) like that:
>
> var MyClass = new Class({
>     Implements: [Options],
>     options: {
>         instanceId: 1 // an integer
>     },
>     instanceId: 0,
>     channel: null,
>     initialize: function(options) { try {
>         this.setOptions(options);
>         this.instanceId = this.options.instanceId;
>         this.channel = Ape.mkChan("*mychannel"+this.instanceId);
>
>         this.channel.pipe.onSend = function(user, params)
> { Ape.log("[MyClass] onSend()..."); };
>
>     } catch(e) { Ape.log("[MyClass] initialize() EXCEPTION: "+e); } },
>
> });
>
> In 'global scope' code, I instanciate MyClass once (with option
> instanceId set to '1').
> I launch my APE server and then I connect to APE with my browser.
>
> Once my client is connected to APE:
> - I join "*myChannel1" : client.core.join("*mychannel1");
> - I wait for the 'CHANNEL' reply.
> - I call myChannelVar.send("abcdef");
>
> But on server side, the onSend callback fuction is never called.
> I don't understand why.
>
> Any idea ?
>
> 2) I wondered if there was a way to register events for a specific
> channel on server side. I mean having events equivalents to
> 'beforeJoin', 'join', left' but binded only to ONE channel (and not
> all channels of the APE server).
>
> I have a couple of workarounds to do that (*), but I think having such
> event at channel level would make sense if there was such feature in
> the server's package itself. Don't you think ?
>
> (*) workaround 1 :
> // global event written once...
> Ape.addEvent('join', function(user, channel) {
>     if (channel.onJoin != null) {
>         channel.onJoin(user);
>     }
>
> }
>
> // ... and for each channel instanciated:
> var myChan = Ape.mkChan("myChan");
> // add a callback if we want to listen to the event.
> myChan.onJoin = function(user) { Ape.log("onJoin"); }
>
> (*) workaround 2 (crappy way):
>
> // for each channel instanciated:
> var myChan = Ape.mkChan("myChan");
> Ape.addEvent('join', function(user, channel) {
>     if (channel == myChan) {
>         Ape.log("onJoin");
>     }
>
> }

-- 
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/

Reply via email to