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

Fix Peripheral state not updating upon connection #300

Merged
merged 6 commits into from
Apr 12, 2022

Conversation

burnhamd
Copy link
Contributor

@burnhamd burnhamd commented Apr 5, 2022

References issue #290

Found issue where if the device is disconnected and delegate does not return a didDisconnect callback on IOS (for example when bluetooth is turned off) that the state flow would stay in connecting and never show connected in the peripheral side during reconnect.

This fixes that by using shared flow instead of state flow

Daniel Burnham and others added 2 commits April 4, 2022 22:32
@burnhamd burnhamd changed the title Bluetooth Bugfix for IOS peripherals not showing connected state upon connection Apr 5, 2022
@twyatt
Copy link
Member

twyatt commented Apr 6, 2022

Sorry, I don't follow how using a SharedFlow vs. a StateFlow would fix the issue?

@burnhamd
Copy link
Contributor Author

burnhamd commented Apr 6, 2022

Sorry, I don't follow how using a SharedFlow vs. a StateFlow would fix the issue?

It took us a while to figure this one out. So after the change which disconnects the peripherals in the event that bluetooth is powered off, the connectionState would remain in the previous state and not change. This would result in the peripheral state being DISCONNECTED, and the ConnectionState still having the most recent state emitted. Then once you call a connect on the peripheral, the peripheral state would change to connected, but the ConnectionState would not emit again because the state was the same as before.

So changing to a shared flow ensures that the ConnectionState emits even if it is the same value as before.

@davertay-j davertay-j requested a review from twyatt April 6, 2022 16:25
Copy link
Member

@twyatt twyatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @burnhamd! Great investigative work to figure out the problem and fix! 💯

core/src/appleMain/kotlin/CentralManagerDelegate.kt Outdated Show resolved Hide resolved
@twyatt twyatt changed the title Bugfix for IOS peripherals not showing connected state upon connection Fix Peripheral state not updating upon connection Apr 7, 2022
@twyatt twyatt added this to the 0.17.0 milestone Apr 7, 2022
Copy link
Contributor

@davertay-j davertay-j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @burnhamd

@twyatt twyatt added the apple label Apr 9, 2022
@twyatt twyatt requested a review from a team as a code owner April 12, 2022 22:10
@twyatt twyatt enabled auto-merge (squash) April 12, 2022 22:12
@twyatt twyatt merged commit b06ab1f into JuulLabs:main Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants