NwApi

interface NwApi

Abstracts the slice of Apple's Network.framework needed by NwLoom.

Implementations: FakeNwApi (tests, commonTest) and the real RealNwApi (appleMain, dispatched separately).

Unlike a single-peer accept/initiate handshake API, NwApi is stream-oriented and multi-connection: it hosts (advertise + listen) and joins (browse + connect) concurrently, and every accepted or dialled link gets its own NwConnectionId. Framing and handshake semantics live above this layer — this interface only moves raw bytes over an already-open connection.

Properties

Link copied to clipboard
abstract val bytesReceived: Flow<NwBytesReceived>

Emits when a byte chunk arrives on a connection.

Link copied to clipboard

Emits when a connection closes, locally or remotely initiated — the fast, reason-carrying close path.

Link copied to clipboard

Emits when a connection is established — accepted (host role) or dialled (join role).

Link copied to clipboard

The per-connection latest lifecycle state: each connection's NwConnectionId mapped to its current NwConnStateNwConnState.Viable (path up), NwConnState.PathLost (path unsatisfied), or NwConnState.Closed (terminally torn, carrying the raw close reason). This ONE drop-tolerant STATE signal unifies the two former parallel maps — connectionViability (#1509) and closedConnections (#1522) — into a single total sum type (#1539). A connection absent from the map has never established.

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

Emits when a remote endpoint is found while browsing.

Link copied to clipboard
open val endpointLost: Flow<NwEndpoint>

Emits when a previously-discovered endpoint is removed while browsing — the browse-time inverse of endpointFound. A consumer maintaining a discovery roster (e.g. NwLoom.visiblePeers) prunes the endpoint on this signal so departed peers don't accumulate as ghosts (#1447).

Link copied to clipboard
open val pathState: StateFlow<NwPathState?>

The device's live network-path state (NWPathMonitor), or null while unknown. This is what makes a seam's us.tractat.kuilt.core.Seam.capability reactive: as the path goes up/down, swaps Wi-Fi↔cellular, or the Local-Network permission is denied, a fresh NwPathState appears here and the seam folds its toAvailability into the live capability.

Functions

Link copied to clipboard

Reports whether the underlying fabric is usable on this runtime.

Link copied to clipboard
abstract suspend fun connect(endpoint: NwEndpoint)

Dial a discovered endpoint, establishing a new outbound connection.

Link copied to clipboard
abstract suspend fun disconnect(connectionId: NwConnectionId)

Tear down the connection identified by connectionId. No-op if already closed.

Link copied to clipboard
abstract suspend fun send(connectionId: NwConnectionId, bytes: ByteArray)

Send raw bytes over connectionId. Framing is the caller's responsibility.

Link copied to clipboard
abstract suspend fun startBrowsing(serviceType: String)

Begin browsing for endpoints advertising Bonjour service type serviceType.

Link copied to clipboard
abstract suspend fun startListening(serviceName: String, serviceType: String)

Begin advertising serviceName under Bonjour service type serviceType and accept inbound connections.

Link copied to clipboard
abstract suspend fun stopBrowsing()

Stop browsing. No-op if not browsing.

Link copied to clipboard
abstract suspend fun stopListening()

Stop listening/advertising. No-op if not listening.