How sarthurx/vector-chat works
Project type and purpose
• This is an iOS SwiftUI application (“vector-chat”) whose core purpose is peer-to-peer ranging and directional measurement using Apple’s NearbyInteraction (UWB) framework. It discovers and connects two devices, exchanges discovery tokens, and then initiates a UWB session to measure distance and direction in real time.
File structure
• Top-level:
• vector-chat.xcodeproj & related Xcode workspace files
• vector-chat/ ← main SwiftUI app target
• vector-chatTests/ ← unit tests
• vector-chatUITests/ ← UI tests
• In vector-chat/:
• vector_chatApp.swift ← @main SwiftUI App entry point
• NearbyInteractionManager.swift ← encapsulates NI session setup, token exchange, callbacks
• PointerView.swift, RadarView.swift ← SwiftUI views that render UI based on UWB data
• vector-chat.entitlements ← declares NearbyInteraction and Multipeer-Connectivity capabilities
• Assets.xcassets, Info.plist
Insights from README
• The README shows the peer-to-peer flow:
a. Device A starts advertising & browsing (MultipeerConnectivity)
b. It waits for invites, invites Device B
c. They exchange discovery tokens over the Multipeer link
d. NearbyInteraction session starts for UWB ranging & direction
Main components
a. SwiftUI Layer
– vector_chatApp.swift (App entry)
– RadarView, PointerView (UI updates)
b. NearbyInteractionManager
– Responsible for:
• Starting/stopping MultipeerConnectivity advertising & browsing
• Sending/receiving discovery tokens
• Setting up NI session (start, delegate callbacks)
c. Apple Frameworks (external services)
– MultipeerConnectivity.framework ← peer discovery & token exchange channel
– NearbyInteraction.framework ← UWB ranging & directional data
d. Device Hardware
– UWB radio (for distance & direction measurement)
– Local device OS (iOS Core)
Relationships & interactions
• UI Layer ↔ NearbyInteractionManager
• UI invokes “startScanning()”, “invitePeer()”
• Manager emits published properties (distance, angle) → SwiftUI views
• Manager ↔ MultipeerConnectivity
• Advertise/browse → establish MCSession
• Exchange discovery tokens over MCSession data channel
• Manager ↔ NearbyInteraction.framework
• Create NISession with peer’s token
• Receive NINearbyObject updates (distance, direction)
• NearbyInteraction.framework ↔ UWB hardware
Architectural patterns & principles
• MVVM-style separation: SwiftUI views bind to published state in the Manager
• Single-responsibility: NearbyInteractionManager isolates all peer/connect/ranging logic
• Reactive updates: SwiftUI + Combine (or @Published) for real-time UI refresh
Essential checklist
• Both devices (Device A and Device B) side by side
• Sequence: advertise/browse → invite/connect → token exchange → UWB ranging