immersive-web / webvr-polyfill

Use WebVR today, without requiring a special browser build.

Home Page:http://immersive-web.github.io/webvr-polyfill/examples/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pose sensor on Android 9 in webview stopped to work

pioncz opened this issue · comments

commented
Description:

display.getFrameData started to fill frameData with default values [0,0,0,1]
As i run this script in other android devices it works just fine.
In android 9 it works only when i uncomment useDeviceMotion() lines.

Run below code in webview (with polyfill script):

var polyfill = new WebVRPolyfill();
var display = null;
var frameData = new VRFrameData();
navigator.getVRDisplays().then((displays) => {
  if (displays.length) {
    display = displays[0];

    // if (display.poseSensor && display.poseSensor.useDeviceMotion) {
    //   display.poseSensor_.useDeviceMotion();
    // }

    window.setInterval(() => {
      if ( display.getFrameData ) {
        display.getFrameData( frameData );
        pose = frameData.pose;
      } else if ( display.getPose ) {
        pose = display.getPose();
      }

      if ( pose.orientation !== null ) {
        console.log(pose.orientation);
      }
    }, 60);
  }
}, (e) => {
  console.error(e);
});

It looks like in webview RelativeOrientationSensor doesn't update its orientation, but when i tried to reproduce this bug without polyfill i see orientation in poseSensor.quaternion and in reading event:

var poseSensor;

try {
  poseSensor = new RelativeOrientationSensor({ frequency: 60, referenceFrame: 'device' });
  poseSensor.addEventListener('error', (e) => {
    if (e && e.error && e.error.message) {
      document.write(e.error.name);
      document.write(e.error.message);
    }
  });
  var sensorListener = function(event) {
    console.log(poseSensor.quaternion);
  };
  
  poseSensor.addEventListener('reading', sensorListener);
  poseSensor.onreading = function(e) {
    console.log(e);
  }
  Promise.all([navigator.permissions.query({ name: "accelerometer" }),
          navigator.permissions.query({ name: "gyroscope" })])
    .then(results => {
    console.log(results);
      if (results.every(result => result.state === "granted")) {
        poseSensor.start();
        window.setInterval(() => {
          console.log(poseSensor.quaternion);
        }, 60);
      } else {
        console.log("No permissions to use RelativeOrientationSensor.");
      }
});
} catch(e) {
  document.write(e);
}
Additional Information:
  • webvr-polyfill version:
    0.10.4
  • Browser name/version/release channel:
    WebView with Chrome 74
  • Operating System:
    Android 9

Can you try using 0.10.10? there's been some changes in Chromium that the polyfill needed to address around the sensors and 0.10.4 is rather out of date and missing some of those fixes

commented

Just testes on 0.10.10 with same results.
To workaraound this issue we emit events called 'devicemotion2' from android app and
added support for 'devicemotion2' events in webvr-polyfill. We had other issues with chromium previously and this sollution worked for us.
I can make pr if you want, but there should be better name for this event.