Skip to content

Commit 6db21b0

Browse files
committed
docs: update README and design doc for 0.2.0 (add installation, fix require() example, document typed events)
1 parent 31f90d1 commit 6db21b0

3 files changed

Lines changed: 86 additions & 5 deletions

File tree

Package.resolved

Lines changed: 64 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ The API should stay simple enough for application code to use without learning l
1010

1111
See [Design Philosophy](docs/DESIGN_PHILOSOPHY.md) for the broader project context and design constraints.
1212

13+
## Installation
14+
15+
Add the package to your `Package.swift` dependencies:
16+
17+
```swift
18+
.package(url: "https://github.com/1amageek/swift-peer-connectivity.git", from: "0.2.0")
19+
```
20+
21+
The libp2p backends require swift-libp2p 0.2.0.
22+
1323
## Usage
1424

1525
Create a session with an explicit backend, browse and advertise when the backend supports those roles, then join discovered peers.
@@ -24,7 +34,7 @@ let session = PeerConnectivitySession.multipeer(
2434
displayName: "Device A"
2535
)
2636

27-
try await session.require([.nearbyDiscovery, .messageSend])
37+
try session.require([.nearbyDiscovery, .messageSend])
2838
try await session.startBrowsing()
2939
try await session.startAdvertising()
3040

@@ -55,6 +65,12 @@ Multi-peer `send(_:to:[peers])` is exhaustive, not atomic: it attempts every pee
5565
and, if any fail, throws `PeerSendError` listing per-peer outcomes (which
5666
succeeded, which failed) instead of aborting on the first failure.
5767

68+
`.error` carries a typed `PeerConnectivityErrorEvent` (operation, peer, and the
69+
underlying error) so a failure can be attributed rather than surfaced as a bare
70+
`Error`. Messages and resources use length-prefixed framing, so a truncated
71+
inbound transfer surfaces as a typed error instead of a silently incomplete
72+
payload, and inbound handlers apply an idle timeout.
73+
5874
Use `join(_:)` for discovered peers. It uses endpoints for direct-connect backends and invitations for nearby-session backends. Use `connect(to:)`, `invite(_:context:timeout:)`, and `openChannel(to:protocol:)` when backend-specific behavior is intentional.
5975

6076
`startBrowsing()` and `startAdvertising()` fail when the backend cannot control those roles separately. Use `start()` when the application intentionally wants the backend's complete configured lifecycle.
@@ -135,4 +151,6 @@ Use explicit factories so call sites choose the backend intentionally:
135151
- `PeerConnectivitySession.appleNetworkLibP2P(configuration:)`
136152
- `PeerConnectivitySession.multipeer(serviceType:displayName:)`
137153

154+
`appleNetworkLibP2P(configuration:)` is throwing. When `enableBonjour` is set, it requires at least one listen address to announce; otherwise it throws `PeerConnectivityError.listenAddressRequired` rather than advertising `.bonjourDiscovery` it cannot honor.
155+
138156
Automatic backend selection is intentionally omitted from the initial API surface.

docs/DESIGN_PHILOSOPHY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ let session = PeerConnectivitySession.multipeer(
164164
displayName: "Robot A"
165165
)
166166

167-
try await session.require([.nearbyDiscovery, .messageSend])
167+
try session.require([.nearbyDiscovery, .messageSend])
168168
try await session.startBrowsing()
169169
try await session.startAdvertising()
170170

@@ -189,11 +189,11 @@ each access. Subscribe before `start()` so no early events are missed.
189189
For cross-platform Robot communication, the app should choose a libp2p-compatible backend explicitly:
190190

191191
```swift
192-
let session = try await PeerConnectivitySession.appleNetworkLibP2P(
192+
let session = try PeerConnectivitySession.appleNetworkLibP2P(
193193
configuration: configuration
194194
)
195195

196-
try await session.require([.libp2pInterop, .streamMultiplexing])
196+
try session.require([.libp2pInterop, .streamMultiplexing])
197197
```
198198

199199
The important distinction is intentional backend choice with a common app-facing workflow.

0 commit comments

Comments
 (0)