Bidirectional Communication

The Equo Server component is the engine of the Equo Framework - it is the service which allows the communication between Java and Javascript and vice versa.

To illustrate the communication from Java to Javascript let’s assume we have a media application and that we want to implement the play action. In an Equo application, the Java code would be something like this:

.withMainMenu("Playback")
   .addMenuItem("Play")
   .onClick(() -> {
     System.out.println("Playing selected movie...");
   }, "playSelectedVideo")

When the developer defines an event, like happens in the case from above (playSelectedVideo), the Equo Server will handle it at runtime and it will broadcast the event and its payload to the registered handlers. Those handlers can live both in the Java code or in the Javascript one. If that event is intended to be handled in the Javascript code, the developer may define a new file (i.e. actions.js) inside the resources folder of the Equo application (See Structure of an Equo Application), and that file will listen to the event playSelectedVideo. When the event occurs, the Javascript handler of the new created file will be executed.

Now, let’s explore how the communication from Javascript to Java is performed. The following example shows a piece of Javascript code which handles a click event on a button:

button.click(function () {
   let videoTitle = MediaUtils.getVideoTitle();
   let imdbUrl = getImdbUrl(videoTitle);
   equo.openBrowser({
     url: imdbUrl,
     name: 'IMDB',
     position: 'bottom'
   });
 });

When the button is clicked, an openBrowser function of the Equo Framework is called and the payload is handled by the Equo Server component, which sends it to the registered handlers. On the Java side of the Equo Application, registered handlers may capture the event and open a new window instance set to the IMDB url of the video title, for example. In fact, this is a behavior provided by the Equo Framework itself - it uses registered Java handlers to automatically create new browser instances and windows.

All of these cases are transparent to the user developer and happen thanks to the Equo Server component. Users do not have to include any Equo dependency. All of these dependencies are provided at build time, thanks to the Equo CLI tool and the Equo Server. Users do not need to worry about the underlying infrastructure, they just send and listen to events.