Creating a foveated streaming client on visionOS
At a glance
| Item | Summary |
|---|---|
| Purpose | Build a visionOS app that streams high-fidelity immersive content from a computer or the cloud using the Foveated Streaming framework. |
| App architecture | A Swift sample with the source-visible chain FoveatedStreamingSampleApp → ContentView → AppModel → FoveatedStreaming / FoveatedStreamingSimulator APIs. |
| Main patterns | Binding-based state propagation, Actor-isolated state |
| Project style | 14 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── FoveatedStreaming-Sample/
├── FoveatedStreaming-Sample/
│ ├── FoveatedStreamingSampleApp.swift
│ ├── Models/
│ │ ├── AppModel.swift
│ │ ├── MessageChannelModel.swift
│ │ └── StreamActions.swift
│ ├── Views/
│ │ ├── StreamConnectionView.swift
│ │ ├── ContentView.swift
│ │ ├── MessageChannelView.swift
│ │ ├── ReopenMainWindowView.swift
│ │ ├── StreamControlsView.swift
│ │ └── TransformStreamWidgetView.swift
│ └── ViewModifiers/
│ └── SetImmersivePresentationBehaviorsViewModifier.swift
└── FoveatedStreamingSimulator/
└── FoveatedStreamingSimulator.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 5 project/configuration file(s) and 21 source declaration(s).
Overall architecture
flowchart LR
N1["FoveatedStreamingSampleApp"]
N2["ContentView"]
N3["AppModel"]
N4["FoveatedStreaming / FoveatedStreamingSimulator APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:12 — architecture anchor
@main
struct FoveatedStreamingSampleApp: App {
var body: some SwiftUI.Scene {
WindowGroup() {
Text("FoveatedStreamingSampleApp is unsupported on the simulator. Please use a device to run this sample.")
}
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Foveated Streaming.
Ownership and state
classDiagram
FoveatedStreamingSampleApp *-- FoveatedStreamingSession : session
FoveatedStreamingSampleApp *-- AppModel : appModel
FoveatedStreamingSampleApp o-- MessageChannelModel : messageChannelModel
MessageChannelModel o-- FoveatedStreamingSession : session
Ownership evidence
FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:26 — stored dependency or nearest verified ownership anchor
private let session = FoveatedStreamingSession()
private let appModel = AppModel()
private let messageChannelModel: MessageChannelModel
init() {
messageChannelModel = MessageChannelModel(session: session)
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
FoveatedStreamingSampleApp |
FoveatedStreamingSession (session) |
creates and retains | Initialized by the owner; the binding is immutable |
FoveatedStreamingSampleApp |
AppModel (appModel) |
creates and retains | Initialized by the owner; the binding is immutable |
FoveatedStreamingSampleApp |
MessageChannelModel (messageChannelModel) |
stores or receives | Initialized by the owner; the binding is immutable |
MessageChannelModel |
FoveatedStreamingSession (session) |
stores or receives | Initialized by the owner; the binding is immutable |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:13 — representative type boundary
struct FoveatedStreamingSampleApp: App {
var body: some SwiftUI.Scene {
WindowGroup() {
Text("FoveatedStreamingSampleApp is unsupported on the simulator. Please use a device to run this sample.")
}
}
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
FoveatedStreamingSampleApp |
Application entry and top-level composition | App |
FoveatedStreamingSampleApp |
Application entry and top-level composition | App |
AppModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
MessageChannelModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
StreamConnectionView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
DeveloperSettingsView |
User-interface presentation and input forwarding | View |
ReopenMainWindowView |
User-interface presentation and input forwarding | View |
StreamControlsView |
User-interface presentation and input forwarding | View |
TransformStreamWidgetView |
User-interface presentation and input forwarding | View |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
session (FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:26) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
appModel (FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:27) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
messageChannelModel (FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:28) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
monitorAvailableChannels (FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift:35) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
Reference code
FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift:26 — representative boundary
private let session = FoveatedStreamingSession()Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | FoveatedStreamingSampleApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | AppModel, MessageChannelModel |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, DeveloperSettingsView, ReopenMainWindowView, StreamConnectionView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Binding-based state propagation | FoveatedStreaming-Sample/FoveatedStreaming-Sample/ViewModifiers/TrackWindowStateViewModifier.swift:18 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
| Actor-isolated state | FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/AppModel.swift:10 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: FoveatedStreamingSampleApp; Model: AppModel, MessageChannelModel; View: ContentView, DeveloperSettingsView, ReopenMainWindowView, StreamConnectionView, StreamControlsView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
monitorAvailableChannels,setUpMessageChannel,startReceivingMessages,local,remote,sendMessage. - Files:
FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift,FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/AppModel.swift,FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift,FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/StreamConnectionView.swift,FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ContentView.swift,FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ReopenMainWindowView.swift.
Architecture takeaways
FoveatedStreamingSampleAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, FoveatedStreaming, FoveatedStreamingSimulator, RealityKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
FoveatedStreaming-Sample/FoveatedStreaming-Sample/FoveatedStreamingSampleApp.swift |
FoveatedStreamingSampleApp, FoveatedStreamingSampleApp |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/AppModel.swift |
AppModel, WindowState |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Models/MessageChannelModel.swift |
MessageChannelModel |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/StreamConnectionView.swift |
ConnectionMode, StreamConnectionView |
FoveatedStreaming-Sample/FoveatedStreamingSimulator/FoveatedStreamingSimulator.swift |
Status, DisconnectReason, Value, Endpoint, Value |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ContentView.swift |
ContentView |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/MessageChannelView.swift |
DeveloperSettingsView |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/ReopenMainWindowView.swift |
ReopenMainWindowView |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/StreamControlsView.swift |
StreamControlsView |
FoveatedStreaming-Sample/FoveatedStreaming-Sample/Views/TransformStreamWidgetView.swift |
TransformStreamWidgetView |