The javascript object to be used to control Ivy is window.ivyRequest or ivyRequest.
Let's now show the different methods :
IvyRequest.init(String applicationName, String greetMessage)
The arguments are optionnal. If no arguments are provided, the bus is initialised with default arguments ("OWB", "Hello") If one of them is omited, it is ignored and the previous statement apply. If both parameters are provided, they are used to initialise the bus.
IvyRequest.start(String IvyBus);
Once again, the paramater is optionnal but be aware that the default behaviour is to start on the loopback interface.
The IvyBus parameter is the bus adresse and possibly the port. For example : IvyRequest.start("192.168.1.255:2010");
IvyRequest.run();
After starting the bus, the application is listening to the bus. All listeners that were added before the call are now binded.
IvyRequest.stop();
IvyRequest.bindIvyMsg(callbackFunction, String regularExpression); or IvyRequest.addIvyMsgListener(callbackFunction, String regularExpression);
By default the callback method can take 3 String as arguments : the name of the application that send the message, the host that send the message and the message itself.
Example of a simple callback method :
function mySimpleCallbackFunction(appName, hostName, message) {
alert("Message " + message + " from "+ appName + "@" + hostName);
}
The registration for anything would be done with :
ivyRequest.bindIvyMsg(mySimpleCallbackFunction, "(.*)");
Another example would be to select only the messages that starts with "alert" :
ivyRequest.bindIvyMsg(mySimpleCallbackFunction, "$alert(.*)");
Note that your function will receive only what follows alert and not "alert" in this case.
Only one listener of this type is allowed and its binding is done with :
ivyRequest.setConnectListener(callbackFunction);
Example : very simple callback
function mySimpleConnectCallbackFunction(appName, hostName) {
alert("Connection from " + appName + "@" + hostName);
}
Only one listener of this type is allowed and its binding is done with :
ivyRequest.setDisconnectListener(callbackFunction);
See previous section for an example.
ivyRequest.unbindIvyMsg(callbackFunction, String regularExpression); or ivyRequest.removeIvyMsgListener(callbackFunction, String regularExpression);
The two arguments must be the same as those used when binding the listener.
In our example, it would be
ivyRequest.unbingIvyMsg(mySimpleCallbackFunction, "(.*)");
ivyRequest.removeAllIvyMsgListeners();
The same apply to setDisconnectionListener.
ivyRequest.removeAllIvyListener();
The status can be asked with
ivyRequest.getStatus();
The method returns a String that is one of those values :
1.5.2