npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cap-sensing-kit

v1.0.1

Published

Capacitor Sensing Kit

Downloads

3

Readme

npm version

Installation

Install the package via npm

npm install --save cap-sensing-kit

In your capacitor project, make sure to register the Android plugin in in the projects MainActivity as follows

import com.sensingkit.plugin.SensingKit;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      add(SensingKit.class);
    }});
  }
}

In your application, use the plugin as described below


import "cap-sensing-kit";
import {Plugins} from "@capacitor/core";

const {SensingKit} = Plugins;

//...do something with the plugin

If you just want to use the web implementation, you can import the plugin directly

import {SensingKit} from "cap-sensing-kit";
//...do something with the plugin

Availability

The web implementation of this plugin uses the Generic Sensor API which is not implemented in many Browsers by now.

| SensorType | Web | Android | iOS | Description | | --- | :---: | :---: | :---: | --- | | AMBIENT_LIGHT | [x] * | [x] | | Measures the ambient light level (illumination) in lx.| | AMBIENT_PRESSURE | | [x] | | Measures the ambient air pressure in hPa or mbar. | | AMBIENT_TEMPERATURE | | [x] | | Measures the ambient room temperature in degrees Celsius (°C). | | RELATIVE_HUMIDITY | | [x] | | Measures the relative ambient humidity in percent (%).| | ACCELEROMETER | [x] * | [x] | | Measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), including the force of gravity. | | GRAVITY | | [x] | | Measures the force of gravity in m/s2 that is applied to a device on all three physical axes (x, y, z).| | GYROSCOPE | [x] * | [x] | | Measures a device's rate of rotation in rad/s around each of the three physical axes (x, y, and z).| | LINEAR_ACCELERATION | [x] * | [x] | | Measures the acceleration force in m/s2 that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity.| | ROTATION_VECTOR | | [x] | | Measures the orientation of a device by providing the three elements of the device's rotation vector.| | GAME_ROTATION_VECTOR | | [x] | | | | GEOMAGNETIC_ROTATION_VECTOR | | [x] | | | | MAGENTIC_FIELD | [x] * | [x] | | Measures the ambient geomagnetic field for all three physical axes (x, y, z) in μT.| | PROXIMITY | | [x] | | Measures the proximity of an object in cm relative to the view screen of a device.| | ABSOLUTE_ORIENTATION | [x] * | | | | | RELATIVE_ORIENTATION | [x] * | | | |

* requires chrome://flags/#enable-generic-sensor-extra-classes to be enabled

Usage

Below, an example of working with a mobile device's ambient light sensor

import "cap-sensing-kit";
import {Plugins} from "@capacitor/core";
import {SensorType, sensorChangedEventName} from "cap-sensing-kit";
const {SensingKit} = Plugins;

const name = SensorType.AMBIENT_LIGHT; 

const {isAvailable} = await SensingKit.isSensorAvailable({name});
const {isActive} = await SensingKit.isSensorActive({name});

if(isAvailable && !isActive){
    await SensingKit.start({name});
}

const event = sensorChangedEventName(name);
const listener = SensingKit.addListener(event, (data) => {

    //Do something ... for example:
    const {value} = data;
    console.log(`Ambient light level changed...illuminance is ${value} lx`);
};

//...

await SensingKit.stop({name});
listener.remove()

API Documentation

Following, an overview over the available SensorKit methods

isSensorAvailable

isSensorAvailable(options: {name: string}): Promise<{isAvailable: boolean}> Checks whether a specific sensor is available on the device. Note: Since it is not possible to check whether a specific sensor is available or not within a web browser without trying to start it, the web implementation simply checks if the corresponding sensor API (e.g. AmbientLightSensor API) is available.

isSensorActive

isSensorActive(options: {name: string}): Promise<{isActive: boolean}> Checks whether a specific sensor was already started through the plugin.

start

start(options: {name: string, frequency?: number}): Promise<void> Starts the propagation of sensor events for the specified sensor. With the frequency property, the sampling rate (in Hz) of the sensor can be specified (if supported). frequency defaults to the maximum sampling rate (specified by browser specific Sensor API implementation) for a sensor, in the web implementation. For Android it defaults to SENSOR_DELAY_NORMAL (5 Hz). Note: Frequency is only a suggested value

stop

stop(options: {name: string}): Promise<void> Stops the propagation of sensor events for the specified sensor.