twilio / twilio-video.js

Twilio’s Programmable Video JavaScript SDK
https://www.twilio.com/docs/video/javascript
Other
571 stars 217 forks source link

Default audio input track doesn't get replaced #1038

Closed ivansivaklepsi closed 4 years ago

ivansivaklepsi commented 4 years ago

Hello,

I encountered this problem when trying to switch audio input track using CreateLocalTrackOptions -> deviceId set to default when default track's name changes due to user changing it in Sound in System Preferences or by disconnecting their headphones etc.

Performing device changes using the code below with a specific deviceId, rather than just "default", the devices change just fine, however, when user has "default" device selected, performs the one of the changes mentioned above, the code detects it, calls replaceAudioTrack with "default" for the deviceId, tracks stop as expected, but the newly attached track is still the same and not the new one from the System.

Also worth mentioning is that when you enter the website with default input device being e.g. Headphones Mic

  1. Switching manually in the app to let's say Built-in Mic
  2. Changing default in System Preferences to be Built-in Mic instead
  3. Switching manually in the app to default, which is now labelled correctly as Built-in Mic
  4. The flow seems okay, but you still end up with the default device which was when you entered the app, so that would be the Headphones Mic, instead of Built-in Mic, which user changed to.

The steps above work as expected without any complications in e.g. Google Meet

Code to reproduce the issue:

  const replaceAudioTrack: ReplaceAudioTrack = React.useCallback(
    async (newDeviceId?: string) => {
      localParticipant?.audioTracks.forEach(trackPublication => {
        trackPublication.track.stop()
        localParticipant.unpublishTrack(trackPublication.track)
        localParticipant.emit('trackUnpublished', trackPublication)
      })
      const newTrack = await getLocalAudioTrack(newDeviceId)
      localParticipant?.publishTrack(newTrack)
      setDeviceId(newDeviceId)
      return newTrack
    },
    [localParticipant, getLocalAudioTrack],
  )
const getLocalAudioTrack: GetLocalAudioTrackFn = async (deviceId?: string) => {
  const options: CreateLocalTrackOptions = {}

  if (deviceId) {
    options.deviceId = { exact: deviceId }
  }

  await ensureMediaPermissions()
  const newTrack = await Video.createLocalAudioTrack(options)
  setTrack(newTrack)
  return newTrack
}

Expected behavior:

Changing default audio input device in the System or anyhow on background should be registered by Twilio when I want to stop the current default and publish new default track.

Actual behavior:

Described with steps above

Software versions:

manjeshbhargav commented 4 years ago

Hi @ivansivaklepsi ,

Thanks for writing in with this issue. I think Chrome needs to be restarted for the default device change to take effect. The SDK does not have any control over it. I will close this issue, but we can continue the conversation here if you need more clarification.

Thanks,

Manjesh Malavalli JSDK Team

evgsklyarov94 commented 3 years ago

Hi, @manjeshbhargav I have a similar problem

User case The user connects to the video chat from their laptop audio and microphone work correctly

after that, the user connects the airpods audio and microphone work correctly

after the user disables the airpods , the result is that the user loses the sound and microphone.

How can I change audio tracks? I'm trying to do something similar to what ivansivaklepsi wrote above