Skip to content

node-av / lib / Device

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 ​

typescript
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() ​

static audioModes(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 ​

typescript
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() ​

static audioModesSync(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 ​

AudioDeviceMode[]

Array of supported audio device modes

Example ​

typescript
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() ​

static getAudioFormat(): string

Defined in: src/lib/device.ts:336

Get platform-specific audio input format name.

Returns ​

string

Format name for FFmpeg input

PlatformFormat
macOSavfoundation
Linuxalsa
Windowsdshow

Example ​

typescript
const format = Device.getAudioFormat(); // 'avfoundation' on macOS

getScreenFormat() ​

static getScreenFormat(): string

Defined in: src/lib/device.ts:356

Get platform-specific screen capture format name.

Returns ​

string

Format name for FFmpeg input

PlatformFormat
macOSavfoundation
Linuxx11grab
Windowsgdigrab

Example ​

typescript
const format = Device.getScreenFormat(); // 'avfoundation' on macOS

getVideoFormat() ​

static getVideoFormat(): string

Defined in: src/lib/device.ts:316

Get platform-specific video input format name.

Returns ​

string

Format name for FFmpeg input

PlatformFormat
macOSavfoundation
Linuxv4l2
Windowsdshow

Example ​

typescript
const format = Device.getVideoFormat();
// Use with Demuxer.open(deviceName, { format })

hasScreenCapturePermission() ​

static hasScreenCapturePermission(): 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 ​

typescript
if (Device.hasScreenCapturePermission()) {
  console.log('Screen capture is permitted');
} else {
  console.log('Screen capture permission not granted');
}

list() ​

static list(): 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 ​

typescript
const devices = await Device.list();
const cameras = devices.filter(d => d.type === 'video');
const microphones = devices.filter(d => d.type === 'audio');

listSync() ​

static listSync(): DeviceInfo[]

Defined in: src/lib/device.ts:155

List all available capture devices synchronously.

Returns ​

DeviceInfo[]

Array of device information

Example ​

typescript
const devices = Device.listSync();

See ​

list For async version


modes() ​

static modes(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 ​

typescript
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() ​

static modesSync(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 ​

DeviceMode[]

Array of supported device modes

Example ​

typescript
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() ​

static requestScreenCaptureAccess(): 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 ​

typescript
const granted = Device.requestScreenCaptureAccess();
if (granted) {
  console.log('Screen capture permission already granted');
} else {
  console.log('Screen capture permission dialog shown to user');
}