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

Add way of getting current orientation #11

Closed
marcoscaceres opened this issue Sep 4, 2014 · 6 comments
Closed

Add way of getting current orientation #11

marcoscaceres opened this issue Sep 4, 2014 · 6 comments
Milestone

Comments

@marcoscaceres
Copy link
Member

The API should provide some way to get request the current orientation without needing to subscribe to events.

@richtr
Copy link
Member

richtr commented Sep 4, 2014

Agreed and we are also currently working on a native Promise-based API for this.

In the mean time, you could use a library like Full Tilt JS https://github.com/richtr/Full-Tilt-JS. It simply dumps the last DeviceOrientation event object to a variable until you call a sync API function in e.g. requestAnimationFrame. At that point it performs more complex processing of the last known device orientation data.

Full Tilt JS performance benchmarking is available at http://jsperf.com/screen-adjusted-deviceorientation-benchmark.

@marcoscaceres
Copy link
Member Author

Where is the work happening and who is involved? I tried looking for branches and PRs but couldn't find any.

@richtr
Copy link
Member

richtr commented Sep 5, 2014

Our draft Promises proposal has now been published on the W3C Device APIs mailing list @ http://lists.w3.org/Archives/Public/public-device-apis/2014Sep/0024.html.

@hexalys
Copy link

hexalys commented Jun 2, 2015

It's definitely lacking. Alternatively or in addition, any thoughts on normalizing the spec for all browsers to star firing Device Orientation on the same time frame at the 'interactive' state of the document, so it can be used at or before DOMContentLoaded?

My related SO post as I was trying to detect this: http://stackoverflow.com/a/30585637/1647538

@gmandyam gmandyam added this to the VNext milestone Jun 21, 2016
@gmandyam
Copy link

Added label of VNext. This can be considered as part of Generic Sensor API work.

@reillyeon
Copy link
Member

I propose closing this issue as "won't fix". A Promise-returning API can easily be polyfilled like so,

function getCurrentOrientation() {
  return new Promise((resolve) => {
    document.addEventListener('deviceorientation', (event) => {
      resolve(event);
    }, {once: true});
  });
}

The Observable proposal would also extend all EventTargets so that you could write:

let event = (await document.on('deviceorientation').take(1).toArray())[0];

@anssiko anssiko closed this as not planned Won't fix, can't repro, duplicate, stale Feb 25, 2024
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

6 participants