aws-samples / amazon-chime-react-native-demo

A React Native demo application for Android and iOS using the Amazon Chime SDK.
MIT No Attribution
101 stars 24 forks source link

when the Bluetooth device disconnecting audioDeviceDidChangeWithFreshAudioDeviceList not triggering (only in IOS) #159

Open ashirkhanpm opened 1 year ago

ashirkhanpm commented 1 year ago
- (void)audioDeviceDidChangeWithFreshAudioDeviceList:(NSArray<MediaDevice *> * _Nonnull)freshAudioDeviceList
{
  NSLog(@"test-ActiveAudio-list freshAudioDeviceList");
  [_bridge configureActiveAudioDevice:freshAudioDeviceList];
}

Some times above function does not trigger when the Bluetooth device disconnects/turns off the Bluetooth , but it triggers when the Bluetooth device connecting

Test environment Info (please complete the following information):

ethanjanadrake commented 1 year ago

Hi @ashirkhanpm , Could you provide the steps to reproduce this issue with the RN demo?

ashirkhanpm commented 1 year ago

Hi @ethanjanadrake

I can able to reproduce this issue with the RN demo, but it happens sometimes only.

steps to reproduce:

  1. clone and set up the react native demo project.
  2. added the DeviceChangeObserver in the bridge file by referring the link #93
    • Added DeviceChangeObserver in RNDemo/MeetingObservers.h and
    • Added - (void)audioDeviceDidChangeWithFreshAudioDeviceList:(NSArray<MediaDevice *> * _Nonnull)freshAudioDeviceList { [_bridge configureActiveAudioDevice:freshAudioDeviceList]; } in RNDemo/MeetingObservers.m file

then added [meetingSession.audioVideo addDeviceChangeObserverWithObserver:observer]; in -(void)startVideo {} inside RNDemo/NativeMobileSDKBridge.m file

  1. then connect the Bluetooth audio device to the phone and join an existing meeting through the demo app
  2. and I got the log value inside the audioDeviceDidChangeWithFreshAudioDeviceList the first time, but when I disconnect or turn off Bluetooth didn't get the log (but sometimes got the log of disconnection)
Screenshot 2022-09-22 at 2 44 07 PM
ashirkhanpm commented 1 year ago

Hi @ethanjanadrake did you get this issue on the demo app, any update?

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ashirkhanpm commented 1 year ago

hi, any update?

hokyungh commented 1 year ago

Hi @ashirkhanpm, sorry for the late reply. When bluetooth device is connected, do you hear audio from the bluetooth? You can also check it by calling getActiveAudioDevice.

If current device is not bluetooth device, disconnecting does not trigger routeChangeNotification as implemented in our DefaultDeviceController, which resulted in not calling audioDeviceDidChangeWithFreshAudioDeviceList.

ashirkhan94 commented 1 year ago

Hi @hokyungh, Yes, I can hear audio through bluetooth, before device was disconnected, But the audioDeviceDidChangeWithFreshAudioDeviceList is not called, Is there any other observer function available for detecting audio route change?

hokyungh commented 1 year ago

Hi @ashirkhan94 , how did you disconnect bluetooth and what bluetooth device do you use? One of our teammates wasn't able to reproduce, so just wanted to see if you have another bluetooth device you can try to test.

ashirkhan94 commented 1 year ago

Hi @hokyungh , I disconnect by bluetooth device disconnect option in phone, using Wireless Earbuds (boAt Airdopes 411 ANC), I have facing same issue when tried with another device

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ashirkhan94 commented 1 year ago

Hi, Any update

hokyungh commented 1 year ago

Sorry for the late reply. I'll try on my device and get back to you.

But before I testing, are you using

-(void)configureActiveAudioDevice:(NSArray<MediaDevice *> * _Nonnull)audioDeviceList

  __block BOOL isHeadsetPluggedIn = false;

  // Judge useing headohone, if current routes has one or more headphones port.
   [currentOutputs enumerateObjectsUsingBlock:^(AVAudioSessionPortDescription *output, NSUInteger idx, BOOL *stop) {
     if([output.portType isEqual:AVAudioSessionPortHeadphones]){
       isHeadsetPluggedIn = true;
     }
   }];

  // If wiredHeadset connected, use Build-in receiver
  if(isHeadsetPluggedIn)
  {
    // use Build-in receiver
    [meetingSession.audioVideo chooseAudioDeviceWithMediaDevice:[audioDeviceList firstObject]];
  } else {
    // use loud speaker (or other device)
    [meetingSession.audioVideo chooseAudioDeviceWithMediaDevice:[audioDeviceList lastObject]];
  }
}

too?

Just wanted to see if you can add a logic to select bluetooth device.

ashirkhan94 commented 1 year ago

Hi, @hokyungh I am using below logic

