
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@ircam/devicemotion
Advanced tools
@ircam/devicemotion
Minimal wrapper around the
devicemotion
API (cf. https://www.w3.org/TR/orientation-event/#devicemotion to normalize API, axis and units accross browsers.
Warning: Be aware that most, if not all, recent browsers will require your application to run through a https
connection to grant access to motion sensors.
npm install @ircam/devicemotion --save
import devicemotion from '@ircam/devicemotion';
const permission = await devicemotion.requestPermission();
if (permission === 'granted') {
devicemotion.addEventListener(e => console.log(e));
}
async devicemotion.requestPermission() -> Promise('granted' | 'refused')
Request permission to access motion sensors, this method should be called on the startup of your application, most browsers will prompt your users so that they authorize the sensors to be accessed by the application
devicemotion.addEventListener(callback: Function) -> void
The callback will be called with the data formatted as specificied in https://www.w3.org/TR/orientation-event/#devicemotion
devicemotion.addEventListener(e => {
console.log(e);
/*
e = {
interval // ms
accelerationIncludingGravity = { x, y, z } // m/s2
rotationRate = { alpha, beta, gamma } // deg/s
}
*/
});
Note: The event object is internally reused by the library, therefore it's the responsibility of the application to copy the data if needed.
devicemotion.removeEventListener(callback: Function) -> void
BSD-3-Clause
FAQs
Low level library dedicated at normalizing devicemotion across browsers
We found that @ircam/devicemotion demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.