Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error while calling setInputDevice when twilio sdk was instantiated with microphone permissions not granted #228

Closed
6 of 8 tasks
PriscilaAlves opened this issue Dec 12, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@PriscilaAlves
Copy link

  • I have verified that the issue occurs with the latest twilio.js release and is not marked as a known issue in the CHANGELOG.md.
  • I reviewed the Common Issues and open GitHub issues and verified that this report represents a potentially new issue.
  • I verified that the Quickstart application works in my environment.
  • I am not sharing any Personally Identifiable Information (PII)
    or sensitive account information (API keys, credentials, etc.) when reporting this issue.

Code to reproduce the issue:

When the app is opened and Twilio device is initialized, ensure you haven't granted microphone permissions yet.
Then, grant permissions to microphone and only after call setInputDevice

this.twilioDevice = new Device(token, options)

// grant permissions to microphone in the browser
try {
 await this.twilioDevice.audio.setInputDevice('default')
} catch (e) {
 console.log(e)
}

Expected behavior:

It should succeed to set the input device since the permissions are already granted

Actual behavior:

It fails to set input device with the error:
InvalidArgumentError: Device not found: default

Software versions:

  • Browser(s): Chrome Version 119.0.6045.199 (Official Build) (arm64)
  • Operating System: Mac OS
  • twilio.js: 2.8.0
  • Third-party libraries (e.g., Angular, React, etc.):
@PriscilaAlves PriscilaAlves added the bug Something isn't working label Dec 12, 2023
@charliesantos
Copy link
Collaborator

@PriscilaAlves thanks for reaching out! This happens because the device ID that you're passing to setInputDevice is not detected. To properly update the internal list of device IDs, you need to grant permissions before initializing the device. For example:

// ask permission
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
stream.getTracks().forEach(track => track.stop());

this.twilioDevice = new Device(token, options);
await this.twilioDevice.audio.setInputDevice('default')

@PriscilaAlves
Copy link
Author

@charliesantos Thanks for the response.
Although I know that would work as a workaround, I don't think it should be needed to instantiate the Twilio Device only after the permissions are set.

I think Twilio SDK should be listening to navigator.permissions state changes and update the availableInputDevices list when the access is granted

This is an example of the code that could live inside the audiohelper.js file:

const permissionStatus = await navigator.permissions.query({ name: 'microphone' })
if (permissionStatus.state != 'granted') {
  permissionStatus.onchange = function () {
    //update this.availableInputDevices list
 }
}

@charliesantos
Copy link
Collaborator

@PriscilaAlves thanks for the suggestion. This is a great improvement and we will consider it.

@charliesantos charliesantos added enhancement New feature or request and removed bug Something isn't working labels Dec 13, 2023
@charliesantos
Copy link
Collaborator

Closing this now. We're tracking this feature request internally. Please feel free to follow up if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants