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] device.destroy throws in Chrome extension workers #309

Open
4 tasks done
andr-smrnv opened this issue Jan 24, 2025 · 1 comment
Open
4 tasks done

[BUG] device.destroy throws in Chrome extension workers #309

andr-smrnv opened this issue Jan 24, 2025 · 1 comment
Labels
bug Something isn't working jira added

Comments

@andr-smrnv
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:
Use device normally somewhere in the context of a browser extension worker (v3)

import { Device } from '@twilio/voice-sdk'

const device = new Device(token)
await device.register()
device.on('unregistered', () => {
  device.destroy() // throws
})

// we unregister when the user logs out
await device.unregister()

Expected behavior:

Device unregisters normally and closes its WS connection. When creating a new device in the same runtime context, everything works correctly and we're able to receive inbound calls.

Actual behavior:

device.destroy() throws, and even if we create a new device it's no longer capable of receiving inbound calls.

Image

More specifically, this place:

if (!this._mediaDevices || !this._enumerateDevices) {
throw new NotSupportedError('Enumeration is not supported');
}

This kinda makes sense, because we grab _mediaDevices from navigator.mediaDevice, which is undefined in the worker, but it probably doesn't make sense to throw it then.

I had to patch it on my end, just by replacing the error with the return statement, but I'm not sure it's the best solution.


This is the error that happens after we create a completely new device and try to receive an inbound call:

Image

I suspect this happens because the first exception interrupts the cleanup procedure and some stale references remain.
Software versions:

@andr-smrnv andr-smrnv added the bug Something isn't working label Jan 24, 2025
@kpchoy
Copy link
Collaborator

kpchoy commented Jan 27, 2025

@andr-smrnv thanks for submitting. I'll submit an internal ticket to track this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jira added
Projects
None yet
Development

No branches or pull requests

2 participants