Skip to content
This repository has been archived by the owner on Dec 6, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved device motion handling to polyfill
  • Loading branch information
borismus committed Dec 9, 2016
1 parent 8497a1f commit 465ee9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
12 changes: 0 additions & 12 deletions src/api/iframe-message-sender.js
Expand Up @@ -77,16 +77,4 @@ IFrameMessageSender.prototype.isIOS_ = function() {
return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
};

// From http://stackoverflow.com/questions/12381334/foolproof-way-to-detect-if-iframe-is-cross-domain.
IFrameMessageSender.prototype.isCrossDomainIframe_ = function(iframe) {
var html = null;
try {
var doc = iframe.contentDocument || iframe.contentWindow.document;
html = doc.body.innerHTML;
} catch (err) {
}

return (html === null);
};

module.exports = IFrameMessageSender;
28 changes: 6 additions & 22 deletions src/embed/iframe-message-receiver.js
Expand Up @@ -25,8 +25,12 @@ var Util = require('../util');
* Adding hotspots.
* Sending messages back to the containing iframe when hotspot is clicked
* Sending analytics events to containing iframe.
* Receiving DeviceMotion events and resynthesizing them in this iframe
* (workaround for https://bugs.webkit.org/show_bug.cgi?id=150072).
*
* Note: this script used to also respond to synthetic devicemotion events, but
* no longer does so. This is because as of iOS 9.2, Safari disallows listening
* for devicemotion events within cross-device iframes. To work around this, the
* webvr-polyfill responds to the postMessage event containing devicemotion
* information (sent by the iframe-message-sender in the VR View API).
*/
function IFrameMessageReceiver() {
window.addEventListener('message', this.onMessage_.bind(this), false);
Expand All @@ -43,16 +47,11 @@ IFrameMessageReceiver.prototype.onMessage_ = function(event) {
var data = message.data;

switch (type) {
case Message.DEVICE_MOTION:
// Synthesize a DeviceMotion event.
this.synthesizeDeviceMotionEvent_(message.deviceMotionEvent);
break;
case Message.SET_CONTENT:
case Message.SET_VOLUME:
case Message.ADD_HOTSPOT:
case Message.PLAY:
case Message.PAUSE:
// TODO(smus): Emit the event
this.emit(type, data);
break;
default:
Expand All @@ -62,19 +61,4 @@ IFrameMessageReceiver.prototype.onMessage_ = function(event) {
}
};

IFrameMessageReceiver.prototype.synthesizeDeviceMotionEvent_ = function(eventData) {
var type = 'devicemotion-iframe';
var canBubble = false;
var cancelable = false;

var dme = document.createEvent('DeviceMotionEvent');
dme.initDeviceMotionEvent(type, canBubble, cancelable,
eventData.acceleration,
eventData.accelerationIncludingGravity,
eventData.rotationRate,
eventData.interval);

window.dispatchEvent(dme);
};

module.exports = IFrameMessageReceiver;

0 comments on commit 465ee9f

Please sign in to comment.