Question

PubNub works by calling callback functions you specify like this: http://www.pubnub.com/account-javascript-api-include

How to integrate this properly with the Qooxdoo JS framework? Qooxdoo application looks like this: http://demo.qooxdoo.org/current/playground/#Hello%20World-ria

How do you load the external JS library and make the global "PUBNUB" available?

Was it helpful?

Solution

You could easily use the add-script config key, to load the pubnub-*.min.js before your app. Then add the PUBNUB.subscribe() call anywhere in your qooxdoo code where it suits you, e.g. in the main method of your main class or in an event handler of a GUI element like a button.

EDIT:

To add more details:

  • You add the add-script key in config.json, in the "jobs" section.
  • As you need the script in both the source and the build version, you should add it to the source-script and the build-script jobs, or you create a separate job for the key and extend source-script and build-script with it (that would I do).
  • The warning about the job shadowing is only to alert people that inadvertently use a pre-defined job name for self-defined job. But here this is exactly what you want, and you can silence the warning with the config-warnings key if you wish. But this doesn't affect the built app.
  • As for the definedness of PUBNUB you might run into a timing issue where your code using PUBNUB is already executed when the pubnub script file has not finished loading. In your running app, first check in the command line (e.g. Firebug or Chrome Developer Tools) if the PUBNUB symbol is known. If so, the loading was successful. In that case you might want to delay access to the PUBNUB symbol in your code, e.g. by placing it in an execute listener of a button.

Here is a fragment of the possible config.json entries:

...
"jobs" : {
   "add-pubnub" : {
       "add-script" : [
         {
           "uri": "http://cdn.pubnub.com/pubnub-3.3.min.js"
         }
       ]
   },
   "source-script" : {
       "extend" : ["add-pubnub"]
   },
   "build-script" : {
       "extend" : ["add-pubnub"]
   }
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top