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

Pose sensor on Android 9 in webview stopped to work #349

Open
pioncz opened this issue Jun 5, 2019 · 2 comments
Open

Pose sensor on Android 9 in webview stopped to work #349

pioncz opened this issue Jun 5, 2019 · 2 comments

Comments

@pioncz
Copy link

pioncz commented Jun 5, 2019

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
@jsantell
Copy link
Contributor

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

@pioncz
Copy link
Author

pioncz commented Jul 10, 2019

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.

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

2 participants