UNPKG

logitech-brio-zoom-control

Version:

Cross-platform native library for controlling Logitech MX Brio camera zoom with 4K video support in Electron applications

220 lines (203 loc) 6.73 kB
let brioZoomControl; try { brioZoomControl = require('./build/Release/brio_zoom_control.node'); } catch (error) { throw new Error( 'Native addon not found. Please ensure you have:\n' + '1. Installed build tools for your platform (see BUILD.md)\n' + '2. Run "npm install" to build the native addon\n' + '3. For Windows: Visual Studio Build Tools\n' + '4. For Linux: build-essential and libv4l-dev\n' + '5. For macOS: Xcode Command Line Tools\n\n' + 'Original error: ' + error.message ); } /** * Logitech MX Brio Zoom Control Library for Electron * * This library provides native camera zoom control for Logitech MX Brio cameras * across Windows (DirectShow), Linux (V4L2), and macOS (AVFoundation) platforms. */ class LogitechBrioZoomControl { constructor() { this.initialized = false; this.currentDevice = null; } /** * Discover available Logitech BRIO devices * @returns {Array} Array of device objects with name, id, vendorId, productId */ discoverDevices() { try { return brioZoomControl.discoverDevices(); } catch (error) { throw new Error(`Failed to discover devices: ${error.message}`); } } /** * Initialize a specific device for zoom control * @param {string} deviceId - Device ID from discoverDevices() * @returns {boolean} True if initialization successful */ initializeDevice(deviceId) { try { const success = brioZoomControl.initializeDevice(deviceId); if (success) { this.initialized = true; this.currentDevice = deviceId; } return success; } catch (error) { throw new Error(`Failed to initialize device: ${error.message}`); } } /** * Initialize the first available Logitech BRIO device * @returns {boolean} True if initialization successful */ initializeFirstDevice() { const devices = this.discoverDevices(); if (devices.length === 0) { throw new Error('No Logitech BRIO devices found'); } return this.initializeDevice(devices[0].id); } /** * Release the current device */ releaseDevice() { try { brioZoomControl.releaseDevice(); this.initialized = false; this.currentDevice = null; } catch (error) { throw new Error(`Failed to release device: ${error.message}`); } } /** * Get zoom capabilities of the current device * @returns {Object} Zoom capabilities including min, max, step, current, supports flags */ getZoomCapabilities() { this._checkInitialized(); try { const result = brioZoomControl.getZoomCapabilities(); if (!result.success) { throw new Error(result.error || 'Failed to get zoom capabilities'); } return { min: result.min, max: result.max, step: result.step, current: result.current, supportsAbsolute: result.supportsAbsolute, supportsRelative: result.supportsRelative }; } catch (error) { throw new Error(`Failed to get zoom capabilities: ${error.message}`); } } /** * Set absolute zoom value * @param {number} zoomValue - Zoom value (typically 100-500 for most devices) * @returns {boolean} True if zoom was set successfully */ setZoomAbsolute(zoomValue) { this._checkInitialized(); if (typeof zoomValue !== 'number') { throw new Error('Zoom value must be a number'); } try { return brioZoomControl.setZoomAbsolute(zoomValue); } catch (error) { throw new Error(`Failed to set absolute zoom: ${error.message}`); } } /** * Set relative zoom value (delta from current) * @param {number} zoomDelta - Change in zoom value (positive = zoom in, negative = zoom out) * @returns {boolean} True if zoom was set successfully */ setZoomRelative(zoomDelta) { this._checkInitialized(); if (typeof zoomDelta !== 'number') { throw new Error('Zoom delta must be a number'); } try { return brioZoomControl.setZoomRelative(zoomDelta); } catch (error) { throw new Error(`Failed to set relative zoom: ${error.message}`); } } /** * Get current zoom value * @returns {number} Current zoom value */ getZoomValue() { this._checkInitialized(); try { const result = brioZoomControl.getZoomValue(); if (!result.success) { throw new Error(result.error || 'Failed to get zoom value'); } return result.value; } catch (error) { throw new Error(`Failed to get zoom value: ${error.message}`); } } /** * Zoom in by a specific amount * @param {number} amount - Amount to zoom in (default: 10) * @returns {boolean} True if zoom was successful */ zoomIn(amount = 10) { return this.setZoomRelative(amount); } /** * Zoom out by a specific amount * @param {number} amount - Amount to zoom out (default: 10) * @returns {boolean} True if zoom was successful */ zoomOut(amount = 10) { return this.setZoomRelative(-amount); } /** * Reset zoom to minimum value * @returns {boolean} True if zoom was reset successfully */ resetZoom() { const capabilities = this.getZoomCapabilities(); return this.setZoomAbsolute(capabilities.min); } /** * Set zoom to maximum value * @returns {boolean} True if zoom was set successfully */ maxZoom() { const capabilities = this.getZoomCapabilities(); return this.setZoomAbsolute(capabilities.max); } /** * Check if device is initialized * @private */ _checkInitialized() { if (!this.initialized) { throw new Error('Device not initialized. Call initializeDevice() first.'); } } /** * Get library information * @returns {Object} Library version and platform info */ static getInfo() { return { name: 'logitech-brio-zoom-control', version: '1.0.0', platform: process.platform, arch: process.arch, nodeVersion: process.version }; } } module.exports = LogitechBrioZoomControl;