Conversation
…k-config' into HEAD # Conflicts: # PeerConnectivity.xcodeproj/project.pbxproj
There was a problem hiding this comment.
Pull request overview
Adds a new UIKit-neutral PeerBrowserModel to the core PeerConnectivity target to support app-owned peer selection UI (especially for the Network backend), along with tests and documentation showing intended usage.
Changes:
- Introduce
PeerBrowserModelto track discovered peers viaPeerConnectionManagerevents and forward approved invites. - Add
PeerBrowserModelTestscovering found/lost tracking, status updates, invite forwarding, and stop-observing behavior. - Update
NetworkBackendGuide.mdto demonstrate.custompeer selection usingPeerBrowserModel.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Sources/PeerBrowserModel.swift | New public model type for peer discovery state + main-queue UI callbacks + invite forwarding. |
| PeerConnectivityTests/PeerBrowserModelTests.swift | New XCTest coverage validating model behavior using mocked transports. |
| PeerConnectivity.xcodeproj/project.pbxproj | Wires the new source and test files into the Xcode project build. |
| NetworkBackendGuide.md | Updates .custom documentation to recommend PeerBrowserModel for app-owned peer UI. |
Suppressed comments (2)
Sources/PeerBrowserModel.swift:152
notifydispatches to the main queue even whenhandleris nil, creating unnecessary async work. Early-return when there is no handler to call.
fileprivate func notify(_ handler: PeersChangedHandler?, peers: [Peer]) {
DispatchQueue.main.async {
handler?(peers)
}
PeerConnectivityTests/PeerBrowserModelTests.swift:168
- This test relies on a short
RunLoopdelay to try to catch post-stopObserving()updates, which can be flaky across environments. Use an inverted XCTest expectation tied to the model'speersChangedcallback instead, then wait for a short duration.
internal func testStopObservingRemovesModelListener() {
let harness = PeerBrowserModelHarness()
let manager = makeManager(harness: harness)
let model = PeerBrowserModel(manager: manager)
let peer = Peer(identity: PeerIdentity(identifier: "remote", displayName: "Remote"), status: .notConnected)
model.startObserving()
manager.startBrowsingOnly()
model.stopObserving()
harness.browserObserver?.value = .foundPeer(peer, discoveryInfo: nil)
RunLoop.current.run(until: Date().addingTimeInterval(0.1))
XCTAssertTrue(model.discoveredPeers.isEmpty)
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Superseded by consolidated PR #48. No commits were discarded; this branch is preserved as a recovery and reference point. Addressed review findings were replied to and resolved before consolidation. |
Summary
Adds a UIKit-neutral
PeerBrowserModelfoundation for app-owned Network backend peer selection UI.Changes
PeerBrowserModelin the corePeerConnectivitytarget..foundPeer.lostPeer.nearbyPeersChanged.devicesChangedpeersChangedcallbacks on the main queue for UI consumers.invitePeer(_:withContext:timeout:); the model does not auto-invite discovered peers.NetworkBackendGuide.mdto show.custompeer selection withPeerBrowserModel.Verification
swift test --filter PeerBrowserModelTests— 4 tests passedswift test— 113 tests passedxcodebuild test -project PeerConnectivity.xcodeproj -scheme PeerConnectivity -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.3.1' -configuration Debug— 113 tests passedpull_requestCI — Swift Package Tests and Xcode Project Tests passedpushCI — Swift Package Tests and Xcode Project Tests passedNotes / limitations
Stack context
Stacked on PR #42 (
feature/network-migration-network-config). This is the Network browser model foundation slice of the migration stack.