# site-permissions-manager

> This is a library to easily manage the browser permissions in a front-end JS project.

Latest version **0.2.1** (published 2021-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install site-permissions-manager
pnpm add site-permissions-manager
yarn add site-permissions-manager
bun add site-permissions-manager
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2021-01-14 |
| First published | 2021-01-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ritesh Tailor |
| Maintainers | ritesht |
| Keywords | browser, permissions |

## Links

- npm: https://www.npmjs.com/package/site-permissions-manager
- Repository: https://github.com/Ritesht95/site-permissions-manager
- Homepage: https://github.com/Ritesht95/site-permissions-manager#readme
- Issues: https://github.com/Ritesht95/site-permissions-manager/issues
- npm.io page: https://npm.io/package/site-permissions-manager

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2021-01-14
- 0.2.0 — 2021-01-05
- 0.1.0 — 2021-01-02

## README

# site-permissions-manager

This is a library which provides a wrapper to manage all the types of site permissions using JavaScript.

## How to install

```
npm i site-permissions-manager

import { permissions } from "site-permissions-manager";
```

## Location Permission Functions

#### promptGeoLocationPermission
It is to prompt user for location permission if it is not already determined and invoke success or error callback based on user action.

##### Usage
```
permissions.promptGeoLocationPermission((result) => {
	//TODO: User grants location permission.
}, (error) => {
	//TODO: User denies location permission or location service is not available.
});
```

#### asyncPromptGeoLocationPermission

It is to prompt user for location permission if it is not already determined and returns promise.

##### Usage

```
try {
	const result = await permissions.asyncPromptGeoLocationPermission();
	//TODO: Location permission granted
} catch (error) {
	//TODO: Location permission denied
}
```

or

```
permissions.asyncPromptGeoLocationPermission()
.then((result) => {
	//TODO: Location permission granted
}).catch((error) => {
	//TODO: Location permission denied
});
```

#### getGeoLocationPermission

It is to get location permission state without prompting user for location access and return result via callback.

##### Usage

```
permissions.getGeoLocationPermission((locationState) => {
	// TODO: Action based on location state
},(error) => {
	// TODO: Handling action on error
});
```

#### startLocationTracking

This function is to continuously track user location as it changes/navigates. It will return `locationTrackingId` which will later be used to stop tracking location.
- Position object will be return with `successCallback` or any error will be return with `errorCallback`.
- PostionOptions can be set by passing `positionOptions` parameter. (i.e. `{enableHighAccuracy: true, timeout: 10000, maximumAge: 5000}`)
	- `enableHighAccuracy`: If true and if the device is able to provide a more accurate position. Default value is true.
	- `timeout`: Value representing the maximum length of time (in milliseconds) the device is allowed to take in order to return a position. Default value is infinity.
	- `maximumAge`: Value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. Default value is 0.
- A threshold can also be set by passing the miliseconds for `thresholdTime` parameter.
##### Usage

```
const locationTrackingId = permissions.startLocationTracking({
      successCallback: (position) => {
        // TODO: Task on successfully receiving the position 
      },
      errorCallback: (err) => {
        // TODO: Task on error
      },
      positionOptions: {enableHighAccuracy: true, timeout: 10000, maximumAge: 5000},
      thresholdTime: 3000,
    });
```
#### stopLocationTracking

This function is to stop tracking user location which was started before by passing `locationTrackingId`.

##### Usage

```
permissions.stopLocationTracking(locationTrackingId);
```

## Media Permission Functions

#### getCameraMicroPhonePermission

It is to prompt user for camera and microphone permissions. This function returns the promise which resolves as an object of stream if permission is granted.
This function also accept the min/max width/height for video stream.

##### Usage

```
/* Simply getting both video and audio permissions and stream */
const stream = await permissions.getCameraMicroPhonePermission({
	video: true,
      	audio: true,
});
```

or

```
/* Passing the min/max width/height for video stream and no audio */
const stream = await permissions.getCameraMicroPhonePermission({
	video: true,
	minWidth: 480,
	maxWidth: 1920,
	minHeight: 320,
	maxHeight: 1080,
      	audio: false,
});
```

or

```
/* Simply getting just audio permission and stream */
const stream = await permissions.getCameraMicroPhonePermission({
	video: false,
      	audio: true,
});
```

#### setAudioStreamOff

It is to turn off only audio stream which was previously started using 'getCameraMicroPhonePermission' function.

##### Usage

```
permissions.setAudioStreamOff(stream);
```

#### setVideoStreamOff

It is to turn off only video stream which was previously started using 'getCameraMicroPhonePermission' function.

##### Usage

```
permissions.setVideoStreamOff(stream);
```

#### setAudioVideoStreamsOff

It is to turn off both video and audio streams which were previously started using 'getCameraMicroPhonePermission' function.

##### Usage

```
permissions.setAudioVideoStreamsOff(stream);
```

---
_Source: https://npm.io/package/site-permissions-manager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
