You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@rave.apache.org by Roel van Dijk <ro...@finalist.com> on 2012/07/02 17:41:52 UTC

osapi.people.getViewer method missing after reload

I am seeing some very strange behavior on our Ubuntu deployment:

Here is our setup: Shindig and Rave on a Tomcat 6 server, OpenJDK6. We have
customized Rave to have a very empty page, with only one OpenSocial gadget.
We host the gadget on the same machine.

We start Tomcat, and visit the main page. We log in and we see the page.
Everything works fine: We see the gadget, all the gadget's Javascript and
CSS are loaded and the application is running fine. Our application calls
osapi.people.getViewer() with a callback, and this works fine.

Here comes the strange thing: when we reload the page, we get a Javascript
error in the browser: "Uncaught TypeError: Object #<Object> has no method
'getViewer' ". In our gadget's Javascript we see that the error is thrown
where we do the   osapi.people.getViewer call. After some debugging, we see
that the osapi.people object that is being called is actually a different
version, which indeed does not have the getViewer method. The only three
methods we see are: get, supportedFields and update. The only way to solve
this problem is to completely restart Tomcat, and it will work for the
first request again.

Does anyone here know what is going on? Why does the first request work,
but all following requests fail? How can the people object miss many
functions?

-- 
Roel

Re: osapi.people.getViewer method missing after reload

Posted by Roel van Dijk <ro...@finalist.com>.
>
> At the end of the day however this
> is a shindig issue, not a rave issue to solve.


I see that. Maybe there should be a separate trigger that fires after all
the other shindig triggers are done.



> > We've fixed this by explicitly checking for the existence of
> > osapi.people.getViewer, and delaying our gadget's Javascript until the
> > function exists.
>
> Can you post how you went about doing this so other people can use it as
> well?
>

In our project we write Coffeescript, and this code waits for the getViewer
method to exist:

   waitForOsapi: (callback) ->
     @interval = setInterval =>
       if osapi and osapi.people and osapi.people.getViewer
         clearInterval(@interval)
         callback()
     , 25

Which is used as such:

     @waitForOsapi =>
       console.log "done!"
       @doStuff()

-- 
Roel

Re: osapi.people.getViewer method missing after reload

Posted by Chris Geer <ch...@cxtsoftware.com>.
On Mon, Jul 9, 2012 at 5:07 AM, Roel van Dijk <ro...@finalist.com> wrote:

> On Mon, Jul 2, 2012 at 5:41 PM, Roel van Dijk <ro...@finalist.com> wrote:
> >
> > Does anyone here know what is going on? Why does the first request work,
> > but all following requests fail? How can the people object miss many
> > functions?
> >
>
> This turned out to be a timing issue. The getViewer() function is added tot
> osapi.people service object by a gadgets.util.registerOnLoadHandler. Our
> call to getViewer() also happens on page load, but apparently too early, so
> it happens before the function was added to osapi.people.
>
> I couldn't find a callback or event to use for the completion of the
> registered registerOnLoadHandler-s.
>

Roel, this is turning out to be a common problem (my opinion at least).
There are a lot of capabilities that internally use the onLoadHandler
mechanic that gadgets depend on but since there isn't a guaranteed order to
them being called you never know if things will be loaded right if your
gadgets triggers on that event as well.  At the end of the day however this
is a shindig issue, not a rave issue to solve.

>
> We've fixed this by explicitly checking for the existence of
> osapi.people.getViewer, and delaying our gadget's Javascript until the
> function exists.
>

Can you post how you went about doing this so other people can use it as
well?

>
> --
> Roel
>

Re: osapi.people.getViewer method missing after reload

Posted by Roel van Dijk <ro...@finalist.com>.
On Mon, Jul 2, 2012 at 5:41 PM, Roel van Dijk <ro...@finalist.com> wrote:
>
> Does anyone here know what is going on? Why does the first request work,
> but all following requests fail? How can the people object miss many
> functions?
>

This turned out to be a timing issue. The getViewer() function is added tot
osapi.people service object by a gadgets.util.registerOnLoadHandler. Our
call to getViewer() also happens on page load, but apparently too early, so
it happens before the function was added to osapi.people.

I couldn't find a callback or event to use for the completion of the
registered registerOnLoadHandler-s.

We've fixed this by explicitly checking for the existence of
osapi.people.getViewer, and delaying our gadget's Javascript until the
function exists.

-- 
Roel