is-camera-on

repository·main·Indexed 40 days ago

https://github.com/sindresorhus/is-camera-on

A 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.

Tokens
515
Snippets
4
Records
4
Agent score
50%

What's inside is-camera-on

  1. Monitor camera status changes with cameraStatusChanges()

    main

    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:

    • Emits the current status immediately upon subscription.
    • Emits subsequent values only when the status changes.
    • Automatically handles device hot-plugging (connecting/disconnecting cameras).
    • Uses property listeners for real-time updates instead of polling.
    import IsCameraOn
    
    // Monitor camera status changes with async/await
    Task {
    	for await isOn in cameraStatusChanges() {
    		print("Camera status: \(isOn ? "ON" : "OFF")")
    	}
    }
  2. Check camera status with isCameraOn()

    main

    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))