rpcopensocial

OpenSocial gadget-to-gadget communication via gadgets.rpc


Could I have an example of communication between two OpenSocial gadgets using the gadgets.rpc API?

I've searched for one, but the closest I can find is a deprecated example of gadget-to-container communication.


Solution

  • you can use pubsub for gadget-to-gadget communication.

    on a gadget, you subscribe for an event as follows:

    gadgets.pubsub.subscribe("my_event_type",whenEventHappens);
    function whenEventHappens(sender, message){
          alert(message.content);
    }
    

    on another gadget, you publish events as follows:

    var message = {};
    message["content"] = "hey,wassup?";
    gadgets.pubsub.publish("my_event_type", message);