mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 01:50:47 -04:00
service live configslop
This commit is contained in:
@@ -8,7 +8,7 @@ module.exports = {
|
||||
feature: true,
|
||||
defaultValue: { enabled: false, captureCooldownMs: 10000 },
|
||||
schema: strictObject({
|
||||
enabled: boolean({ description: 'Starts the Kinect worker and exposes authorized frame capture after restart.' }),
|
||||
enabled: boolean({ description: 'Immediately starts the Kinect worker and exposes authorized frame capture.' }),
|
||||
captureCooldownMs: integer({ description: 'Minimum milliseconds between accepted Kinect frame-capture requests across all clients.', minimum: 0, maximum: 3600000 }),
|
||||
}, {
|
||||
title: 'Kinect',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Kinect Service
|
||||
// Purpose: Composes Kinect hardware capture and browser socket delivery.
|
||||
// Scope: Exposes session-readable state while keeping startup side effects in this service folder.
|
||||
const { loadConfig } = require('../../configuration');
|
||||
const { loadConfig, registerConfigurationHandler } = require('../../configuration');
|
||||
const hardware = require('./hardware');
|
||||
const { registerKinectSocketGateway, kinectEvents } = require('./socketGateway');
|
||||
|
||||
@@ -11,6 +11,10 @@ const gateway = registerKinectSocketGateway({
|
||||
hardware,
|
||||
});
|
||||
|
||||
registerConfigurationHandler('kinect', (kinectConfig) => {
|
||||
gateway.reconfigure({ kinect: kinectConfig || {} });
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
getState: gateway.getState,
|
||||
kinectEvents,
|
||||
|
||||
@@ -33,7 +33,7 @@ function normalizeKinectConfig(config = {}) {
|
||||
}
|
||||
|
||||
function registerKinectSocketGateway({ config, hardware }) {
|
||||
const settings = normalizeKinectConfig(config);
|
||||
let settings = normalizeKinectConfig(config);
|
||||
let captureCooldownUntil = 0;
|
||||
let busy = false;
|
||||
let lastAction = null;
|
||||
@@ -206,8 +206,31 @@ function registerKinectSocketGateway({ config, hardware }) {
|
||||
}
|
||||
}
|
||||
|
||||
function reconfigure(nextConfig) {
|
||||
const previousEnabled = settings.enabled;
|
||||
settings = normalizeKinectConfig(nextConfig);
|
||||
lastError = null;
|
||||
|
||||
// The native worker is the Kinect service's complete hardware runtime.
|
||||
// Restarting only when the enabled state changes avoids interrupting an
|
||||
// unrelated cooldown edit while still making enable/disable immediate.
|
||||
if (previousEnabled && !settings.enabled) {
|
||||
hardware.stopWorker();
|
||||
busy = false;
|
||||
} else if (!previousEnabled && settings.enabled) {
|
||||
try {
|
||||
hardware.startWorker();
|
||||
} catch (err) {
|
||||
lastError = err.message || 'kinect worker failed to start';
|
||||
logger.warn('Kinect worker startup failed after configuration change', { err: lastError });
|
||||
}
|
||||
}
|
||||
emitStatusChange();
|
||||
}
|
||||
|
||||
return {
|
||||
getState: buildStatus,
|
||||
reconfigure,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user