-
Notifications
You must be signed in to change notification settings - Fork 80
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
Remove Central and simpify/unify API #24
Conversation
This comment has been minimized.
This comment has been minimized.
README.md
Outdated
val example = scanner() | ||
.advertisements | ||
.first { it.name?.startsWith("Example") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intention that all advertising peripherals will be in the flow, and filtering is done after they've been scanned? (as opposed to passing a filter to the scanner itself, like it is traditionally done in Android?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, yes, all filtering is to be done at the Flow
level. Not ideal, but good enough for MVP.
The plan is to add additional configuration support to Scanner
(follow the builder pattern), similar to how Json
works in kotlinx.serialization.
So, for platforms that support it, filtering could be done at the scanner level via an API similar to:
val scanner = Scanner {
services = arrayOf(...)
priority = Low
}
See also: #22
core/src/jsMain/kotlin/Bluetooth.kt
Outdated
import kotlin.js.Promise | ||
|
||
private val bluetooth: Bluetooth | ||
get() = js("window.navigator.bluetooth") ?: error("Bluetooth unavailable") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only works because we're targeting js().browser()
correct? Supporting non-browser based JS environments would require a different approach, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Good point. I don't believe this will work for Node.js.
Looks like Noble library does it via some kind of Node.js bindings mechanism.
...something to look into in the future. Tracking via #25.
This comment has been minimized.
This comment has been minimized.
🤦 I'm not sure what I was doing wrong, but when I tried this earlier it wasn't compiling. Seems to be working now, this was my preferred approach. So, I'm glad it seems to be working now. 😄 |
@@ -27,6 +28,10 @@ import org.w3c.dom.events.Event as JsEvent | |||
|
|||
private const val GATT_SERVER_DISCONNECTED = "gattserverdisconnected" | |||
|
|||
public actual fun CoroutineScope.peripheral( | |||
advertisement: Advertisement, | |||
): Peripheral = peripheral(advertisement.bluetoothDevice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same implementation as the Android version's Peripheral implementation. I haven't seen much expected/actual implementations. Is it possible for disparate platforms to share implementations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case. The bluetoothDevice
property name is the same on both platforms, but the type is the platform specific type for each platform, so being able to have this as a single function in common
is not possible unless the BluetoothDevice
is defined as expect
/actual
.
Unfortunately, since the platforms diverge a bit in their representation of the underlying bluetooth device, it's probably better to have this function duplicated than deal with the potential complexity of trying to unify the bluetooth device platform representations.
Decouples components from
Central
paradigm (Central
has been removed).API was simplified and unified by making the following changes:
CentralManager
Initializer
(and obtain applicationContext
)Scanner
is no longer scoped, soPeripheral
remains the only Coroutine scoped component. This allows library consumers more flexibility about the lifecycle of the various components.Updated README can be viewed here.