logitech-brio-zoom-control
Version:
Cross-platform native library for controlling Logitech MX Brio camera zoom with 4K video support in Electron applications
165 lines (143 loc) • 4.07 kB
JavaScript
// Electron Main Process Example
// Save as: main.js
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const LogitechBrioZoomControl = require('../index.js');
let mainWindow;
let cameraControl;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
mainWindow.loadFile('index.html');
}
app.whenReady().then(() => {
// Initialize camera control
cameraControl = new LogitechBrioZoomControl();
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
// Cleanup camera control
if (cameraControl) {
try {
cameraControl.releaseDevice();
} catch (error) {
console.error('Error releasing camera:', error);
}
}
if (process.platform !== 'darwin') {
app.quit();
}
});
// IPC handlers for camera control
ipcMain.handle('camera:discover', async () => {
try {
return cameraControl.discoverDevices();
} catch (error) {
console.error('Error discovering devices:', error);
return [];
}
});
ipcMain.handle('camera:initialize', async (event, deviceId) => {
try {
return cameraControl.initializeDevice(deviceId);
} catch (error) {
console.error('Error initializing device:', error);
return false;
}
});
ipcMain.handle('camera:initialize-first', async () => {
try {
return cameraControl.initializeFirstDevice();
} catch (error) {
console.error('Error initializing first device:', error);
return false;
}
});
ipcMain.handle('camera:release', async () => {
try {
cameraControl.releaseDevice();
return true;
} catch (error) {
console.error('Error releasing device:', error);
return false;
}
});
ipcMain.handle('camera:zoom:capabilities', async () => {
try {
return cameraControl.getZoomCapabilities();
} catch (error) {
console.error('Error getting zoom capabilities:', error);
return null;
}
});
ipcMain.handle('camera:zoom:set-absolute', async (event, zoomValue) => {
try {
return cameraControl.setZoomAbsolute(zoomValue);
} catch (error) {
console.error('Error setting absolute zoom:', error);
return false;
}
});
ipcMain.handle('camera:zoom:set-relative', async (event, zoomDelta) => {
try {
return cameraControl.setZoomRelative(zoomDelta);
} catch (error) {
console.error('Error setting relative zoom:', error);
return false;
}
});
ipcMain.handle('camera:zoom:get', async () => {
try {
return cameraControl.getZoomValue();
} catch (error) {
console.error('Error getting zoom value:', error);
return null;
}
});
ipcMain.handle('camera:zoom:in', async (event, amount = 10) => {
try {
return cameraControl.zoomIn(amount);
} catch (error) {
console.error('Error zooming in:', error);
return false;
}
});
ipcMain.handle('camera:zoom:out', async (event, amount = 10) => {
try {
return cameraControl.zoomOut(amount);
} catch (error) {
console.error('Error zooming out:', error);
return false;
}
});
ipcMain.handle('camera:zoom:reset', async () => {
try {
return cameraControl.resetZoom();
} catch (error) {
console.error('Error resetting zoom:', error);
return false;
}
});
ipcMain.handle('camera:zoom:max', async () => {
try {
return cameraControl.maxZoom();
} catch (error) {
console.error('Error setting max zoom:', error);
return false;
}
});
ipcMain.handle('library:info', async () => {
return LogitechBrioZoomControl.getInfo();
});