Lorti / vue-dictaphone

🎙️ Vue.js dictaphone component to record audio from the user
MIT License
24 stars 8 forks source link

Is it possible to ask user permission after click on button? #4

Closed heliomsolivas closed 5 years ago

heliomsolivas commented 5 years ago

I need to ask for user permission after some action happens on the page, this is possible? Actually it's firing when the component is mounted.

Lorti commented 5 years ago

Hmm … you could circumvent this by using v-if if I am correct.

How or when would you like to ask for permission? After setting a special prop? Or by setting a ref and calling one of the instance methods?

I will try to add this as soon as possible, but feel free to open up a pull request.

rhsobr commented 5 years ago

As @Lorti mentioned, you can use a v-if before instantiate the vue-dictaphone component. I used the below snippet to control. So I just let pass through v-if when user clicks on an icon or when site is already allowed to use mic.

navigator.permissions.query({ name: 'microphone' }).then(function(result) {
      if (result.state == 'granted') {

      } else if (result.state == 'prompt') {

      } else if (result.state == 'denied') {

      }
    })