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] Switching microphone device from system does not work on the first instance #256

Open
7 of 8 tasks
varunm0503 opened this issue Apr 24, 2024 · 0 comments
Open
7 of 8 tasks
Labels
bug Something isn't working

Comments

@varunm0503
Copy link

varunm0503 commented Apr 24, 2024

  • 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:

Adding a reference from code in audioHelper.ts file

if (deviceChanged || lostDeviceIds.length) {
            // Force a new gUM in case the underlying tracks of the active stream have changed. One
            //   reason this might happen is when `default` is selected and set to a USB device,
            //   then that device is unplugged or plugged back in. We can't check for the 'ended'
            //   event or readyState because it is asynchronous and may take upwards of 5 seconds,
            //   in my testing. (rrowland)
            if (this.inputDevice !== null && this.inputDevice.deviceId === 'default') {
                this._log.warn("Calling getUserMedia after device change to ensure that the           tracks of the active device (default) have not gone stale.");
                this._setInputDevice(this.inputDevice.deviceId, true);
            }
            this._log.debug('#deviceChange', lostActiveDevices);
            this.emit('deviceChange', lostActiveDevices);
        }

Suggested code fix

if (deviceChanged || lostDeviceIds.length) {
            // Force a new gUM in case the underlying tracks of the active stream have changed. One
            //   reason this might happen is when `default` is selected and set to a USB device,
            //   then that device is unplugged or plugged back in. We can't check for the 'ended'
            //   event or readyState because it is asynchronous and may take upwards of 5 seconds,
            //   in my testing. (rrowland)
            if ((this.inputDevice === null && this.availableInputDevices.get("default")) || (this.inputDevice && this.inputDevice.deviceId === 'default')) {
                this._log.warn("Calling getUserMedia after device change to ensure that the           tracks of the active device (default) have not gone stale.");
                this._setInputDevice('default', true);
            }
            this._log.debug('#deviceChange', lostActiveDevices);
            this.emit('deviceChange', lostActiveDevices);
        }

Expected behavior:

When we are switching microphone device from our system (i.e changing my default device from one inbuilt device to bluetooth device), the voice call should start taking input stream from new default device.

Actual behavior:
When we are switching microphone device from our system (i.e changing my default device from one inbuilt device to bluetooth device), input stream becomes stale and voice cannot be heard by other party on call.

Attached a code update that may be needed to fix this issue. The issue does not happen once setDevices is manually called in twilio sdk api. Once we call setDevices, inputDevice is set and from then on switching microphone device from system is no longer an issue.

this.inputDevice === null || (this.inputDevice !== null && this.inputDevice.deviceId === 'default'

Software versions:

  • Browser(s): Chrome v124.0.6367.62
  • Operating System: MacOS Monterey
  • twilio.js: 2.10.1
  • Third-party libraries (e.g., Angular, React, etc.): React
@varunm0503 varunm0503 added the bug Something isn't working label Apr 24, 2024
@varunm0503 varunm0503 changed the title [BUG] [BUG] Switching microphone device from system does not work on the first instance Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant