You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
import MusubiCore
|
|
import NDIKit
|
|
import Observation
|
|
|
|
@MainActor @Observable
|
|
final class SourceListModel {
|
|
enum State { case idle, searching, unavailable }
|
|
|
|
private(set) var sources: [Source] = []
|
|
private(set) var state: State = .idle
|
|
private var finder: NDIFinder?
|
|
|
|
func start() {
|
|
guard state == .idle else { return }
|
|
|
|
guard NDI.initialize() else {
|
|
Log.ndi.error("NDI initialization failed (unsupported CPU)")
|
|
state = .unavailable
|
|
return
|
|
}
|
|
Log.ndi.info("NDI \(NDI.version, privacy: .public)")
|
|
|
|
guard let finder = NDIFinder() else {
|
|
Log.ndi.error("Could not create NDI finder")
|
|
state = .unavailable
|
|
return
|
|
}
|
|
self.finder = finder
|
|
state = .searching
|
|
|
|
Task { [weak self] in
|
|
for await list in finder.sources {
|
|
self?.sources = list.sorted { $0.ndiName.localizedStandardCompare($1.ndiName) == .orderedAscending }
|
|
}
|
|
}
|
|
}
|
|
}
|