-(void)configureActiveAudioDevice:(NSArray<MediaDevice *> * _Nonnull)audioDeviceList
{
  NSLog(@"test-ActiveAudio-list  currentoutput: %ld%ld" ,[[audioDeviceList firstObject]type],[[audioDeviceList lastObject]type]);
  if([[audioDeviceList firstObject]type]==0||[[audioDeviceList firstObject]type]==1)
     {
       NSLog(@"test-ActiveAudio-list  if value2: %@" ,[audioDeviceList firstObject]);
       [meetingSession.audioVideo chooseAudioDeviceWithMediaDevice:[audioDeviceList firstObject]];
       [self sendEventWithName:KEventonGetActiveAudioDevice body:@([[audioDeviceList firstObject] type])];
     } else {
       NSLog(@"test-ActiveAudio-list  else value3: %@" ,[audioDeviceList lastObject]);
       [meetingSession.audioVideo chooseAudioDeviceWithMediaDevice:[audioDeviceList lastObject]];
       [self sendEventWithName:KEventonGetActiveAudioDevice body:@([[audioDeviceList lastObject] type])];
     }
}

but my issue is audioDeviceDidChangeWithFreshAudioDeviceList function not triggering some times, when i disconnect bluetooth device

- (void)audioDeviceDidChangeWithFreshAudioDeviceList:(NSArray<MediaDevice *> * _Nonnull)freshAudioDeviceList
{
  NSLog(@"test-ActiveAudio-list freshAudioDeviceList");
  [_bridge configureActiveAudioDevice:freshAudioDeviceList];
}
hokyungh commented 1 year ago

Could you try with https://github.com/aws-samples/amazon-chime-react-native-demo/tree/use-device and see if it works for you?

ashirkhan94 commented 1 year ago

Hi, @hokyungh It's not working, i tried with above changes. The audio is routing successfully when we connect or disconnect bluetooth device, but some times can't able to change the icons, means if we disconnect bluetooth device the audio is flowing through earpiece, but the icon showing is bluetooth icon, not earpiece icon, because the audioDeviceDidChangeWithFreshAudioDeviceList is not trigger some times .

- (void)audioDeviceDidChangeWithFreshAudioDeviceList:(NSArray<MediaDevice *> * _Nonnull)freshAudioDeviceList
{
  NSLog(@"test-ActiveAudio-list freshAudioDeviceList");
  [_bridge configureActiveAudioDevice];
}
hokyungh commented 1 year ago

Hi @ashirkhan94, do you mind explaining the case where it is not working? We have a report on https://github.com/aws/amazon-chime-sdk-ios/issues/242, and there is case where if you are on different device and disconnect bluetooth, it won't get callback, which we have reported to Apple.

ashirkhan94 commented 1 year ago

Hi @hokyungh, Case: Connect the bluetooth device and the audio flowing through the bluetooth device, then I disconnect the bluetooth device using 3 ways

  1. turn off bluetooth in phone , but audioDeviceDidChangeWithFreshAudioDeviceList was not trigger IMG_0075

  2. Disconnect the Bluetooth device from phone, but audioDeviceDidChangeWithFreshAudioDeviceList was not trigger IMG_0074

  3. closed the earBud box, then device disconnected from phone, but audioDeviceDidChangeWithFreshAudioDeviceList was not trigger

In my case the disconnected time audio is not flowing through different device, audio is on bluetooth device.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ashirkhan94 commented 1 year ago

Hi any update

hokyungh commented 1 year ago

Sorry for late reply. Could you try with our demo application to see if you are getting the log?

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ashirkhan94 commented 1 year ago

Sorry for late reply. Could you try with our demo application to see if you are getting the log?

Yes I already tried with the demo application https://github.com/aws-samples/amazon-chime-react-native-demo/issues/159#issuecomment-1254751846

ashirkhan94 commented 1 year ago

Hi, Any update?

hokyungh commented 1 year ago

Hi sorry for late reply. I couldn't reproduce with our demo application, so I am getting new bluetooth earphone to test again.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ashirkhan94 commented 1 year ago

Hi @hokyungh any update

hokyungh commented 1 year ago

Hi I have tried all three test cases you posted with new bluetooth device, but only the third case I wasn't able to reproduce. We'll have to look into the third case, but for the first two cases, I hear beeping sound disconnecting and able to get audioDeviceDidChangeWithFreshAudioDeviceList callback. Let me mark it as bug.

AlkanV commented 1 year ago

hello any news on this? @hokyungh

hokyungh commented 1 year ago

Hi @AlkanV, we filed a ticket to apple and waiting for their reply.

AlkanV commented 1 year ago

@hokyungh thank you for lightning fast response.

ashirkhan94 commented 1 year ago

Hi @hokyungh Any update ?

salimkt commented 1 year ago

Hi @hokyungh Still having this issue.Any progress on this?

hokyungh commented 1 year ago

Hi sorry, we haven't got reply yet. We might need to implement short-term mitigation to fix this issue.

shivam-kakkar27 commented 6 months ago

@hokyungh Hi, Any update on this?