Example

The following example shows how to write a simple JavaScript that receives initialization notification, then sets up a listener to receive connection state changes.

<script language="JavaScript">
<!--
    var mJSNotifier = null;
    var mJSAPI = null;

    /*
     *  This function receives the initial notification when the
     *  Reflection session is initialized and the JSEventNotifier
     *  module is done loading. It stores references to the
     *  notifier module itself and the JSAPI object,
     *  sets up the connection listener, then starts the host
     *  communications.
     */
    function ECLInitComplete(jsNotifier)
    {
        mJSNotifier = jsNotifier;
        mJSAPI = mJSNotifier.getJSAPI();
        registerConnectionListener();
        mJSAPI.connect();
    }

    /*
     *  Adds a listener to receive connection state changes. The
     *  parameter "connectionCallback" specifies the name of the
     *  JavaScript function that should be invoked when the
     *  connection state listener is invoked.
     */
    function registerConnectionListener()
    {
        mJSNotifier.addConnectionCallback("connectionCallback");
    }

    /*
     *  Callback function for connection state changes. This is the
     *  function defined above in the registerConnectionListener()
     *  function. This function will be invoked by the JSEventNotifier
     *  module when the connection state changes. The "state" parameter
     *  will contain the current state of the connection, either "true"
     *  if connected, or "false" if disconnected. The parameter is a boolean,
   *  but Firefox seems to see it as a string, while Internet Explorer sees
   *  it as a boolean.
     */
    function connectionCallback(state)
    {
      if ( state == true || state == "true" )        // session became connected
      {
          alert( "Session is connected!" );
      }
        else if ( state == false || state == "false" )  // session became disconnected 
      {
          alert( "Session is disconnected!" );
      }
    }
//-->
</script>

The JSEventNotifier module is part of the ECL API and its methods are detailed in the ECL documentation that's part of the ECL development kit.

HINT:The JSEventNotifier module also provides methods for accessing many of the ECL API objects, including ECLSession, ECLPS, ECLOIA, and others. Although you can access these objects from browser-based scripting languages, they are not fully compatible with these languages due to browser security restrictions, and invoking methods on these objects may result in script failures (as indicated by exceptions in the Java console). You should restrict your use of JSEventNotifier methods to those methods provided by the JSEventNotifier class itself, and to the methods in the JSAPI object you obtain.