Gadgets.pubsub (v0.9)

From VZ Developer Wiki
Jump to: navigation, search

gadgets.pubsub

Provides operations for publishing and subscribing to message channels for gadget to gadget communication, if there are more than one gadget present on one page.

Methods

gadgets.pubsub.publish

gadgets.pubsub.publish(channelName, message)
Publishes a string-type message to a channel.
Parameters
String channelName - The name of the channel
String message - The message to publish
Returns
None

gadgets.pubsub.subscribe

gadgets.pubsub.subscribe(channelName, callback)
Subscribes a gadget to a message channel.
Parameters
String channelName - The name of the channel
Funciton callback - A function that will be called with the channel messages
Returns
None

gadgets.pubsub.unsubscribe

gadgets.pubsub.unsubscribe(channelName)
Unsubscribes the gadget from a message channel.
Parameters
String channelName - The name of the channel
Returns
None

Examples

function callback(sender, message) {
  document.getElementById("output").innerHTML =
    "message : " + gadgets.util.escapeString(message + "") + "<br/>" +
    "sender : " + gadgets.util.escapeString(sender);
}

function subscribe() {
  gadgets.pubsub.subscribe("random-number", callback);
}

function unsubscribe() {
  gadgets.pubsub.unsubscribe("random-number");
  document.getElementById("output").innerHTML = "";
}

function publish() {
  var message = Math.random();
  gadgets.pubsub.publish("random-number", message);
  document.getElementById("output").innerHTML = message;
}


OpenSocial (v0.9)

gadgets

gadgets.io

gadgets.json

gadgets.Prefs

gadgets.util

gadgets.views

gadgets.flash

gadgets.MiniMessage

gadgets.oauth.Popup

gadgets.rpc

gadgets.skins

gadgets.pubsub

gadgets.Tab

gadgets.TabSet

gadgets.window

gadgets.i18n

opensocial

opensocial.Activity

opensocial.Address

opensocial.Album

opensocial.BodyType

opensocial.Collection

opensocial.CreateActivityPriority

opensocial.DataRequest

opensocial.DataResponse

opensocial.Email

opensocial.Enum

opensocial.Environment

opensocial.EscapeType

opensocial.IdSpec

opensocial.MediaItem

opensocial.Message

opensocial.MessageCollection

opensocial.Name

opensocial.NavigationParameters

opensocial.Organization

opensocial.Permission

opensocial.Person

opensocial.Phone

opensocial.ResponseItem

opensocial.Url

osapi.Request

osapi.BatchRequest

osapi.people

osapi.activities

osapi.appdata

osapi.messages

osapi.http