Skip to content

feat: Add and document optional kadb-mdns module#26

Open
Flyfish233 wants to merge 2 commits into
flyfishxu:mainfrom
Flyfish233:test/mdns
Open

feat: Add and document optional kadb-mdns module#26
Flyfish233 wants to merge 2 commits into
flyfishxu:mainfrom
Flyfish233:test/mdns

Conversation

@Flyfish233

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new optional Kotlin Multiplatform module (kadb-mdns) that discovers ADB-related mDNS services (Android via NsdManager, JVM via JmDNS), and updates project/docs to publish and document its usage alongside the core kadb artifact.

Changes:

  • Introduce new :kadb-mdns module with Android + JVM discovery implementations and a shared StateFlow-based state model.
  • Add mDNS discovery documentation and update README/platform docs to reference the optional artifact and usage.
  • Add dependency catalog entry for JmDNS and add unit tests for parsing, mapping, and registry behavior.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
settings.gradle.kts Registers the new :kadb-mdns Gradle module.
README.md Documents the optional mDNS artifact and shows Android/JVM usage snippets.
kadb-mdns/build.gradle.kts Defines the new KMP module, dependencies, and Maven publishing coordinates.
gradle/libs.versions.toml Adds JmDNS dependency coordinates/version.
docs/README.md Adds mDNS doc entry to the docs index.
docs/platform.md Notes optional mDNS discovery support and requirements per platform.
docs/mdns.md New dedicated documentation page for mDNS discovery and lifecycle/state model.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/KadbMdns.kt Defines the shared KadbMdns interface and lifecycle methods.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/MdnsConfig.kt Introduces configuration for service types and IPv4 preference.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/MdnsDiscoveryState.kt Shared state model for discovery results and status.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/MdnsEndpoint.kt Shared endpoint model for discovered services.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/MdnsServiceType.kt Enumerates supported ADB-related service types.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/MdnsStatus.kt Shared discovery status enum.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/internal/MdnsRegistry.kt Central state registry for upsert/remove and grouping into connect/pair lists.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/internal/MdnsServiceKey.kt Registry keying for endpoints by name + service type.
kadb-mdns/src/commonMain/kotlin/com/flyfishxu/kadb/mdns/internal/MdnsServiceTypeParser.kt Normalization/parsing utilities for service type strings.
kadb-mdns/src/androidMain/kotlin/com/flyfishxu/kadb/mdns/KadbMdnsAndroid.kt Android discovery implementation using NsdManager and API-level branching.
kadb-mdns/src/androidMain/kotlin/com/flyfishxu/kadb/mdns/internal/AndroidDiscoveryListener.kt Bridges NSD discovery events into the module callbacks.
kadb-mdns/src/androidMain/kotlin/com/flyfishxu/kadb/mdns/internal/AndroidResolveListener.kt Handles pre-API-34 resolve callbacks.
kadb-mdns/src/androidMain/kotlin/com/flyfishxu/kadb/mdns/internal/AndroidServiceInfoCallback.kt Handles API-34+ ServiceInfoCallback updates/lifecycle.
kadb-mdns/src/androidMain/kotlin/com/flyfishxu/kadb/mdns/internal/NsdServiceInfoMapper.kt Maps resolved NSD info into MdnsEndpoint/keys with IPv4 preference.
kadb-mdns/src/jvmMain/kotlin/com/flyfishxu/kadb/mdns/KadbMdnsJvm.kt JVM discovery implementation with backend abstraction and registry integration.
kadb-mdns/src/jvmMain/kotlin/com/flyfishxu/kadb/mdns/internal/JmDnsBackend.kt Backend + event abstraction for JmDNS integration/testing.
kadb-mdns/src/jvmMain/kotlin/com/flyfishxu/kadb/mdns/internal/JmDnsEndpointMapper.kt Maps resolved JmDNS service info to MdnsEndpoint.
kadb-mdns/src/jvmMain/kotlin/com/flyfishxu/kadb/mdns/internal/JmDnsServiceListener.kt Adapts JmDNS ServiceListener to internal event callbacks.
kadb-mdns/src/jvmMain/kotlin/com/flyfishxu/kadb/mdns/internal/RealJmDnsBackend.kt Real JmDNS backend, interface selection, and service type formatting.
kadb-mdns/src/commonTest/kotlin/com/flyfishxu/kadb/mdns/MdnsRegistryTest.kt Tests registry grouping, remove behavior, and validation.
kadb-mdns/src/commonTest/kotlin/com/flyfishxu/kadb/mdns/MdnsServiceTypeParserTest.kt Tests service type parsing/normalization.
kadb-mdns/src/jvmTest/kotlin/com/flyfishxu/kadb/mdns/JmDnsEndpointMapperTest.kt Tests endpoint mapping and validation on JVM.
kadb-mdns/src/jvmTest/kotlin/com/flyfishxu/kadb/mdns/KadbMdnsJvmTest.kt Tests JVM discovery wiring (listeners, publish/remove, stop cleanup).
kadb-mdns/src/jvmTest/kotlin/com/flyfishxu/kadb/mdns/internal/FakeJmDnsBackend.kt Fake backend for deterministic JVM tests.
kadb-mdns/src/jvmTest/kotlin/com/flyfishxu/kadb/mdns/internal/JmDnsServiceTypeFormatterTest.kt Tests service type formatting for JmDNS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +15
internal fun String?.normalizeMdnsServiceType(): String =
this.orEmpty()
.trim()
.removeSuffix(".")
.removeSuffix(".local")
.lowercase()
val pairDevices = values.filter { it.serviceType == MdnsServiceType.TLS_PAIRING }
mutableState.value = MdnsDiscoveryState(
status = status,
loading = status != MdnsStatus.STOPPED && status != MdnsStatus.FAILED && values.isEmpty(),
Comment on lines +45 to +49
val interfaceBackends = runCatching {
eligibleInterfaceAddresses().map { address ->
RealJmDnsBackend(JmDNS.create(address))
}
}.getOrElse { emptyList() }
@IndiTheo

IndiTheo commented Jun 6, 2026

Copy link
Copy Markdown

Nice to see it!
By the way, is there a reason not to structure the SDK as Kadb.discover(...) and pass the configuration options in there? Looks more consistent with other SDK calls and dadb discovery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants