Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple comet application "org is not defined"

I am trying to update an old cometd javascript wrapper and test client (was 1.3.x) that I have to the newer comet 2.5.1 javascript implementation. I have all of the dependencies and the browser can find them all, yet I am getting errors in Firebug's console (see below) Multiple errors about "org"

The head of my HTML is as below:

<head>
    <title>CometD Tester</title>
    <link rel="stylesheet" type="text/css"href="style/style.css" />
    <script type="text/javascript" src="org/cometd/Cometd.js"></script>
    <script type="text/javascript" src="org/cometd/AckExtension.js"></script>
    <script type="text/javascript" src="org/cometd/ReloadExtension.js"></script>
    <script type="text/javascript" src="jquery/jquery-1.9.0.js"></script>
    <script type="text/javascript" src="jquery/jquery.cookie.js"></script>
    <script type="text/javascript" src="jquery/jquery.cometd.js"></script>
    <script type="text/javascript" src="jquery/jquery.cometd-reload.js"></script>
    <script type="text/javascript" src="js/myCometd.js"></script>
</head>

All of these are found by the browser. Looking at Cometd.js I see the following:

org.cometd.Cometd = function(name)
{
 ....
}

So is that not defining org? Note that none of the errors in the Console are from Cometd.js. Otherwise I see no other definition of "org.cometd". I would really appreciate it if anyone can help me out. I am using Tomcat 7 and below is the dir structure:

Layout of the directories for the client app

Thanks.

UPDATE - Further testing

I reduced the header to:

<head>
    <title>CometD Tester</title>
    <link rel="stylesheet" type="text/css"href="style/style.css" />
    <script type="text/javascript" src="org/cometd/Cometd.js"></script>
</head>

And removed ALL JS from the index.html. The only JS now included is the Cometd.js from the comet.org. There is still the same error... coming from the very first line in that script:

org.cometd.Cometd = function(name)

Not sure what I have missed here.

EDIT - Add jquery.cometd-reload.js This is the contents of the file. It looks like it is "re-binding" functionality from the cometd library to use the jquery one instead (?). I'm not up to speed enough in JS to debug this (I'm a C++ dev really).

(function($)
{
    function bind(org_cometd, cookie, ReloadExtension, cometd)
    {
        // Remap cometd COOKIE functions to jquery cookie functions
        // Avoid to set to undefined if the jquery cookie plugin is not present
        if (cookie)
        {
            org_cometd.COOKIE.set = cookie;
            org_cometd.COOKIE.get = cookie;
        }

        var result = new ReloadExtension();
        cometd.registerExtension('reload', result);
        return result;
    }

    if (typeof define === 'function' && define.amd)
    {
        define(['org/cometd', 'jquery.cookie', 'org/cometd/ReloadExtension', 'jquery.cometd'], bind);
    }
    else
    {
        bind(org.cometd, $.cookie, org.cometd.ReloadExtension, $.cometd);
    }
})(jQuery);
like image 850
Dennis Avatar asked Jan 30 '13 14:01

Dennis


1 Answers

So the problem was that I misunderstood the project layout from the Comet.org site. I should have followed the direction posted at cometd primer for non-maven setups a lot more closely. Basically when you are setting up the project you download the distribution, and then you need to take the code from the war files bundled inside the tarball. SO, once you have extracted the tarball...

  1. Take the org folder from cometd-javascript-common-2.5.1.war (located in \cometd-2.5.1\cometd-javascript\jquery\target) or cometd-javascript-jquery-2.5.1.war (located in \cometd-2.5.1\cometd-javascript\common\target)
  2. Take the jquery folder from cometd-javascript-jquery-2.5.1.war

The org namespace definition was in the file org/cometd.js which I did not have before, as I wrongly assumed that it had been replace by the org/cometd/Cometd.js file. The namespaces org and comet are defined as below starting on line 17 of that file:

// Namespaces for the cometd implementation
this.org = this.org || {};
org.cometd = {};

org.cometd.JSON = {};

The functions are working correctly now.

like image 115
Dennis Avatar answered Oct 03 '22 12:10

Dennis