Home Reference Source Test

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.

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:

    const jsSensor = new require('js-sensor');
    
    //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

  3. watchPosition
  4. getUserMedia
  5. deviceOrientation
  6. deviceLight
  7. deviceProximity
  8. deviceMotion
  9. test

    Tests

    Run npm run test

    Reports

  10. Built when running tests.
  11. Eslint

    Documentation

  12. Esdoc(./docs/)