Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theopenwebjp/js-sensor
JavaScript sensor library for native input sensors.
https://github.com/theopenwebjp/js-sensor
accelerometer geolocation gyrosensor html5 javascript js sensor
Last synced: about 23 hours ago
JSON representation
JavaScript sensor library for native input sensors.
- Host: GitHub
- URL: https://github.com/theopenwebjp/js-sensor
- Owner: theopenwebjp
- License: mit
- Created: 2017-12-08T12:44:08.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-23T07:33:33.000Z (over 1 year ago)
- Last Synced: 2024-04-25T10:20:33.069Z (7 months ago)
- Topics: accelerometer, geolocation, gyrosensor, html5, javascript, js, sensor
- Language: JavaScript
- Homepage: https://theopenweb.info/app/js-sensor/example/index.html
- Size: 1.05 MB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JS Sensor
Sensor watcher of JavaScript sensor events.
This module is designed to have only basic functionality.
Any more complex functionality should be achieved through extending this module.## Environment
Should work and be extensible using any new JavaScript environment(node, browser).
Default event listeners provided via browser-sensor-watcher.
Possible to use own via extension.Currently uses Common JS due to not being limited to use on browser.
Can load via Common JS require OR by loading pre-built /dist/bundle.js.## Build
If building from source is desired OR the latest dist is not provided, building can by done via `npm run build-all`
## Installation
1. Install node(including npm)
2. "npm install" in base directory## Usage
The full api can be checked from the documentation. See "Documentation" below.
Basic usage can be seen below:
```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`
## Reports
* Built when running tests.
* Eslint## Documentation
* Esdoc(./docs/)