New contribution: qooxdoo cometd wrapper

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

New contribution: qooxdoo cometd wrapper

panyasan
Hello,

ever since Alex Russell coined the term "comet" for a server push technology for http, I have been fascinated by the idea. Being dissatisfied with the responsiveness of my app, I have long wanted to use it in qooxdoo - but without having the full overhead of including yet another javascript framework like dojo.  I have finally gotten around to porting the client javascript code to qooxdoo. The original code is a real mess, unfortunately - compared to the clean OO architecture of qooxdoo (it works with closures everywhere - it is hard to digest). The first result of the port can be found in qooxdoo contrib (cometd).

https://qooxdoo-contrib.svn.sourceforge.net/svnroot/qooxdoo-contrib/trunk/qooxdoo-contrib/cometd/trunk/

Here are the release notes:

This is a wrapper for the cometd javascript library.
See http://cometdproject.dojotoolkit.org/

Prerequisites:
-------------
- You need a working cometd server (http://cometd.org/documentation/cometd).
  I have been successful only with the Java/Jetty implementation, neither
  the python/twisted nor the perl server worked for me (on Mac OS X 10.5).
- You need to make sure that the cometd server listens on the same domain and port
  as the http server that serves the javascript files, otherwise it won't work
  (because of the dame-domain security policy). This might require that you
  add a redirection to the Apache server (for example, in my case, I had to use
  "ProxyPass /cometd http://localhost:8090/cometd-demo-1.0.0rc0/cometd"
  to redirect the requests to /cometd on the Apache instance to the Jetty
  server instance, which is running the cometd server.
 
Getting started..
-----------------
The best place to start is the chat demo shipped with this contribution. The other
demos provided with the dojo implementation have not been ported yet. The demo
has to be generated before it can be used.


Todo
----
- The contribution still depends on the dojo base library, this needs to be ported
  to work with the qooxdoo transport API.
- At the moment, the required libraries need to be manually imported in index.html.
  Need to find a way to programmatically load them at load time.

It works pretty well already:



Unfortunately, I cannot publish an online demo because I don't want to install a Jetty server on my public server.

As noted, there is still dojo code in the wrapper - because I don't really know how to port the transport stuff. In particular, the following code has to be changed: (source/class/cometd/Client.js:74).

    /*
     * Remap comet AJAX functions to dojo AJAX functions
     * @todo remap to qooxdoo transport
     */
    org.cometd.AJAX.send = function(packet)
    {
        var transportType = packet.transport.getType();
       
        if (transportType == 'long-polling')
        {
            // @todo qx'ify
            var deferred = dojo.rawXhrPost({
                url: packet.url,
                contentType: 'text/json;charset=UTF-8',
                headers: packet.headers,
                postData: packet.body,
                handleAs: 'json',
                load: packet.onSuccess,
                error: function(error) {          
                  packet.onError(error.message, deferred.ioArgs.error);
                }
            });
            return deferred.ioArgs.xhr;
        }
        else if (transportType == 'callback-polling')
        {
            // @todo qx'ify
            dojo.io.script.get({
                url: packet.url,
                callbackParamName: 'jsonp',
                content: {
                    // In callback-polling, the content must be sent via the 'message' parameter
                    message: packet.body
                },
                load: packet.onSuccess,
                error: function(error) { packet.onError(error.message, deferred.ioArgs.error); }
            });
            return undefined;
        }
        else
        {
            throw 'Unsupported transport ' + transportType;
        }
    };

Also, I haven't yet found a good was of including the required libraries at runtime - is there a way of telling the generator to load them in the script loader?

Ok, if you know how to setup the cometd server, you can check out the demo on your computer and  enjoy instant synchronization accross windows.

Best,

Christian


Reply | Threaded
Open this post in threaded view
|

Re: New contribution: qooxdoo cometd wrapper

fritz
On Sun, 4 Oct 2009, panyasan wrote:

> Also, I haven't yet found a good was of including the required libraries
> at runtime - is there a way of telling the generator to load them in the
> script loader?

Here is the answer I got recently on a similar question:

   qx.io2.ScriptLoader.load("your external js script", function() {
           // script is loaded
   }, this);

Cheers,
Fritz

--
Oetiker+Partner AG tel: +41 62 775 99 03 (direct)
Fritz Zaucker                        +41 62 775 99 00 (switch board)
Aarweg 15                            +41 79 675 06 30 (mobile)
CH-4600 Olten                   fax: +41 62 775 99 05
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: New contribution: qooxdoo cometd wrapper

panyasan
Fritz:

thanks, that would do the downloading, if you wrap the instantiation
of the cometd object into a series of nested callbacks which load the
required libraries. However, that is very hacky and unconvenient for
the user. It would be better if I could tell the generator to inlcude
these files into the script loader or the generated package. Since the
script files do not conform to the qooxdoo syntax, I cannot do that
through "#require". I don't know the generator options that well,
maybe there is a way of achieving this - this question goes to
generator experts ...

Thanks,
Christian

Fritz Zaucker-2 wrote
On Sun, 4 Oct 2009, panyasan wrote:

> Also, I haven't yet found a good was of including the required libraries
> at runtime - is there a way of telling the generator to load them in the
> script loader?

Here is the answer I got recently on a similar question:

   qx.io2.ScriptLoader.load("your external js script", function() {
           // script is loaded
   }, this);

Cheers,
Fritz

--
Oetiker+Partner AG tel: +41 62 775 99 03 (direct)
Fritz Zaucker                        +41 62 775 99 00 (switch board)
Aarweg 15                            +41 79 675 06 30 (mobile)
CH-4600 Olten                   fax: +41 62 775 99 05
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: New contribution: qooxdoo cometd wrapper

panyasan
In reply to this post by panyasan

panyasan wrote
- You need to make sure that the cometd server listens on the same domain and port
  as the http server that serves the javascript files, otherwise it won't work
  (because of the dame-domain security policy). This might require that you
  add a redirection to the Apache server (for example, in my case, I had to use
  "ProxyPass /cometd http://localhost:8090/cometd-demo-1.0.0rc0/cometd"
  to redirect the requests to /cometd on the Apache instance to the Jetty
  server instance, which is running the cometd server.
Just found this discussion thread:

http://groups.google.com/group/cometd-users/browse_thread/thread/a358dc87d1efa91c

saying that the cometd library does support cross-domain requests, which probably has to do with the "dojo.io.script.get()" command in the transport code. Does anybody on this list have deeper dojo knowledge?

Thanks,
Christian
Reply | Threaded
Open this post in threaded view
|

Re: New contribution: qooxdoo cometd wrapper

Siarhei Barysiuk
Hi Christian,

If you take a look at dojo comted implementation you can find how they  
get specific transport:

this.currentTransport = dojox.cometd.connectionTypes.match(
                                        data.supportedConnectionTypes,
                                        data.version,
                                        this._isXD
                                );

They provide _isXD flag which means "is this request cross domain?".

Also a few transports are implemented and they are right in cometd  
folder:
longPollTransportFormEncoded.js
longPollTransportJsonEncoded.js
callbackPollTransport.js

Each of these transports registers itself in connectionTypes pool (a  
line at the very bottom of each file) and implements check() function  
which checks based on provided params in onnectionTypes.match() call  
if this transport can be used.

CallbackPoll transport handles cross domain requests and it uses  
dojo.io.script.get() inside.

Hope it helps.

Cheers,
Siarhei Barysiuk

P.S. As I said I had started own cometd wrapped implementation some  
time ago using all qooxdoo OOP features but didn't have chance to  
finish it. I'll take a look at this once again and will provide my  
feedback.


On Oct 5, 2009, at 5:54 PM, panyasan wrote:

>
>
>
> panyasan wrote:
>>
>> - You need to make sure that the cometd server listens on the same  
>> domain
>> and port
>>  as the http server that serves the javascript files, otherwise it  
>> won't
>> work
>>  (because of the dame-domain security policy). This might require  
>> that
>> you
>>  add a redirection to the Apache server (for example, in my case, I  
>> had
>> to use
>>  "ProxyPass /cometd http://localhost:8090/cometd-demo-1.0.0rc0/ 
>> cometd"
>>  to redirect the requests to /cometd on the Apache instance to the  
>> Jetty
>>  server instance, which is running the cometd server.
>>
>
> Just found this discussion thread:
>
> http://groups.google.com/group/cometd-users/browse_thread/thread/a358dc87d1efa91c
>
> saying that the cometd library does support cross-domain requests,  
> which
> probably has to do with the "dojo.io.script.get()" command in the  
> transport
> code. Does anybody on this list have deeper dojo knowledge?
>
> Thanks,
> Christian
>
> --
> View this message in context: http://n2.nabble.com/New-contribution-qooxdoo-cometd-wrapper-tp3764689p3769346.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart  
> your
> developing skills, take BlackBerry mobile applications to market and  
> stay
> ahead of the curve. Join us from November 9-12, 2009. Register  
> now!
> http://p.sf.net/sfu/devconf
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: New contribution: qooxdoo cometd wrapper

Thomas Herchenroeder
In reply to this post by panyasan
Hi Christian,

thanks for this contrib, I'm very pleased to see cometd support coming
to qooxdoo :). I hope Siarhei can make it, and will support you in your
efforts. I'm sure you guys would make for a great team.

I've made a rough dump of your release notes into an initial contrib
homepage (cf. http://qooxdoo.org/contrib/project/cometd), as I thought
it too valuable to let it pass, but you might want to brush it up sometimes.


> Also, I haven't yet found a good was of including the required libraries at
> runtime - is there a way of telling the generator to load them in the script
> loader?
>  

I'm afraid no, not currently. Take a look at the Playground app and how
it handles the CodeMirror code. It treats the CodeMirror code files as
resources, and loads the main file in the index.html. That's probably
what you do now. As an alternative, you could probably load the foreign
code dynamically with a transport.Script object from your own code. This
would get the index.html rid of it.

Hope to see this thing grow.

T.

>  

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel