├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── Package.resolved ├── Package.swift ├── Sources └── IsCameraOnCLI │ └── main.swift ├── index.js ├── is-camera-on ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: macos-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 16 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v2 17 | with: 18 | node-version: ${{ matrix.node-version }} 19 | - run: npm install 20 | - run: npm test 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | /.build 4 | /*.xcodeproj 5 | /main 6 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "IsCameraOn", 6 | "repositoryURL": "https://github.com/sindresorhus/is-camera-on", 7 | "state": { 8 | "branch": null, 9 | "revision": "dee6e81e863efe717e7a5149db53df760a311320", 10 | "version": "2.0.2" 11 | } 12 | } 13 | ] 14 | }, 15 | "version": 1 16 | } 17 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "IsCameraOnCLI", 6 | platforms: [ 7 | .macOS(.v10_11) 8 | ], 9 | products: [ 10 | .executable( 11 | name: "is-camera-on", 12 | targets: [ 13 | "IsCameraOnCLI" 14 | ] 15 | ) 16 | ], 17 | dependencies: [ 18 | .package( 19 | url: "https://github.com/sindresorhus/is-camera-on", 20 | from: "2.0.2" 21 | ) 22 | ], 23 | targets: [ 24 | .executableTarget( 25 | name: "IsCameraOnCLI", 26 | dependencies: [ 27 | .product( 28 | name: "IsCameraOn", 29 | package: "is-camera-on" 30 | ) 31 | ] 32 | ) 33 | ] 34 | ) 35 | -------------------------------------------------------------------------------- /Sources/IsCameraOnCLI/main.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import IsCameraOn 3 | 4 | print(isCameraOn()) 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import {fileURLToPath} from 'node:url'; 3 | import {assertMacOSVersionGreaterThanOrEqualTo} from 'macos-version'; 4 | import {execa} from 'execa'; 5 | 6 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); 7 | 8 | const binaryPath = path.join(__dirname, 'is-camera-on'); 9 | 10 | export default async function isCameraOn() { 11 | assertMacOSVersionGreaterThanOrEqualTo('10.11'); 12 | const {stdout} = await execa(binaryPath); 13 | return stdout === 'true'; 14 | } 15 | -------------------------------------------------------------------------------- /is-camera-on: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sindresorhus/node-is-camera-on/2d0e5a3dcb20571cccbfd45e0fe28b0498750e11/is-camera-on -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-camera-on", 3 | "version": "3.1.0", 4 | "description": "Check if the built-in Mac camera is on", 5 | "license": "MIT", 6 | "repository": "sindresorhus/node-is-camera-on", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": "./index.js", 15 | "engines": { 16 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava", 20 | "build": "swift build --configuration=release --arch arm64 --arch x86_64 && mv .build/apple/Products/Release/is-camera-on .", 21 | "prepare": "npm run build" 22 | }, 23 | "files": [ 24 | "index.js", 25 | "is-camera-on" 26 | ], 27 | "keywords": [ 28 | "macos", 29 | "camera", 30 | "webcam", 31 | "cam", 32 | "builtin", 33 | "built-in", 34 | "internal", 35 | "status", 36 | "on", 37 | "off", 38 | "enabled", 39 | "disabled", 40 | "used", 41 | "swift" 42 | ], 43 | "dependencies": { 44 | "execa": "^6.0.0", 45 | "macos-version": "^6.0.0" 46 | }, 47 | "devDependencies": { 48 | "ava": "^4.0.1", 49 | "xo": "^0.47.0" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # is-camera-on 2 | 3 | > Check if the built-in Mac camera is on 4 | 5 | ## Install 6 | 7 | ```sh 8 | npm install is-camera-on 9 | ``` 10 | 11 | Requires macOS 10.11 or later. 12 | 13 | ## Usage 14 | 15 | ```js 16 | import isCameraOn from 'is-camera-on'; 17 | 18 | console.log(await isCameraOn()); 19 | //=> true 20 | ``` 21 | 22 | ## Related 23 | 24 | - [is-camera-on-cli](https://github.com/sindresorhus/is-camera-on-cli) - CLI for this module 25 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import isCameraOn from './index.js'; 3 | 4 | test('main', async t => { 5 | const isOn = await isCameraOn(); 6 | t.is(typeof isOn, 'boolean'); 7 | console.log(`Camera is ${isOn ? 'on' : 'off'}`); 8 | }); 9 | --------------------------------------------------------------------------------