Developer Tips & Tricks – Communication Between Gadgets and Presentations

February 06, 2013

Have you ever wished that your Gadgets could "talk" to your Presentations? Well, they can! A Gadget can communicate with a Presentation and vice versa using RPC, or remote procedure calls. If you've ever built a Gadget, then you've already used RPC. It's what is used to tell the Viewer app that a Gadget is Ready or Done, for example.

Let's suppose you need to pass some information to the Presentation when a user selects an element in a Gadget. When that happens, you'll want to make an RPC call inside the Gadget:

gadgets.rpc.call("", "elementClicked", null, "param1 goes here");

The gadgets.rpc.call declared above includes several parameters. Here’s the breakdown:

  • The ID of the RPC service provider ("" means the parent container).
  • The name of the service that is being called.
  • The name of a local callback function to be executed when the RPC call is complete.
  •  The fourth and subsequent parameters are any parameters you'd like to pass along.

Get started with Rise Vision

Then, in the Presentation of our signage software, you would register to listen for the elementClicked service:

gadgets.rpc.register("elementClicked", function(param1) {
//Do something with param1 here.
});

The parameters for gadgets.rpc.register are as follows:

  •  Name of the RPC service.
  • Callback function to handle the response.

In the callback function, you can do whatever is appropriate for your particular Presentation. That's pretty much all it takes to establish communication between Gadgets and Presentations!