Contents | Index | Previous | Next

Chapter 3: Acquiring system level information

This chapter shows how the system level information can be acquired in synchronous or asynchronous manner.

At any point in time after registration, certain system information can be obtained from Tango_agent:

jsapi00090000.gif userName: name of the user as logged to the Tango

jsapi00090000.gif isMaster: whether the user is the master of this session

jsapi00090000.gif masterName: name of the user who is the master of this session

jsapi00090000.gif participantNames: names of all participants of this session.

Example below creates a form with one button, which, when clicked, calls appropriate methods of Tango_agent in order to get Tango system info and print it out to the Java console of the browser:

ex31.html

<html>

<body onUnload="Tango_exit()">

<script language="javascript">

function Tango_register(win)

{

Tango_agent=Packages.webwisdom.tango.TAgentJS.createTAgentJS(win);

}

function Tango_exit()

{

if(Tango_agent!=null)

Tango_agent.exitJS();

}

function print(s)

{

Packages.java.lang.System.out.println(s);

}

function Tango_debug()

{

if(Tango_agent==null)

return;

print("agent="+Tango_agent);

print(" userName="+Tango_agent.getUserNameJS());

print(" isMaster="+Tango_agent.isMasterJS());

print(" masterName="+Tango_agent.getMasterNameJS());

print(" participantsNames="+Tango_agent.getParticipantsNamesJS());

}

Tango_register(window);

</script>

<form>

<input type="button" value="debug" onclick="Tango_debug()">

</form>

</body>

</html>

Function print() is only a utility that prints its argument to the Java console. Function Tango_debug() calls Tango_agent's methods and prints results using print() function. Button "debug" calls Tango_debug() when clicked.

Some of the information provided by the Tango system is, by its very nature, constant, e.g. user name, which is determined on login, remains unchanged during the session's life span. Another type of system information may change during the session, e.g. who is the master of the session. In such a case, it is useful to have a mechanism for being informed about changes when they occur. In Tango, an application may register to receive asynchronous updates about system state changes. The way to do this is similar to registering data listeners (Tango_agent.addTDataListenerJS(window) in the Chapter 2):

ex32.html

<html>

<body onUnload="Tango_exit()">

<script language="javascript">

function print(s)

{

Packages.java.lang.System.out.println(s);

}

function Tango_register(win)

{

Tango_agent=Packages.webwisdom.tango.TAgentJS.createTAgentJS(win);

}

function Tango_exit()

{

if(Tango_agent!=null)

Tango_agent.exitJS();

}

Tango_register(window);

function Tango_masterChanged(isM,mNa)

{

print("Tango_masterChanged("+isM+","+mNa+")");

}

function Tango_participantJoined(pNa)

{

print("Tango_participantJoined("+pNa+")");

}

function Tango_participantLeft(pNa)

{

print("Tango_participantLeft("+pNa+")");

}

if(Tango_agent!=null)

{

Tango_agent.addTMasterListenerJS(window);

Tango_agent.addTParticipantsListenerJS(window);

}

</script>

</body>

</html>

Functions addTMaster/ParticipantsListenerJS() register the script identified by the window passed as the functions' argument. Note that this is different registration than the initial registration in the system (Tango_register()) or the registration of this session private data listeners (addTDataListenerJS()). This one notifies Tango_agent that the given script should receive notifications about system events. Notifications will be made by calling script's functions: Tango_masterChanged(), Tango_participantJoined(), and Tango_participantLeft(). All these functions must be defined in the script, and their signatures (number of arguments) must be as in the example above. The implementation, however, will vary with the applications needs; some functions' bodies may be left empty, while another may make a full use of all the arguments. Our code just prints function names and their arguments.

Advanced applications will most probably require asynchronous notifications and still use synchronous calls for the sake of convenience.