Class: Device
Defined in: src/lib/device.ts:101
Low-level device enumeration and format detection.
Provides direct access to system capture devices (cameras, microphones) and platform-specific input format names for FFmpeg.
Direct mapping to platform-specific APIs:
- macOS: AVFoundation
- Linux: V4L2/ALSA
- Windows: DirectShow
Example
import { Device } from 'node-av/lib';
// List all capture devices
const devices = await Device.list();
for (const device of devices) {
console.log(`[${device.type}] ${device.name}: ${device.description}`);
}
// Get platform-specific format names
console.log(`Video format: ${Device.getVideoFormat()}`);
console.log(`Audio format: ${Device.getAudioFormat()}`);
console.log(`Screen format: ${Device.getScreenFormat()}`);See
DeviceInfo For device structure
Constructors
Constructor
new Device():
Device
Returns
Device
Methods
audioModes()
staticaudioModes(deviceName):Promise<AudioDeviceMode[]>
Defined in: src/lib/device.ts:262
Query supported audio capture modes for an audio device.
Returns supported sample rates, channel counts and sample formats for the specified device. Modes are sorted descending by sample rate, then by channel count.
Parameters
deviceName
string
Device name as returned by list() (e.g. uniqueID on macOS, hw:0 on Linux)
Returns
Promise<AudioDeviceMode[]>
Array of supported audio device modes
Example
const devices = await Device.list();
const mic = devices.find(d => d.type === 'audio');
if (mic) {
const modes = await Device.audioModes(mic.name);
console.log('Supported audio modes:', modes);
}audioModesSync()
staticaudioModesSync(deviceName):AudioDeviceMode[]
Defined in: src/lib/device.ts:290
Query supported audio capture modes for an audio device synchronously.
Parameters
deviceName
string
Device name as returned by listSync()
Returns
Array of supported audio device modes
Example
const devices = Device.listSync();
const mic = devices.find(d => d.type === 'audio');
if (mic) {
const modes = Device.audioModesSync(mic.name);
console.log('Supported audio modes:', modes);
}See
audioModes For async version
getAudioFormat()
staticgetAudioFormat():string
Defined in: src/lib/device.ts:336
Get platform-specific audio input format name.
Returns
string
Format name for FFmpeg input
| Platform | Format |
|---|---|
| macOS | avfoundation |
| Linux | alsa |
| Windows | dshow |
Example
const format = Device.getAudioFormat(); // 'avfoundation' on macOSgetScreenFormat()
staticgetScreenFormat():string
Defined in: src/lib/device.ts:356
Get platform-specific screen capture format name.
Returns
string
Format name for FFmpeg input
| Platform | Format |
|---|---|
| macOS | avfoundation |
| Linux | x11grab |
| Windows | gdigrab |
Example
const format = Device.getScreenFormat(); // 'avfoundation' on macOSgetVideoFormat()
staticgetVideoFormat():string
Defined in: src/lib/device.ts:316
Get platform-specific video input format name.
Returns
string
Format name for FFmpeg input
| Platform | Format |
|---|---|
| macOS | avfoundation |
| Linux | v4l2 |
| Windows | dshow |
Example
const format = Device.getVideoFormat();
// Use with Demuxer.open(deviceName, { format })hasScreenCapturePermission()
statichasScreenCapturePermission():boolean
Defined in: src/lib/device.ts:377
Check if the application has screen capture permission (macOS only).
Uses CGPreflightScreenCaptureAccess() on macOS 11+. Always returns true on Linux, Windows, and macOS < 11.
Returns
boolean
true if screen capture is permitted
Example
if (Device.hasScreenCapturePermission()) {
console.log('Screen capture is permitted');
} else {
console.log('Screen capture permission not granted');
}list()
staticlist():Promise<DeviceInfo[]>
Defined in: src/lib/device.ts:117
List all available capture devices.
Enumerates video and audio capture devices on the system. Uses platform-specific APIs for device discovery.
Returns
Promise<DeviceInfo[]>
Array of device information
Example
const devices = await Device.list();
const cameras = devices.filter(d => d.type === 'video');
const microphones = devices.filter(d => d.type === 'audio');listSync()
staticlistSync():DeviceInfo[]
Defined in: src/lib/device.ts:155
List all available capture devices synchronously.
Returns
Array of device information
Example
const devices = Device.listSync();See
list For async version
modes()
staticmodes(deviceName):Promise<DeviceMode[]>
Defined in: src/lib/device.ts:201
Query supported capture modes for a video device.
Returns supported resolutions and frame rate ranges for the specified device. Modes are sorted descending by resolution (area), then by max frame rate.
Parameters
deviceName
string
Device name as returned by list() (e.g. uniqueID on macOS, /dev/video0 on Linux)
Returns
Promise<DeviceMode[]>
Array of supported device modes
Example
const devices = await Device.list();
const camera = devices.find(d => d.type === 'video');
if (camera) {
const modes = await Device.modes(camera.name);
console.log('Supported modes:', modes);
}modesSync()
staticmodesSync(deviceName):DeviceMode[]
Defined in: src/lib/device.ts:231
Query supported capture modes for a video device synchronously.
Parameters
deviceName
string
Device name as returned by listSync()
Returns
Array of supported device modes
Example
const devices = Device.listSync();
const camera = devices.find(d => d.type === 'video');
if (camera) {
const modes = Device.modesSync(camera.name);
console.log('Supported modes:', modes);
}See
modes For async version
requestScreenCaptureAccess()
staticrequestScreenCaptureAccess():boolean
Defined in: src/lib/device.ts:400
Request screen capture permission from the user (macOS only).
Uses CGRequestScreenCaptureAccess() on macOS 11+. This will trigger the system permission dialog if not already granted. Always returns true on Linux, Windows, and macOS < 11.
Returns
boolean
true if permission was already granted (does not wait for dialog)
Example
const granted = Device.requestScreenCaptureAccess();
if (granted) {
console.log('Screen capture permission already granted');
} else {
console.log('Screen capture permission dialog shown to user');
}