@untemps/user-permissions-utils

1.1.21 • Public • Published

@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

Package Sidebar

Install

npm i @untemps/user-permissions-utils

Weekly Downloads

42

Version

1.1.21

License

MIT

Unpacked Size

32.3 kB

Total Files

6

Last publish

Collaborators

  • untemps