Namespace `Devices` under `Aperture`

This commit is contained in:
Sindre Sorhus 2020-02-14 18:53:01 +07:00
parent 5f80b523c1
commit 5e4c311540
2 changed files with 29 additions and 28 deletions

View File

@ -22,7 +22,6 @@ public final class Aperture: NSObject {
public var onResume: (() -> Void)?
public var isRecording: Bool { output.isRecording }
public var isPaused: Bool { output.isRecordingPaused }
public let devices = Devices.self
private init(
destination: URL,
@ -80,7 +79,7 @@ public final class Aperture: NSObject {
/**
Start a capture session with the given screen ID.
Use `Aperture.devices.screen()` to get a list of available screens.
Use `Aperture.Devices.screen()` to get a list of available screens.
Then pass the `id` property from those dictionaries to this initializer to start recording.
@ -126,7 +125,7 @@ public final class Aperture: NSObject {
/**
Start a capture session with the given iOS device.
Use `Aperture.devices.iOS()` to get a list of connected iOS devices.
Use `Aperture.Devices.iOS()` to get a list of connected iOS devices.
Use the `id` property from those dictionaries to create an `AVCaptureDevice` like in the following example:

View File

@ -14,37 +14,39 @@ private func enableDalDevices() {
CMIOObjectSetPropertyData(CMIOObjectID(kCMIOObjectSystemObject), &property, 0, nil, UInt32(sizeOfAllow), &allow)
}
public struct Devices {
public static func screen() -> [[String: Any]] {
NSScreen.screens.map {
[
// TODO: Use `NSScreen#localizedName` when targeting macOS 10.15.
"name": $0.name,
"id": $0.id
]
extension Aperture {
public struct Devices {
public static func screen() -> [[String: Any]] {
NSScreen.screens.map {
[
// TODO: Use `NSScreen#localizedName` when targeting macOS 10.15.
"name": $0.name,
"id": $0.id
]
}
}
}
public static func audio() -> [[String: String]] {
AVCaptureDevice.devices(for: .audio).map {
[
"name": $0.localizedName,
"id": $0.uniqueID
]
}
}
public static func ios() -> [[String: String]] {
enableDalDevices()
return AVCaptureDevice
.devices(for: .muxed)
.filter { $0.localizedName.contains("iPhone") || $0.localizedName.contains("iPad") }
.map {
public static func audio() -> [[String: String]] {
AVCaptureDevice.devices(for: .audio).map {
[
"name": $0.localizedName,
"id": $0.uniqueID
]
}
}
public static func ios() -> [[String: String]] {
enableDalDevices()
return AVCaptureDevice
.devices(for: .muxed)
.filter { $0.localizedName.contains("iPhone") || $0.localizedName.contains("iPad") }
.map {
[
"name": $0.localizedName,
"id": $0.uniqueID
]
}
}
}
}