NearbyApi

interface NearbyApi

Abstracts the slice of Google Nearby Connections needed by NearbyLoom.

Implementations: FakeNearbyApi (tests, commonTest) and the real GmsNearbyApi (androidMain, dispatched separately).

All callbacks surface as Flows. The endpointId used in these events is a local-namespace opaque string assigned by the runtime — it is NOT a stable peer identity across sessions. Stable identity is exchanged as a payload during the handshake.

Properties

Link copied to clipboard

Emits when a connection initiation is signalled (either side triggered it). The receiver should call acceptConnection to proceed.

Link copied to clipboard

Emits the result of a connection request — success or failure.

Link copied to clipboard

Emits when an endpoint disconnects.

Link copied to clipboard
abstract val endpointFound: Flow<EndpointFound>

Emits when a remote endpoint is found during discovery. Carries the endpointId and the remote's display name.

Link copied to clipboard
abstract val payloadReceived: Flow<PayloadReceived>

Emits when a bytes payload is received from an endpoint.

Link copied to clipboard
open val radioState: StateFlow<NearbyRadioState?>

The device's live radio state, or null while unknown. This is what makes a seam's us.tractat.kuilt.core.Seam.capability reactive (#1543): as Bluetooth is toggled, Wi-Fi returns, or the Play services runtime hosting the fabric goes away, a fresh NearbyRadioState appears here and the seam folds its toAvailability into the live capability — and its radioRoles into the live ROLES.

Functions

Link copied to clipboard
abstract suspend fun acceptConnection(endpointId: String)

Accept an incoming connection from endpointId. Called after an EndpointEvent.ConnectionInitiated event is received.

Link copied to clipboard

Reports whether the underlying fabric is usable on this runtime — a one-shot, static platform-support question ("is there a Nearby runtime here at all"), answered once when NearbyLoom.capability is asked. It is deliberately NOT the live signal: see radioState, which is what makes a woven seam's capability reactive.

Link copied to clipboard
abstract suspend fun disconnect(endpointId: String)

Disconnect from endpointId. No-op if already disconnected.

Link copied to clipboard
abstract suspend fun requestConnection(displayName: String, endpointId: String)

Request a connection to a discovered endpointId. The local displayName is sent to the remote during the handshake.

Link copied to clipboard
abstract suspend fun sendBytesPayload(endpointId: String, bytes: ByteArray)

Send a raw bytes payload to endpointId.

Link copied to clipboard
abstract suspend fun startAdvertising(displayName: String, serviceId: String)

Begin advertising under displayName with service id serviceId.

Link copied to clipboard
abstract suspend fun startDiscovery(serviceId: String)

Begin discovering endpoints with the given serviceId.

Link copied to clipboard
abstract suspend fun stopAdvertising()

Stop advertising. No-op if not advertising.

Link copied to clipboard
abstract suspend fun stopDiscovery()

Stop discovery. No-op if not discovering.