This commit is contained in:
legop3
2025-11-15 14:00:09 -05:00
parent 248fe3eef1
commit e3a0161ba6
+4 -3
View File
@@ -37,7 +37,8 @@ module.exports = {
}; };
io.on('connection', (socket) => { io.on('connection', (socket) => {
function handleCommand({ roverId, type, data } = {}, cb = () => {}) { function handleCommand({ roverId, type, data } = {}, cb) {
const reply = typeof cb === 'function' ? cb : () => {};
try { try {
if (!roverId) { if (!roverId) {
throw new Error('roverId required'); throw new Error('roverId required');
@@ -48,10 +49,10 @@ io.on('connection', (socket) => {
const payload = data ? { ...data } : {}; const payload = data ? { ...data } : {};
const id = issueCommand(roverId, { type, ...payload }); const id = issueCommand(roverId, { type, ...payload });
logger.info('Queued command', socket.id, roverId, type); logger.info('Queued command', socket.id, roverId, type);
cb({ id }); reply({ id });
} catch (err) { } catch (err) {
logger.warn('Command rejected', socket.id, err.message); logger.warn('Command rejected', socket.id, err.message);
cb({ error: err.message }); reply({ error: err.message });
} }
} }