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
Emits when a byte chunk arrives on a connection.
Emits when a connection closes, locally or remotely initiated — the fast, reason-carrying close path.
Emits when a connection is established — accepted (host role) or dialled (join role).
The per-connection latest lifecycle state: each connection's NwConnectionId mapped to its current NwConnState — NwConnState.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.
Emits when a remote endpoint is found while browsing.
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).
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
Reports whether the underlying fabric is usable on this runtime.
Dial a discovered endpoint, establishing a new outbound connection.
Tear down the connection identified by connectionId. No-op if already closed.
Send raw bytes over connectionId. Framing is the caller's responsibility.
Begin browsing for endpoints advertising Bonjour service type serviceType.
Begin advertising serviceName under Bonjour service type serviceType and accept inbound connections.
Stop browsing. No-op if not browsing.
Stop listening/advertising. No-op if not listening.