Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support I-Frames through PostMessage #173

Closed
ngokevin opened this issue Nov 15, 2016 · 4 comments
Closed

Support I-Frames through PostMessage #173

ngokevin opened this issue Nov 15, 2016 · 4 comments

Comments

@ngokevin
Copy link
Contributor

Safari has a rule that disallows an I-Frame to access deviceorientation events to get rotation data. On aframe.io, we've had to limit the example scenes we show on mobile to scenes hosted on the same domain.

We can work around this by using postMessage. The parent window has a small script that continuously emits a postMessage with device orientation data. Then we have webvr-polyfill listen to the postMessage and send that data through the polyfill to support the I-Frame use case.

@borismus
Copy link
Contributor

Are you suggesting to add a listener for these synthetic deviceorientation
events? If so I think that's reasonable. Open to PRs.

On Mon, Nov 14, 2016 at 5:24 PM Kevin Ngo notifications@github.com wrote:

Safari has a rule that disallows an I-Frame to access deviceorientation
events to get rotation data. On aframe.io, we've had to limit the example
scenes we show on mobile to scenes hosted on the same domain.

We can work around this by using postMessage. The parent window has a
small script that continuously emits a postMessage with device orientation
data. Then we have webvr-polyfill listen to the postMessage and send that
data through the polyfill to support the I-Frame use case.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#173, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AAQ8gKXh5s2YzKR7E1EjORMMsTQN22-Mks5q-Qm1gaJpZM4KyBCI
.

@htmlr
Copy link

htmlr commented Mar 13, 2017

@ngokevin can you share the code snippet that does this device orientation update via postMessage ?
I was considering using iframes as a way to load scenes asynchronously via the frame into a page

@ngokevin
Copy link
Contributor Author

I don't have code snippets, but the pseudocode is:

window.top script:

window.addEventListener('devicemotion', function (evt) {
  iframes.forEach(function (iframe) {
    iframe.contentWindow.postMessage({name: 'devicemotionpolyfillupdate', acceleration: evt.acceleration, ...});
  });
});

Polyfill / I-Frame content script:

window.addEventListener('message', function (evt) {
  if (evt.data.name !== 'devicemotionpolyfillupdate') { return; }
  // Tell polyfill to update camera using device motion data.
});

cvan referenced this issue in immersive-web/webxr Oct 3, 2017
Described how magic window and mirroring work with a canvas `outputContext`. Follows the proposal in #224.
@jsantell
Copy link
Contributor

Added an example usage of iframes in the cardboard-vr-display README, as well fixed the issue with working with cross-origin iframes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants