Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Supporting any rpc feature requires that the container include the appropriate javascript. The easiest way to get this is to source it from the gadget rendering server, i.e.:

<script src="http://example.org/gadgets/js/rpc.js?c=1"></script>

Specifying c=1 minimizes the returned set of javascript files to just that necessary to satisfy container dependencies.

You must also make sure that the rpc_relay.html (found in trunk/javascript/container/rpc_relay.html) is available to the gadget. You can do this by specifying the parent parameter in your iframe url.

You must call gadgets.rpc.setAuthToken for every gadget on the page, passing the same value for the second parameter as is included in the "rpctoken" query string parameter in the gadget's iframe. If you don't include the rpctoken parameter, you don't need to make this call, but messages can be spoofed.

Additional requirements for container to gadget message passing:

You must make sure that gadgets.rpc.setRelayUrl is called for every app, so that the container code understands where rpc_relay.html can be located.

dynamic-height

Code Block
titledynamic-height.js
 
gadgets.rpc.register('resize_iframe', function(height) {
 var element = document.getElementById(this.f);
 if (element) {
   // Adjust IFrame height
   height = Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, height));
   element.style.height = height + 'px';
 }
});

setprefs

Code Block
titlesetprefs.js
 
gadgets.rpc.register('set_pref', function(token, name, value) { 
  storeSomeValueForThisGadget(this.f, name, value);
});

setprefs has a legacy wart, the 'token' parameter. You can safely ignore this for now.

settitle

Code Block
titlesettitle.js
 
gadgets.rpc.register('set_title', function(title) {
 var element = document.getElementById(this.f + '_title');
 element.innerHTML = gadgets.util.escape(title);
});

requestNavigateTo

Code Block
titlerequestNavigateTo.js
 
gadgets.rpc.register('requestNavigateTo', function(view, opt_params) {
 var url = getUrlFor(view);
 if (opt_params) {
   var paramStr = gadgets.json.stringify(opt_params);
   if (paramStr) {
     url += '&appParams=' + encodeURIComponet(paramsStr);
   }
 }

 if (url && document.location.href.indexOf(url) == -1) {
   document.location.href = url;
 }
});

pubsub

To support pubsub, you'll need to include some additional code. Replace the first script with this:

<script src="http://example.org/gadgets/js/rpc:pubsub.js?c=1"></script>

Code Block
titlepubsub.js
 
gadgets.pubsubrouter.init(function(id) {
 // return the gadget spec url corresponding to the given gadget id.
 }
);

alternatively:

Code Block
titlepubsub-alt.js
 
gadgets.pubsubrouter.init(
 function(id) {
 // return the gadget spec url corresponding to the given gadget id.
 },
 {
   onSubscribe: function(sender, channel) {
     // return true to reject the request.
   },
   onUnsubscribe: function(sender, channel) {
     // return true to reject the request.
   },
   onPublish: function(sender, channel, message) {
     // return true to reject the request.
   }
 }
);