A modern, fully-typed TypeScript library for controlling Reolink cameras and NVRs
This project implements Reolinkβs private Baichuan API β the same API used by the official Reolink iOS/Android apps and the Reolink CLI. The implementation is informed by and based on the excellent Python project reolink-aio.
Features β’ Installation β’ Quick Start β’ Examples β’ API β’ TODO
- β Full TypeScript Support - Complete type safety and IntelliSense
- β HTTP API Client - Comprehensive REST API implementation
- β Baichuan API/Protocol - Implements Reolinkβs Baichuan API (same as official apps/CLI); real-time push events via TCP
- β NVR & Camera Support - Works with both standalone cameras and NVR systems
- β VOD (Video on Demand) - Search, browse, and download recorded clips
- β Session Management - Automatic token refresh and connection handling
- β Optimization - Connection pooling, request batching, and response caching
- β Error Handling - Rich exception hierarchy for robust error management
- β Motion Detection - Real-time motion alerts via Baichuan
- β AI Detection - Person, vehicle, pet/animal, face, and package detection
- β Visitor Detection - Doorbell button press events
- β State Monitoring - Continuous monitoring of camera states
- β Event Subscription - Subscribe to push notifications
- β VOD File Search - Find recordings by time range and event type
- β Video Download - Download MP4 clips from NVR/cameras
- β Multiple Streams - Support for main and sub streams
- β Stream URLs - Generate FLV, RTMP, and RTSP URLs
- β Snapshot Capture - Get still images from cameras
- β IR Lights - Control infrared illumination
- β Spotlight - Toggle camera spotlight with brightness control
- β Siren - Activate camera siren/audio alarm (fully working!)
- β Focus Control - Set camera focus position
- β Zoom Control - Set camera zoom position
- β PTZ Control - Pan/Tilt/Zoom operations with presets, patrols, guard positions, and auto-tracking
- β Device Discovery - Automatic NVR/camera detection
- β Channel Management - Multi-channel support for NVRs
- β Capability Detection - Automatic feature detection
- β Model Information - Device model, firmware, hardware version
- β Network Settings - Port configuration (RTSP, RTMP, ONVIF)
npm install reolink-aio@nextNote: This package is currently a pre-release. Interfaces and behavior may change between versions. For stability, pin an exact version or wait for a 1.0.0 stable release.
import { Host } from 'reolink-aio';
const host = new Host('192.168.1.100', 'admin', 'your-password');
// Connect and fetch device information
await host.getHostData();
console.log(`Connected to: ${host.nvrName}`);
console.log(`Channels: ${host.channelsValue.length}`);import { Host } from 'reolink-aio';
const host = new Host('192.168.1.100', 'admin', 'your-password');
await host.getHostData();
// Control IR lights (Auto mode enables IR, Off disables it)
await host.setIrLights(0, true); // Enable IR lights
await host.setIrLights(0, false); // Disable IR lights
// Control spotlight/floodlight
await host.setSpotlight(0, true); // Turn on at current brightness
await host.setSpotlight(0, true, 75); // Turn on at 75% brightness
await host.setSpotlight(0, false); // Turn off
// Control siren/audio alarm
await host.setSiren(0, true, 2); // Sound siren for 2 seconds
await host.setSiren(0, false); // Stop siren immediately
// Control zoom and focus (for cameras that support it)
await host.setZoom(0, 16); // Set zoom position (0-33 typically)
await host.setFocus(0, 128); // Set focus position (0-255 typically)
// PTZ control (for cameras with Pan/Tilt/Zoom)
await host.ptzControl(0, 'Left', undefined, 32); // Move left at speed 32
await host.gotoPreset(0, 'Home'); // Go to preset position
await host.startPatrol(0); // Start auto patrol
await host.setPtzGuard(0, 'set'); // Set current position as guard
await host.setAutoTracking(0, true); // Enable auto-trackingimport { Host } from 'reolink-aio';
const host = new Host('192.168.1.100', 'admin', 'your-password');
await host.getHostData();
// Subscribe to events
await host.baichuan.subscribeEvents();
// Monitor motion states
setInterval(async () => {
await host.getStates();
for (const channel of host.channelsValue) {
if (host.motionDetected(channel)) {
console.log(`β οΈ Motion on ${host.cameraName(channel)}!`);
}
if (host.aiDetected(channel, 'person')) {
console.log(`π€ Person detected!`);
}
}
}, 2000);import { Host } from 'reolink-aio';
import * as fs from 'fs';
const host = new Host('192.168.1.100', 'admin', 'your-password');
await host.getHostData();
// Search for recordings
const startTime = new Date(Date.now() - 3600000); // 1 hour ago
const endTime = new Date();
const clips = await host.requestVodFiles(0, startTime, endTime, true);
// Download the first clip
if (clips.length > 0) {
const result = await host.downloadVod(
0,
clips[0].startTime,
clips[0].endTime,
'sub'
);
fs.writeFileSync('recording.mp4', new Uint8Array(result.data));
console.log(`Downloaded: ${(result.data.byteLength / 1024 / 1024).toFixed(2)} MB`);
}The examples/ directory contains complete, working examples:
| Example | Description | Difficulty |
|---|---|---|
| 01-basic-connection.ts | Connect to camera and display info | π’ Beginner |
| 02-get-video-clips.ts | Search and list VOD recordings | π’ Beginner |
| 03-motion-monitor.ts | Real-time motion/AI detection | π‘ Intermediate |
| 04-download-clips.ts | Download MP4 clips from NVR | π‘ Intermediate |
| 05-event-webhook.ts | Webhook event receiver | π΄ Advanced |
| 06-scheduled-backup.ts | Automated backup system | π΄ Advanced |
| 07-device-control.ts | Control IR, spotlight, siren, zoom | π’ Beginner |
| 08-ptz-control.ts | PTZ movement, presets, patrols, tracking | π‘ Intermediate |
| 09-live-streaming.ts | Live stream URLs, snapshots, encoding | π’ Beginner |
| 10-optimization.ts | Performance optimization features | π’ Beginner |
# Update credentials in the example file first
npx tsx examples/01-basic-connection.ts
# Enable debug logging
REOLINK_AIO_DEBUG=1 npx tsx examples/03-motion-monitor.tsThe main class for interacting with Reolink devices.
new Host(
host: string, // IP address or hostname
username: string, // Username
password: string, // Password
port?: number, // HTTP port (default: 80 or 443)
useHttps?: boolean, // Use HTTPS (default: auto-detect)
protocol?: string, // Stream protocol (default: 'rtmp')
stream?: string, // Stream quality (default: 'sub')
timeout?: number // Request timeout in seconds (default: 60)
)getHostData()- Fetch and cache device informationgetStates()- Update current states (motion, AI detection, etc.)login()- Manually login (usually automatic)logout()- Logout and end session
motionDetected(channel)- Check if motion detectedaiDetected(channel, objectType)- Check AI detection- Supported types:
'person','vehicle','dog_cat','face','package'
- Supported types:
visitorDetected(channel)- Check if doorbell pressedirEnabled(channel)- Check if IR lights enabled
setIrLights(channel, enabled)- Control IR illuminationsetSpotlight(channel, enabled, brightness?)- Control spotlight/floodlightsetSiren(channel, enabled, duration?)- Activate siren/audio alarmsetFocus(channel, position)- Set focus position (0-255)setZoom(channel, position)- Set zoom position (0-33 typically)
ptzControl(channel, command?, preset?, speed?, patrol?)- Manual PTZ controlgotoPreset(channel, preset)- Move to preset positiongetPtzPresets(channel)- Get available presetsgetPtzPatrols(channel)- Get available patrolsstartPatrol(channel)- Start auto patrolstopPatrol(channel)- Stop auto patrolgetPtzPanPosition(channel)- Get current pan positiongetPtzTiltPosition(channel)- Get current tilt positionisPtzGuardEnabled(channel)- Check if guard enabledgetPtzGuardTime(channel)- Get guard return timesetPtzGuard(channel, command?, enable?, time?)- Configure guard positionptzCalibrate(channel)- Calibrate PTZisAutoTrackingEnabled(channel)- Check if auto-tracking enabledsetAutoTracking(channel, enable?, disappearTime?, stopTime?, method?)- Configure auto-trackinggetAutoTrackMethod(channel)- Get tracking methodgetAutoTrackLimitLeft(channel)- Get left limitgetAutoTrackLimitRight(channel)- Get right limitsetAutoTrackLimit(channel, left?, right?)- Set tracking limits
getOsdSettings(channel)- Get OSD (On-Screen Display) settingssetOsd(channel, namePos?, datePos?, enableWaterMark?)- Set OSD parametersgetRecordingSettings(channel)- Get recording settingssetRecording(channel, enable)- Enable/disable recordinggetMdAlarmSettings(channel)- Get motion detection settingssetMotionDetection(channel, enable)- Enable/disable motion detectionsetMdSensitivity(channel, value)- Set motion detection sensitivity (1-50)getAiAlarmSettings(channel, aiType?)- Get AI detection settingssetAiSensitivity(channel, value, aiType)- Set AI detection sensitivity (0-100)setAiDelay(channel, value, aiType)- Set AI detection delay (0-8 seconds)getFtpSettings(channel)- Get FTP settingssetFtp(channel, enable)- Enable/disable FTP uploadgetEmailSettings(channel)- Get email settingssetEmail(channel, enable)- Enable/disable email notificationsgetPushSettings(channel)- Get push notification settingssetPush(channel, enable)- Enable/disable push notificationsgetBuzzerSettings(channel)- Get buzzer alarm settingssetBuzzer(channel, enable)- Enable/disable buzzer alarmgetNetworkSettings()- Get network port settings
getStreamSource(channel, stream?, check?)- Get live stream URL (auto-selects protocol)getRtspStreamSource(channel, stream?, check?)- Get RTSP stream URLgetRtmpStreamSource(channel, stream?)- Get RTMP stream URLgetFlvStreamSource(channel, stream?)- Get FLV stream URLgetSnapshot(channel, stream?)- Capture still image/snapshotgetEncoding(channel, stream?)- Get video encoding (h264/h265)encoding(channel, stream?)- Get cached encoding
nvrName- Device nameisNvrValue- Is NVR?channelsValue- Active channelscameraName(channel)- Get camera namecameraModel(channel)- Get camera model
-
Device Control Commands
-
setIrLights()- Control IR illumination -
setSpotlight()- Toggle spotlight -
setSiren()- Activate siren (fully working!) -
setFocus()- Focus control -
setZoom()- Digital zoom
-
-
PTZ (Pan/Tilt/Zoom)
-
ptzControl()- Manual PTZ movement -
getPtzPresets()- List presets -
gotoPreset()- Move to preset -
startPatrol()/stopPatrol()- Auto patrol -
setPtzGuard()- Guard position control -
setAutoTracking()- Auto-tracking configuration - Position getters and patrol management
-
-
Video Streaming
-
getStreamSource()- Get live stream URL -
getRtspStreamSource()- RTSP URLs -
getRtmpStreamSource()- RTMP URLs -
getFlvStreamSource()- FLV URLs -
getSnapshot()- Still image capture -
getEncoding()- Detect video encoding - Stream quality switching
- Multi-stream support
-
-
Advanced Features
-
subscribe()- Webhook subscriptions - Privacy mode detection
- Audio support (two-way)
-
-
Configuration Management
- Get/Set OSD settings
- Get/Set recording schedules
- Get/Set motion detection settings and sensitivity
- Get/Set AI detection settings, sensitivity, and delay
- Get/Set FTP configuration
- Get/Set email notifications
- Get/Set push notifications
- Get/Set buzzer alarm
- Get network configuration
-
Optimization
- Connection pooling
- Request batching
- Caching layer
-
Testing
- Integration tests
- Mock device server
- Code coverage > 80%
-
Documentation
- API docs site
- Video tutorials
- Migration guide
- Basic HTTP API client
- Baichuan event protocol
- Device information retrieval
- Motion/AI detection monitoring
- VOD file search and listing
- VOD file download (NVR)
- Stream URL generation
- Session management
- TypeScript types
- Working examples
- NVR detection
- Multi-channel support
- Device control commands (IR, spotlight, siren, focus, zoom)
- PTZ control (movement, presets, patrols, guard, auto-tracking)
- Live streaming (RTSP, RTMP, FLV URLs)
- Snapshot capture
- Video encoding detection
- Baichuan TCP protocol fixes (XML formatting, future cleanup)
MIT Β© starkillerOG
- Based on the Python reolink_aio library
- Thanks to the Reolink developer community