Run manual tests for is-camera-on
mainYou can run the included manual tests using the Swift CLI to verify camera detection and async monitoring functionality.
swift run TestCamera
swift run TestAsyncCamerarepository·main·Indexed 40 days ago
https://github.com/sindresorhus/is-camera-onA Swift module for macOS 10.15 or later that detects whether a built-in or external camera is currently in use. It provides the isCameraOn() function for synchronous checks and cameraStatusChanges() for asynchronous monitoring of camera status changes via an AsyncSequence.
You can run the included manual tests using the Swift CLI to verify camera detection and async monitoring functionality.
swift run TestCamera
swift run TestAsyncCameraAdd the package dependency to your Package.swift file to use this module in your Swift project. Requires macOS 10.15 or later.
.package(url: "https://github.com/sindresorhus/is-camera-on", from: "3.0.0")Use cameraStatusChanges() to receive real-time updates when the camera status changes. This function returns an AsyncSequence that can be iterated using for await within a Task or async context.
Key behaviors:
import IsCameraOn
// Monitor camera status changes with async/await
Task {
for await isOn in cameraStatusChanges() {
print("Camera status: \(isOn ? "ON" : "OFF")")
}
}Use isCameraOn() to check if a Mac camera is currently active. By default, it only checks built-in cameras (like FaceTime HD or iSight). You can pass includeExternal: true to include external physical cameras (USB, Thunderbolt, Continuity Camera, etc.) in the check.
import IsCameraOn
// Check built-in camera only (default)
print(isCameraOn())
// Check both built-in and external physical cameras
print(isCameraOn(includeExternal: true))