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 here.you can understand what i want to say more easily.
http://code.google.com/p/akjavacom-hangouts/

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
app://xxxx/hangout

gwt created js is still where you uploaded
http://???.appspoto.com/xxx123.cache.js

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

computeUrlForGadgetResource.js
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};
  }
  /** YOU MUST REPLACE HERE **/
  resource="http://api.akjava.com/api_list/"+resource;
 
  /* 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 $wnd.gadgets.io.getProxyUrl(resource, 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"

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

changed
return computeUrlForResource("http://akj.appspot.com/"+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
http://code.google.com/p/gwt-google-apis/

If you use Eclipse read gadget/eclipse/README.txt
you need to download http://google-web-toolkit.googlecode.com/svn/tools
and set GWT_HOME environment.

try
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("http://hangoutsapi.appspot.com/static/hangout.js",null);
HTML html=new HTML();
html.getElement().insertFirst(script);
RootPanel.get().add(html);

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

now i'm changing com.google.gwt.gadgets.client.linker.GadgetLinker.java like this
String bootstrap = "<script type='text/javascript' src='http://hangoutsapi.appspot.com/static/hangout.js'></script>\n"+


4. gadget need rpc and dynamic-height feature

do like that.

@FeatureName({"rpc","dynamic-height"})
interface SupportFeature {}

@ModulePrefs(//
        title = "GWT Hangouts",width=550,height=200)
        @UseLongManifestName(false)
        @AllowHtmlQuirksMode(false)
public class AkjGadget extends Gadget<TestPreference> implements SupportFeature {

According to official document "views" is imporant too.
http://developers.google.com/+/hangouts/writing#xml

@FeatureName({"rpc","dynamic-height","views"})


5. understand how to access js-object.


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


use $wnd
public native String ready()/*-{
      return ""+$wnd.gapi.hangout.isApiReady();
    }-*/;



Sample Apps



Comments