Google+‎ > ‎

5 points to remember when trying to hangouts api with GWT-Gadget

hangout api is still preview.maybe all problem will be fixed soon.
I have to say I'm not familiar with inside-gwt,so maybe  i have misunderstan,feel free to collect me.
my google+ account is here.

I opensourced my first demo project can understand what i want to say more easily.

1. your gadget.xml can not read GWT created cached.js file.

your registed gadget.xml in Google API console,maybe copied to some google's server.
that why gadget.xml can not read cache.js file.

gadget.xml is loaded

gwt created js is still where you uploaded

you can make com/google/gwt/gadgets/linker/computeUrlForGadgetResource.js  and replace  resource path like below.

function computeUrlForResource(resource) {
    var tmpBase = $wnd.gadgets.util.getUrlParameters()['url']; 
      tmpBase = tmpBase.substring(0,  tmpBase.lastIndexOf('/') + 1);
    //useless like - app://334799408970/hangout
  var cacheSpec;
  if (resource.match(/\.cache\.(js|html)$/)) {
    // Allow GWT resources marked named as cachabele to be cached for one year.
    cacheSpec = {refreshInterval:31536000};
  /* Prepend anything that is not a fully qualified URL with the module base URL */
  if (!resource.match(/^[a-zA-Z]+:\/\//)) {
      resource = __MODULE_FUNC__.__moduleBase + resource;
  return $, cacheSpec);

warning if you choose this way,usually only one module would work fine. because each module have a difference location.

alternative way
I fixed this problem to add host url to gadget.xml manually with GWT compile option "-style pretty"

return computeUrlForResource(strongName + '.cache.js');

return computeUrlForResource(""+strongName + '.cache.js');

this solutions has a problem that compiler always rewrite your changed.
when you use google app engine,after deploying you need change gadget.xml and re-deploy(this time no compiling) it.

or create or change GadgetLinker and rebuild gwt-gadget.jar

sorry i misunderstand

I have no idea how to get original hosted url from gadget.xml in somewhere.
anyway if your gwt don't work anything check  result of loading cached.js in your browser log.

2. Released libraries usually don't work newer GWT

This is FAQ
Q some released library don't work GWT 2.4
A use newer library in trunk.

checkout /svn/gadgets

If you use Eclipse read gadget/eclipse/README.txt
you need to download
and set GWT_HOME environment.

build.xml and gadgets/build.xml
in my situation somehow i need to call build.xml and gadgets/build.xml to rebuild gwt-gadget.jar

3. gadget need hangout.js

I dont know smart way to insert script tab.

I have did in init(). be carefull this way make a problem when you call addApiReadyListener(),because script had not loaded yet.
ScriptElement script=createScriptElement("",null);
HTML html=new HTML();

     private static ScriptElement createScriptElement(String src,String content) {
            ScriptElement script = Document.get().createScriptElement();
            script.setAttribute("type", "text/javascript");
            return script;

now i'm changing like this
String bootstrap = "<script type='text/javascript' src=''></script>\n"+

4. gadget need rpc and dynamic-height feature

do like that.

interface SupportFeature {}

        title = "GWT Hangouts",width=550,height=200)
public class AkjGadget extends Gadget<TestPreference> implements SupportFeature {

According to official document "views" is imporant too.


5. understand how to access js-object.

don't call directly ,you will cache gapi is undefined error.
public native String ready()/*-{
      return "";

use $wnd
public native String ready()/*-{
      return ""+$;

Sample Apps