shinyorg / shiny

.NET Framework for Backgrounding & Device Hardware Services (iOS, Android, & Catalyst)
https://shinylib.net
MIT License
1.43k stars 227 forks source link

[Bug]: The devices are not disconnected with 2 Bluetooth connections #1472

Closed HausBJB closed 3 months ago

HausBJB commented 3 months ago

Component/Nuget

BluetoothLE Client (Shiny.BluetoothLE)

What operating system(s) are effected?

Version(s) of Operation Systems

iOS-Version 16.6 Unfortunately, I was unable to test Android and other platforms

Hosting Model

Steps To Reproduce

  1. Start sample project
  2. make sure there are at least two devices nearby that you can connect to
  3. press the Click me button in the app
  4. take a look at the console logs

Expected Behavior

I expect the connection to be disconnected after calling CancelConnection()

Actual Behavior

At the moment, if two devices are connected and then you disconnect from both devices, it will automatically reconnect a short time later and then it repeats itself over and over again, disconnecting and reconnecting, look at the logs

Exception or Log output

2024-05-24 14:54:35.380 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Disconnected

2024-05-24 14:54:35.379 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Disconnected

2024-05-24 14:54:35.947 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Connected

2024-05-24 14:54:35.947 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Connected

2024-05-24 14:54:35.952 Xamarin.PreBuilt.iOS[902:140454] All connections successfully established

2024-05-24 14:54:45.488 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Disconnected

2024-05-24 14:54:45.487 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Disconnected

2024-05-24 14:54:45.958 Xamarin.PreBuilt.iOS[902:140454] Try to interrupt all connections

2024-05-24 14:54:45.990 Xamarin.PreBuilt.iOS[902:140454] GATT is not connected

2024-05-24 14:54:46.025 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Connected

2024-05-24 14:54:46.025 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Connected

Thread finished: #4 Der Thread 4 hat mit Code 0 (0x0) geendet. 2024-05-24 14:54:55.567 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Disconnected

2024-05-24 14:54:55.567 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Disconnected

2024-05-24 14:54:56.104 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Connected

2024-05-24 14:54:56.103 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Connected

2024-05-24 14:55:05.647 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Disconnected

2024-05-24 14:55:05.646 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Disconnected

2024-05-24 14:55:06.185 Xamarin.PreBuilt.iOS[902:140454] The status of device number 2 has changed to Connected

2024-05-24 14:55:06.184 Xamarin.PreBuilt.iOS[902:140454] The status of device number 1 has changed to Connected

Code Sample

https://github.com/HausBJB/MauiApp1

Code of Conduct

aritchie commented 3 months ago

I do absolutely nothing special here. This is entirely on the platform to figure out.

I have never seen anything remotely close to this in any of my projects. The only thing I can see is that you're not cancelling out of your scan wave in the most appropriate way.

public ConnectionState Status => this.Native.State switch
{
    CBPeripheralState.Connected => ConnectionState.Connected,
    CBPeripheralState.Connecting => ConnectionState.Connecting,
    CBPeripheralState.Disconnected => ConnectionState.Disconnected,
    CBPeripheralState.Disconnecting => ConnectionState.Disconnecting,
    _ => ConnectionState.Disconnected
};

public void CancelConnection()
{
    this.autoReconnectSub?.Dispose();
    this.manager.Manager.CancelPeripheralConnection(this.Native);
}

I'd suggest pulling down the code to see what might be happening. There isn't really anything for me to solve here.