JavaScript sensor library for native input sensors.
npm install @theopenweb/js-sensornpm run build-all
javascript
const jsSensor = new require('js-sensor');
// OR Load via script element:
// Get sensor list
console.log('names:' jsSensor.getMappedSensorNames());
// Update/extend
jsSensor.updateSensorListeners((sensorListenerMap)=>{
sensorListenerMap['myListener'] = {
start: (options)=>{
const data = '...HANDLE HERE';
options.events.data(data);
},
stop: ()=>{
// STOP
},
check: ()=>{
// CHECK FOR AVAILABILITY
return true;
}
};
return sensorListenerMap;
});
// Get
jsSensor.get('deviceMotion')
.then((data)=>{
console.log('get', data);
});
// Watch
jsSensor.watch('deviceOrientation',
{
events: {
data: (data)=>{
console.log('watch', data);
}
}
});
// Stop
jsSensor.stop('deviceOrientation);
// WatchAll
jsSensor.watchAll();
// ...wait a while
// StopAll
jsSensor.stopAll()
`
Events
* watchPosition
* getUserMedia
* deviceOrientation
* deviceLight
* deviceProximity
* deviceMotion
* test
Tests
Run npm run test`