Just a guess, but perhaps your script was executed before the rpc feature 
had been initialized?  Maybe use a gadgets.util.registerOnLoadHandler.

But this problem seems to reveal a gap in OpenSocial.  There's this whole 
mechanism in place for injecting feature javascript into both the gadget 
and the container page, yet there are features like rpc and pubsub which 
still need more help.  Maybe the spec could use some API for the 
containing page and its role of managing gadgets.  This API could then be 
used to contribute to the rendering URL construction (so RPC could augment 
the location's hash with the auth token), and to then register the 
gadget's iframe ID (so RPC could set the relay URL). Maybe pubsub router 
could be smarter too.  It could just observe the gadget lifecycle and 
manage the id->specURL mapping itself, or maybe a gadget manager just make 
an equivalent available to the router.

Randy Hudson



From:
Fayland Lam <[email protected]>
To:
[email protected]
Date:
09/24/2009 11:04 PM
Subject:
Re: requestSendMessage problem again



hi Chris.

you saved my time. I added as what you said. and the firebug showes:

Unknown RPC service: requestSendMessage rpc.js?c=1 (line 4)

should I call something like "gadgets.rpc.register('requestSendMessage', 
this.requestSendMessage);" in the <script> tag?
or include which js in iframe page or xml?

I found in the shindig-1.1 the javascript/container/gadgets.js
  gadgets.rpc.register('requestSendMessage', this.requestSendMessage);
gadgets.IfrGadgetService.prototype.requestSendMessage = 
function(recipients,
    message, opt_callback, opt_params) {
    if (opt_callback) {
      window.setTimeout(function() {
        opt_callback(new opensocial.ResponseItem(
            null, null, opensocial.ResponseItem.Error.NOT_IMPLEMENTED, 
null));
      }, 0);
    }
};

so what's the next step?

Thanks for you reply, it really helps a lot.
once I make it working, I'll blog it.

Thanks.


Chris Chabot wrote:
> There's been quite a bit of work on the RPC code in the OS 0.8 -> 0.9 
time
> frame, and in most situations the rpc file isn't being used anymore.
>
> It took me a while to find out too (so I know how you feel about the 
lacking
> documentation:), the way to make it work now is to emit a bit of 
javascript
> after each iframe and include the #rpctoken in there, ie something like:
>
> <iframe
>                width="482"
>                        scrolling="no"
>                        height="200"
>                        frameborder="no"
> src="http://example.org/gadgets/ifr?etc#rpctoken=1707975397";
>                        class="gadgets-gadget"
>                        name="remote_iframe_14020"
>                        id="remote_iframe_14020">
> </iframe>
>
> <script type="text/javascript">
>   gadgets.rpc.setRelayUrl("remote_iframe_14020",
> "http://example.org/gadgets/ifr?etc#rpctoken=1707975397";);
>   gadgets.rpc.setAuthToken("remote_iframe_14020", "1707975397");
> </script>
>
> Example is a generized copy&paste from a random www.partuza.nl profile 
page
> & you can check it's code for the complete iframe generation flow
>
>
>
> On Thu, Sep 24, 2009 at 10:45 AM, Fayland Lam <[email protected]> wrote:
>
> 
>> well, basically I'm use the 'shindig-1.1-incubating-SNAPSHOT-php' for 
the
>> requestSendMessage
>>
>> for example, the shindig domain is 'opensocial.example.com' and the app
>> domain is 'app.example.com'.
>> then in app.example.com we will use iframe to call 
opensocial.example.com
>> the app xml contains something like:
>>       <script type="text/javascript">
>>           var init = function() {
>>               SendMessage(1747383, 'blabla');
>>           };
>>           gadgets.util.registerOnLoadHandler(init);
>>
>> function SendMessage(friendId, fname) {
>>
>>   var recipient = new Array();
>>   var message = new opensocial.newMessage(fname + ", You are invited to 
my
>> room");
>>   message.setField(opensocial.Message.Field.TITLE,"Test Invintation");
>>
>> 
message.setField(opensocial.Message.Field.TYPE,opensocial.Message.Type.NOTIFICATION);
>>
>> var onMessage = function(obj) {
>>   if (obj.hadError()){
>>       switch(obj.getErrorCode()) {
>>           case opensocial.ResponseItem.Error.NOT_IMPLEMENTED:
>>             alert('NOT_IMPLEMENTED');
>>             break;
>>           default:
>>             alert('code: ' + obj.getErrorCode());
>>             break;
>>       };
>>       return;
>>   }
>> };
>>
>>   recipient.push(friendId);
>>   opensocial.requestSendMessage(recipient,message,onMessage);
>> }
>>
>> and in the app.example.com we have
>> app.example.com/gadgets/files/container/rpc_relay.html
>>
>> I debugged for a while and I put an alert in
>> features/src/main/javascript/features/rpc/wpm.transport.js
>> to debug the 'gadgets.json.stringify(rpc), relay'
>> the relay is 
http://app.example.com/gadgets/files/container/rpc_relay.html
>> the rpc string is somehow
>> 
{"s":"requestSendMessage","f":"remote_iframe_5","c":2,"a":[[1747383],"fields_":{"body":"blabla,
>> You ....
>> it seems the "targetWin.postMessage(gadgets.json.stringify(rpc), 
relay);"
>> does NOT send any request to the server. (I check the access_log of
>> app.example.com and opensocial.example.com, but I don't see the rpc
>> request and I don't see the rpc_relay.html neither).
>>
>> I tried FF3 and IE8, both is not working, anyone got any hint? the 
shindig
>> config issue? or the app js issue? or what?
>>
>> Thanks.
>>
>> --
>> Fayland Lam // http://www.fayland.org/
>>
>>
>> 
>
> 


-- 
Fayland Lam // http://www.fayland.org/


Reply via email to