mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-18 18:40:47 -04:00
service live configslop
This commit is contained in:
@@ -8,7 +8,7 @@ module.exports = {
|
||||
feature: true,
|
||||
defaultValue: { enabled: false },
|
||||
schema: strictObject({
|
||||
enabled: boolean({ description: 'Registers barcode scanning, barcode administration, and scan-triggered server behavior after restart.' }),
|
||||
enabled: boolean({ description: 'Immediately enables barcode scanning, barcode administration, and scan-triggered server behavior.' }),
|
||||
}, {
|
||||
title: 'Barcode scanner',
|
||||
description: 'Optional physical barcode scanning and barcode registry service.',
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
const fs = require('fs');
|
||||
const io = require('../../globals/io');
|
||||
const logger = require('../../globals/logger').child('barcodeScannerService');
|
||||
const { loadConfig } = require('../../configuration');
|
||||
const { loadConfig, registerConfigurationHandler } = require('../../configuration');
|
||||
const { resolveDataDir, resolveDataPath } = require('../../helpers/dataPaths');
|
||||
const { getMode, MODES, modeEvents } = require('../modeManager');
|
||||
const { publishEvent } = require('../eventBus');
|
||||
@@ -15,7 +15,7 @@ const REGISTRY_PATH = resolveDataPath('barcode-registry.json');
|
||||
const RECENT_SCAN_LIMIT = 8;
|
||||
const VALID_CODE_PATTERN = /^[a-z][0-9]{3}$/;
|
||||
const SCANNER_SOCKET_ROOM = 'barcode-scanner';
|
||||
const enabled = Boolean(loadConfig().barcodeScanner?.enabled);
|
||||
let enabled = Boolean(loadConfig().barcodeScanner?.enabled);
|
||||
|
||||
let lastKnownGoodRegistry = null;
|
||||
let lastRegistryError = null;
|
||||
@@ -312,19 +312,16 @@ async function applyScan(rawCode) {
|
||||
return { result };
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
/*
|
||||
Barcode scanning is tied to a physical scanner station. Disabled installs
|
||||
should not create the registry file or expose scanner socket commands.
|
||||
*/
|
||||
io.on('connection', (socket) => {
|
||||
io.on('connection', (socket) => {
|
||||
socket.on('barcode:subscribe', (_payload = {}, cb = () => {}) => {
|
||||
if (!enabled) return cb({ error: 'barcode scanner disabled' });
|
||||
socket.join(SCANNER_SOCKET_ROOM);
|
||||
socket.emit('barcode:state', buildStatePayload());
|
||||
cb({ success: true, state: buildStatePayload() });
|
||||
});
|
||||
|
||||
socket.on('barcode:scan', async ({ code } = {}, cb = () => {}) => {
|
||||
if (!enabled) return cb({ error: 'barcode scanner disabled' });
|
||||
try {
|
||||
const { result } = await applyScan(code);
|
||||
cb({ success: true, result, state: buildStatePayload() });
|
||||
@@ -336,20 +333,28 @@ if (enabled) {
|
||||
cb({ error: err.message || 'barcode scan failed' });
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
modeEvents.on('change', () => {
|
||||
modeEvents.on('change', () => {
|
||||
// Access-mode changes affect whether the scanner page should beep when it
|
||||
// submits a code, so scanner clients need a fresh state packet even without a
|
||||
// new scan.
|
||||
broadcastState();
|
||||
});
|
||||
});
|
||||
|
||||
if (enabled) {
|
||||
loadRegistryForScan();
|
||||
} else {
|
||||
logger.info('Barcode scanner disabled by config');
|
||||
}
|
||||
|
||||
registerConfigurationHandler('barcodeScanner', (scannerConfig = {}) => {
|
||||
const wasEnabled = enabled;
|
||||
enabled = Boolean(scannerConfig.enabled);
|
||||
if (!wasEnabled && enabled) loadRegistryForScan();
|
||||
broadcastState();
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
REGISTRY_PATH,
|
||||
applyScan: (...args) => {
|
||||
|
||||
Reference in New Issue
Block a user