Wednesday, April 9, 2014

Shindig communication

 

There are different ways a gadget can interact with the container and vice versa.
  1. RPC
  2. Gadget to server communication
  3. Publish / Subscribe

 RPC

The RPC mechanism is used to perform Gadget to Container communication & Gadget to Gadget communication.

The following needs to be done in order to call an RPC service from a gadget:
Container Page:
§  Create a new javascript Function

§  Register the function as a javascript service using gadgets.rpc.register API.

                Gadget Page:
§  From the gadget, call the RPC service using gadgets.rpc.call API

The first parameter “” indicates that we are going to call arpc service of the parent container.
Define the callback method for processSearchTerm.



1.2.    Gadget to Server communication.


Gadget.io API provides a mechanism by which the gadget will be able to communicate with the server side.

Gadgets.io.makeRequest accepts 3 parameters.
The first param is the URI that defines a service, second one defines the callback method, and the third one is the input parameters to the service.  The content type mentioned in the parameter is given as “TEXT”, which means the service will return a TEXT. The other content types supported are DOM, FEED & JSON. This has been explained in detail here: http://code.google.com/apis/gadgets/docs/remote-content.html#Content_Types
In the above example, the uri - rest/searchResults is nothing but a REST based service defined in Wink.

The code is given below:
           



1.3.    Publish/Subscribe.

This works on the basic bulletin board concept. A gadget can publish a message and the other gadgets which has subscribed for it can obtain the information and perform some business logic.
The example given below is taken from Shindig and is part of the distribution:
Subscriber:


The gadget can subscribe to master gadget using the subscribe API. The first parameter “random-number” defines a channel which it listens to.
The master gadget publishes a message using the following API:

Once this is called, the message is published to the channel, and the callback method is called on the subscriber.


No comments:

Post a Comment