aws / amazon-chime-sdk-js

A JavaScript client library for integrating multi-party communications powered by the Amazon Chime service.
Apache License 2.0
713 stars 476 forks source link

Audio device permission prompt not displayed when the only device is audio-only #2694

Open TimMisiak opened 1 year ago

TimMisiak commented 1 year ago

What happened and what did you expect to happen?

We have some code that is starting a chime meeting session.

  const deviceController = new ChimeSDK.DefaultDeviceController(logger);
  const configuration = new ChimeSDK.MeetingSessionConfiguration(meeting, attendee);
  meetingSession = new ChimeSDK.DefaultMeetingSession(configuration, logger, deviceController);
  audioDevices = await meetingSession.audioVideo.listAudioInputDevices();
  videoDevices = await meetingSession.audioVideo.listVideoInputDevices();

The line of code listing audio devices will usually be when the permission dialog asking the user if the audio/video device can be used. We found that on one machine, if the video camera is disconnected and only a headset is connected, the permission dialog is never displayed. Stepping through the code, we found where the two cases diverge. When enumerating devices in DefaultDeviceController.updateDeviceInfoCacheFromBrowser(), the device labels are not found and hasDeviceLabels is false, so the code calls deviceLabelTrigger().

            for (const device of devices) {
                if (!device.label) {
                    hasDeviceLabels = false;
                    break;
                }
            }
            if (!hasDeviceLabels) {
                try {
                    this.logger.info('attempting to trigger media device labels since they are hidden');
                    const triggerStream = yield this.deviceLabelTrigger();

In the case where a video camera is connected, this line of code will result in the permissions dialog to show up:

        this.deviceLabelTrigger = () => {
            return navigator.mediaDevices.getUserMedia({ audio: true, video: true });
        };

When no video camera is connected, this line does nothing. We found that by using video: false, the permissions dialog will be displayed again.

Have you reviewed our existing documentation?

Reproduction steps

We're only able to get this to reproduce on one machine, which has a Poly BT600 headset. The problem reproduces on both firefox and chrome.

Amazon Chime SDK for JavaScript version

3.13.0

What browsers are you seeing the problem on?

chrome, firefox

Browser version

Chrome 114

Meeting and Attendee ID Information.

No response

Browser console logs

[undefined] ChimeMeetingLogs - DefaultDeviceController video dimension 960 x 540
[undefined] ChimeMeetingLogs - Supported Constraints in this browser {"aspectRatio":true,"autoGainControl":true,"brightness":true,"channelCount":true,"colorTemperature":true,"contrast":true,"deviceId":true,"displaySurface":true,"echoCancellation":true,"exposureCompensation":true,"exposureMode":true,"exposureTime":true,"facingMode":true,"focusDistance":true,"focusMode":true,"frameRate":true,"groupId":true,"height":true,"iso":true,"latency":true,"noiseSuppression":true,"pan":true,"pointsOfInterest":true,"resizeMode":true,"sampleRate":true,"sampleSize":true,"saturation":true,"sharpness":true,"suppressLocalAudioPlayback":true,"tilt":true,"torch":true,"whiteBalanceMode":true,"width":true,"zoom":true}
[undefined] ChimeMeetingLogs - browser is chrome 114 (114.0.0)
[undefined] ChimeMeetingLogs - Event ingestion URL is present in the configuration
[undefined] ChimeMeetingLogs - Event reporting started
[undefined] ChimeMeetingLogs - adding meeting observer
[undefined] ChimeMeetingLogs - attempting to trigger media device labels since they are hidden
[undefined] ChimeMeetingLogs - unable to get media device labels
[undefined] ChimeMeetingLogs - API/DefaultDeviceController/listAudioInputDevices false -> [{"deviceId":"","kind":"audioinput","label":"","groupId":""}]
[undefined] ChimeMeetingLogs - API/DefaultAudioVideoFacade/2ceda7a0-587f-4581-b182-9e8fc7e96404/7f8cecb3-f353-8c5c-35d6-7ea1a1952066/listAudioInputDevices false -> [{"deviceId":"","kind":"audioinput","label":"","groupId":""}]
TimMisiak commented 1 year ago

We were able to work around this issue with the following code, so this feels like something which should be fixed in the chime layer.

  meetingSession.audioVideo.setDeviceLabelTrigger(
    async () => {
      var stream;
      try {
        stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
      } catch { }
      if (stream == null) {
        stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
      }
      return stream;
    }
  );