Proposal: gadgets.rpc.pubsub - a gadget-to-gadget communication API

4 views
Skip to first unread message

Zhen Wang

unread,
Apr 17, 2008, 5:43:11 PM4/17/08
to opensocial-an...@googlegroups.com
Problem:
The gadgets.rpc library enables a gadget to send messages to its container page, and vice versa, yet there is not a standard gadget-to-gadget communication protocol which could open the door to more collaborative gadgets.


Proposed solution:
Add a JavaScript feature named "pubsub" which, based on a publisher-subscriber model, allows gadgets on the same container page to communicate with each other. "Pubsub" utilizes the existing gadget.rpc library for container-mediated message delivery.

To publish a string-type message to a channel, a gadget calls:
    gadgets.rpc.pubsub.publish(channel_name, message);

To subscribe to a message channel, a gadget calls:
    gadgets.rpc.pubsub.subscribe(channel_name, subscriber_callback);
    function subscriber_callback(message, sender) {
      /* Do something with message if sender is a trusted gadget spec URL. */
    }

To unsubscribe from a channel, a gadget calls:
    gadgets.rpc.pubsub.unsubscribe(channel_name);

On the container side, the following function must be called to support "pubsub":
    gadgets.rpc.pubsub.initializeRouter(gadget_id_to_spec_url_callback, {
      onSubscribe: on_subscribe_callback, // optional
      onUnsubscribe: on_unsubscribe_callback, // optional
      onPublish: on_publish_callback // optional
    });
    function gadget_id_to_spec_url_callback(gadget_id) {
      /* Given a gadget id, return the corresponding gadget spec URL. */
    }
    function on_subscribe_callback(gadget_id, channel_name) {
      /* Return true to reject the subscription request; return false to accept it. */
    }
    function on_unsubscribe_callback(gadget_id, channel_name) {
      /* Return true to reject the unsubscription request; return false to accept it. */
    }
    function on_publish_callback(gadget_id, channel_name, message) {
      /* Return true to discard the message; return false to proceed to broadcast it to the channel. */
    }

The "pubsub" library is designed in such a way that all gadgets are allowed to send messages to any message channel without having to register a channel first; containers have full control over message delivery and may choose to discard or throttle messages; and subscribers are given the choice to ignore messages sent from untrusted sources.

Thoughts?

Kevin Brown

unread,
Apr 17, 2008, 7:46:56 PM4/17/08
to opensocial-an...@googlegroups.com
Why not just gadgets.pubsub? I know it's layered on top of rpc, but it seems a little cleaner to just have it exist as a standalone library. Are there implementation details that make this easier if it's actually an extension of rpc?
--
~Kevin

Zhen Wang

unread,
Apr 17, 2008, 7:52:46 PM4/17/08
to opensocial-an...@googlegroups.com
gadgets.pubsub sounds good to me.

Kevin Brown

unread,
Apr 17, 2008, 8:15:10 PM4/17/08
to opensocial-an...@googlegroups.com
And the triggering would be <Require feature="pubsub"/>, right?
--
~Kevin

Zhen Wang

unread,
Apr 17, 2008, 8:18:47 PM4/17/08
to opensocial-an...@googlegroups.com
Correct.

Reinoud Elhorst

unread,
Apr 18, 2008, 3:47:10 AM4/18/08
to opensocial-an...@googlegroups.com
+1

Jun Yang

unread,
Apr 21, 2008, 1:06:10 AM4/21/08
to opensocial-an...@googlegroups.com
+1

Zhen Wang

unread,
Apr 24, 2008, 3:42:42 PM4/24/08
to opensocial-an...@googlegroups.com
Kevin, Reinoud, Jun, and I are all for it.
Will one more person chime in please?

Thanks!

Robert Evans

unread,
Apr 24, 2008, 5:58:11 PM4/24/08
to opensocial-an...@googlegroups.com
+1

Martin Webb

unread,
Apr 24, 2008, 6:20:01 PM4/24/08
to opensocial-an...@googlegroups.com
+1

--
Internet Related Technologies - http://www.irt.org

Cassie

unread,
Apr 25, 2008, 7:46:37 AM4/25/08
to opensocial-an...@googlegroups.com
approved. thanks.

- cassie
Reply all
Reply to author
Forward
0 new messages