@untemps/user-permissions-utils

Collection of utility functions to manage user permissions


Keywords
utils, permissions, javascript
License
MIT
Install
npm install @untemps/user-permissions-utils@1.1.7

Documentation

@untemps/user-permissions-utils

Collection of utility functions to manage user permissions.

npm GitHub Workflow Status Codecov

Installation

yarn add @untemps/user-permissions-utils

Utils

getPermission:

Returns a promise resolved when the permission is granted

import { getPermission } from '@untemps/user-permissions-utils'

const init = async () => {
    try {
    	await getPermission('microphone')
        ...
    } catch (error) {
        console.error(error)
    }
}

getUserMediaStream:

Returns a promise resolved when the permission is granted and the stream is retrieved

import { getUserMediaStream } from '@untemps/user-permissions-utils'

const init = async () => {
    try {
    	const stream = await getUserMediaStream('microphone', { audio: true })
    	if(!!stream) {
    	    const audioContext = new AudioContext()
    	    const streamNode = audioContext.createMediaStreamSource(stream)
            ...
    	} else {
    	    console.error('Stream is not available')
    	}
    } catch (error) {
        console.error(error)
    }
}

Todos

  • Add permissions-based API:
    • clipboard
    • geolocation
    • notification
    • ...
  • Add commitlint to ensure commit logs are valid