@rtorcato/browser-common / motion
motion
Functions
isDeviceMotionAvailable()
isDeviceMotionAvailable():
boolean
Defined in: motion/index.ts:10
Checks if the DeviceMotion API is available in the browser.
Returns
boolean
True if DeviceMotionEvent is supported, false otherwise.
Example
import { isDeviceMotionAvailable } from '@rtorcato/browser-common/motion'
if (isDeviceMotionAvailable()) listen()
onDeviceMotion()
onDeviceMotion(
callback): () =>void
Defined in: motion/index.ts:25
Adds a listener for device motion events.
Parameters
callback
(event) => void
The callback to run on device motion.
Returns
A function to remove the event listener.
() => void
Example
import { onDeviceMotion } from '@rtorcato/browser-common/motion'
const off = onDeviceMotion((e) => console.log(e.acceleration))
off()
isGenericSensorApiAvailable()
isGenericSensorApiAvailable():
boolean
Defined in: motion/index.ts:40
Checks if the browser supports the Generic Sensor API for motion sensors.
Returns
boolean
True if supported, false otherwise.
Example
import { isGenericSensorApiAvailable } from '@rtorcato/browser-common/motion'
if (isGenericSensorApiAvailable()) startSensor()
requestMotionPermission()
requestMotionPermission():
Promise<"granted"|"denied"|"default">
Defined in: motion/index.ts:57
Requests permission for motion and orientation events (iOS 13+).
Returns
Promise<"granted" | "denied" | "default">
The permission state.
Remarks
Required on iOS Safari; must be called from a user gesture.
Example
import { requestMotionPermission } from '@rtorcato/browser-common/motion'
button.addEventListener('click', async () => {
if ((await requestMotionPermission()) === 'granted') listen()
})