JavaScript Application - Summary Steps

This uses the JavaScriptDemo example application which is included with the ManagedHubDemo files.

This example consists of three files:

  • The main html file:

    ./JavaScriptDemo.html

    • Two JavaScript files which are loaded from the main page like this:
      <head>
         <title></title>
         <!-- Load the PageBus JavaScript file. -->
         <script type="text/javascript" language="javascript" src="./ManagedHubDemo/PageBus.js"></script>
         <!-- Load the JavaScriptDemo JavaScript file. -->
         <script type="text/javascript" language="javascript" src="./ManagedHubDemo/JavaScriptDemo.js"></script>
      </head>

The steps for creating a JavaScript client that receives ManagedEvents from Openspace are similar to those of the ManagedHubDemo example GWT application with several key differences:

  • The TIBCO PageBus ManagedHub JavaScript interface must be used directly. For details on this interface see:

    TIBCO PageBus™ Developer’s Guide Software Release 2.0 October 2009

  • In JavaScript there is no ManagedEvent or ManagedEventHandler classes so the JavaScript message object is handled directly.
  • In JavaScript there is no ManagedEventClient class which handles the details of creating and connecting the IframeHubClient. This needs to be done directly in JavaScript.
Note: The same basic steps are performed as in the createIframeHubClient() method of the ManagedEventClient class in GWT.

Procedure

  1. Check the format of the messages that correspond to the Openspace ManagedEvent the client will be receiving:
  2. Create an onDataCallback function to handle the message resulting from an Openspace ManagedEvent:
        function onDataCallback(topic, message, subscriberData)
        {
        	// Process topic and message here.
        }
  3. Create the IframeHubClient:

    See the JavaScriptDemo.js createIframeHubClient function.

  4. Connect the IframeHubClient:

    The call to IframeHubClient connect is asynchronous and the post connect actions must be done in a callback that is passed to the connect method:

    iframeHubClient.connect(onConnectCompleteCallback);

  5. After connecting the IframeHubClient:
    • These actions are performed in the onConnectCompleteCallback.
    • Subscribe to each of the message types using the topic and onDataCallback that will process incoming messages.
    • The JavaScriptDemo.js provides two examples functions that subscribe to messages:

      doPageBusMessageSubscribe();

      doManagedEventMessageSubscribe();

      These both subscribe to messages in the same way. The only difference is in distinguishing between messages that result from an Openspace ManagedEvent being fired and any other message that can be published on the PageBus.