Skip to content

Commit

Permalink
Namespace Devices under Aperture
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 14, 2020
1 parent 5f80b52 commit 5e4c311
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
5 changes: 2 additions & 3 deletions Sources/Aperture/Aperture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:

Expand Down
52 changes: 27 additions & 25 deletions Sources/Aperture/Devices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
}
}

public static func audio() -> [[String: String]] {
AVCaptureDevice.devices(for: .audio).map {
[
"name": $0.localizedName,
"id": $0.uniqueID
]
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 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
]
}
}
}
}

0 comments on commit 5e4c311

Please sign in to comment.