Discovering a third-party media-streaming device
At a glance
| Item | Summary |
|---|---|
| Purpose | Build an extension that streams media to a server app in iOS or macOS. |
| App architecture | A Swift sample with the source-visible chain ServerApp → ServerView → VideoViewModel → DemoClientSession → SwiftUI / Network APIs. |
| Main patterns | Model-View-ViewModel, View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Coordinator, Publisher-backed observable state |
| Project style | 21 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── DeviceDiscoveryExtensionDemo/
├── CustomMediaDeviceDemo/
│ ├── Server/
│ │ ├── ServerApp.swift
│ │ └── ServerView.swift
│ ├── Client/
│ │ ├── ClientApp.swift
│ │ ├── ClientView.swift
│ │ ├── DevicePickerView.swift
│ │ ├── RemoteControlView.swift
│ │ └── RouteController.swift
│ └── Protocol/
│ ├── DemoSession.swift
│ └── DemoProtocol.swift
├── CustomMediaDeviceMacServer/
│ ├── DemoMacServerApp.swift
│ └── ContentView.swift
└── CustomMediaDeviceExtension/
└── Appex.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 13 project/configuration file(s) and 49 source declaration(s).
Overall architecture
flowchart LR
N1["ServerApp"]
N2["ServerView"]
N3["VideoViewModel"]
N4["DemoClientSession"]
N5["SwiftUI / Network APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Server/ServerApp.swift:23 — architecture anchor
@main
struct DataAccessDemoServerApp: App {
// ...
}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 DeviceDiscoveryExtension.
Ownership and state
classDiagram
Volume *-- Float : level
Volume *-- Volume : volume
State *-- Float : timeRemaining
State *-- Int : sessionId
Ownership evidence
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Protocol/DemoSession.swift:26 — stored dependency or nearest verified ownership anchor
struct Volume {
var muted = false
var level: Float = 1.0
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
Volume |
Float (level) |
owns value state | App/module collaborators |
Volume |
Volume (volume) |
creates and retains | App/module collaborators |
State |
Float (timeRemaining) |
owns value state | App/module collaborators |
State |
Int (sessionId) |
owns value state | App/module collaborators |
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
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Protocol/BonjourConnection.swift:20 — representative type boundary
protocol DemoConnectionDelegate: AnyObject {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | NSObject, UIApplicationDelegate |
DataAccessDemoServerApp |
Application entry and top-level composition | App |
DataAccessDemoClientApp |
Application entry and top-level composition | App |
DemoMacServerApp |
Application entry and top-level composition | App |
DemoConnectionDelegate |
Defines a capability or collaboration contract | AnyObject |
DemoSession |
Owns a session-scoped interaction | Concrete collaborators/imported frameworks |
DemoClientSession |
Owns a session-scoped interaction | DemoSession<DemoClientMessage, DemoServerMessage> |
DemoServerSession |
Owns a session-scoped interaction | DemoSession<DemoServerMessage, DemoClientMessage> |
VideoViewModel |
UI-facing state and feature coordination | ObservableObject |
ServerView |
User-interface presentation and input forwarding | View |
The source explicitly defines local protocol relationships: DemoUdpConnection → DemoConnection, DemoMessageBase → HasMessageTypeParam, DemoClientMessage → DemoMessageBase, DemoServerMessage → DemoMessageBase.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
activateRouteManager (DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientView.swift:140) |
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. |
routesHaveSameNetworkEndpoint (DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/RouteController.swift:186) |
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. |
findControllerRoutes (DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/RouteController.swift:193) |
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. |
processBluetoothIdentifier (DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/RouteController.swift:201) |
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
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientView.swift:140 — representative boundary
private func activateRouteManager() {
// ...
}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 | DataAccessDemoClientApp, DataAccessDemoServerApp, DemoMacServerApp |
The source’s App suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | ClientSessionController, RouteController |
The source’s Controller suffix makes this role explicit. |
| Cross-object flow or session coordination | Coordinator |
The source’s Coordinator suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate, DemoConnectionDelegate |
The source’s Delegate suffix makes this role explicit. |
| Long-lived feature or framework coordination | BTPeripheralManager, RouteManager |
The source’s Manager suffix makes this role explicit. |
| Owns a session-scoped interaction | DemoClientSession, DemoServerSession, DemoSession |
The source’s Session suffix makes this role explicit. |
| User-interface presentation and input forwarding | ClientDiscoveryView, ClientView, ContentView, DevicePickerView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientView.swift:14 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| View-controller organization | DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/RemoteControlView.swift:62 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Protocol/BonjourConnection.swift:33 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientDiscovery.swift:29 |
Callback protocols invert event delivery back into the sample’s owner. |
| Coordinator | DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/DevicePickerView.swift:36 |
A role-named coordinator centralizes cross-object flow. |
| Publisher-backed observable state | DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientDiscovery.swift:33 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: DataAccessDemoClientApp, DataAccessDemoServerApp, DemoMacServerApp; Controller: ClientSessionController, RouteController; Coordinator: Coordinator; Delegate: AppDelegate, DemoConnectionDelegate; Manager: BTPeripheralManager, RouteManager; Session: DemoClientSession, DemoServerSession, DemoSession; View: ClientDiscoveryView, ClientView, ContentView, DevicePickerView, RemoteControlView; ViewModel: VideoViewModel.
- Protocols:
DemoConnectionDelegate,HasMessageTypeParam,DemoMessageBase,DemoConnection. - Methods:
application,toStr,appendInterpolation,didStart,didStop,didSend,didReceive,post. - Files:
DeviceDiscoveryExtensionDemo/CustomMediaDeviceMacServer/DemoMacServerApp.swift,DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Protocol/DemoSession.swift,DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Server/ServerView.swift,DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientView.swift,DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/DevicePickerView.swift,DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/RemoteControlView.swift.
Architecture takeaways
ServerAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, Network, AVRouting, CoreBluetooth 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.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Server/ServerApp.swift |
AppDelegate, DataAccessDemoServerApp |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientApp.swift |
DataAccessDemoClientApp |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceMacServer/DemoMacServerApp.swift |
DemoMacServerApp |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Protocol/DemoSession.swift |
DemoProtocolError, DemoServerStatus, Volume, State, DemoSessionState, DemoSession, DemoClientSession, DemoServerSession |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Server/ServerView.swift |
RoomLocation, TargetProtocol, BroadcastType, VideoViewModel, ServerView, RoundedButtonStyle, ServerView_Previews |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceExtension/Appex.swift |
DataAccessDemoExtension |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/ClientView.swift |
VideoViewModel, ClientView, ConnectionTester, ClientView_Previews |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Protocol/DemoProtocol.swift |
DemoMessageType, HasMessageTypeParam, DemoMessageBase, DemoClientMessage, Message, DemoServerMessage, Message |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/DevicePickerView.swift |
DevicePickerView, Coordinator |
DeviceDiscoveryExtensionDemo/CustomMediaDeviceDemo/Client/RemoteControlView.swift |
RemoteControlView, ClientSessionController |