Zhen Wang
unread,Apr 17, 2008, 5:43:11 PM4/17/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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?