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.

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.

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.