-
-
Save findchris/1441158 to your computer and use it in GitHub Desktop.
| new easyXDM.Rpc( | |
| { | |
| swf: "http://ourstaticcontent/easyxdm.swf", | |
| remote: content_url, // the URL of iframe opened by the consumer | |
| container: container, // the iframe object | |
| onReady: function() { | |
| console.log('activityFrameLoaded: onReady'); // this gets called | |
| } | |
| }, | |
| { | |
| remote: {}, | |
| local: { | |
| test:function(){...} | |
| } | |
| }); |
I appreciate your comment. I removed the 'container' option, but that didn't change anything. Maybe you can correct me so I can better understand the terms you are using:
(1) The consumer/host page embeds my script.
(2) My script returns a URL to the consumer. This URL is to a page containing content that will be shown in a lightbox. This URL is on our company domain, which is different than the consumer/host domain embedding my script.
(3) The consumer takes the URL from my script, creates an iframe DOM element, set its src to be the URL I passed to them, and then displays the iframe to the user.
(4) Immediately after (3), the consumer tells my script that the iframe has been loaded, at which point I create an easyXDM RPC as in the above gist.
(5) The page corresponding to the URL I gave to the consumer contains the other end of the easyXDM RPC, as shown in this gist: https://gist.github.com/1441150
So, is there another piece I'm missing from this configuration? Should the content URL in the above example be different than some "endpoint" as you mention in your comment?
Thanks again for your correspondence and contributing easyXDM to the community.
I'm not sure I understand your questions - you should simply take a look at the examples that is provided (http://consumer.easyxdm.net/current/example) and work from these.
If you are making a lightbox then you simply take a regular ligtbox, remove the embedded iframed, copy the resize-iframe example (you could simplify it) and use this to target the container that would previously have held the static iframe.
I've looked further at the example, and read in detail the resize example. However, I don't see how this translates to my use case. In the resize example, the consumer opens a socket with the remote being an intermediate page, and the container being the 'embedded' div. The intermediate page opens a socket to the parent, and when communication is established, creates a new iframe with a src retrieved from the querystirng.
In my case, I don't have an intermediate page. I have a content page (the equivalent of resized_iframe_1.html in your example), whose URL is directly opened in an iframe by the consumer. So the consumer basically does the following:
iframe = document.createElement("iframe");
iframe.src = 'http://mydomain/content.html';
iframe.id = 'container';
myCode.notifyFrameLoaded(iframe); // this trigger my code to create the easyXDM Rpc as in this gist
Should this work?
Assuming I have the terms correct, my provider and content page are the same, to be loaded in an iframe by the consumer. Is this possible?
If not, one option I'm considering is to have the consumer create a div, which they'll pass to me, and I'll create the iframe myself. This might work ok, but I'd still prefer to use the above method as I won't have to change my API.
Thanks again for your correspondence.
We posted at the same time. I'll try what you've suggested, thanks.
You stress not to create the iframe, which makes sense, but as it stands right now the consumer/host will create the iframe and set it's src to what they get from my API. Could this work with the host page creating the iframe? If not, what you describe is:
(1) Host/consumer page creates a container (e.g. div)
(2) Host/consumer page let's my code know that it wants the iframe to be created inside of this div.
(3) I create an easyXDM RPC with the container set to the div from (1).
(4) This will create the iframe with the desired content in the provided container div.
Does that sound accurate?
Ok, thanks. I set up the end point like so (in my content page):
easy_xdm_proxy = new easyXDM.Rpc(
{
swf: document.location.protocol + "//static.site/js/easyxdm.swf",
onReady: function() { console.log('provider onReady'); }
},
{
remote: { start: {} },
local: { }
});
And... the pages are communicating successfully. Despite this, I am seeing the following common XDM communication error:
Unsafe JavaScript attempt to access frame with URL http://testconsumer.com:3000/# from frame with URL http://provider/page?var=1&xdm_c=default1709&xdm_e=http%3A%2F%2Ftestconsumer.com%3A3000&xdm_p=1. Domains, protocols and ports must match.
Like I said, communication seems to work, so wondering why these errors are showing up. It looks like it occurs twice in the provider when the easyXDM RPC is created, and once in the consumer when the RPC is created.
remote is the url of the endpoint, but easyXDM will open this in its own iframe.
container is not the iframe, but the domnode where you want the created iframe to appear (if you want it visible and not hidden off-screen)