chore: auto-commit uncommitted changes
This commit is contained in:
parent
60a6d973f5
commit
d039be46a4
26
server.js
26
server.js
|
|
@ -23,6 +23,7 @@ const PROTOCOL_VERSION = 'clawdnode/1.0';
|
||||||
// Connected clients
|
// Connected clients
|
||||||
const clients = new Map();
|
const clients = new Map();
|
||||||
let commandQueue = [];
|
let commandQueue = [];
|
||||||
|
const pendingCommands = new Map(); // commandId -> { resolve, timer }
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
const logStream = fs.createWriteStream(LOG_FILE, { flags: 'a' });
|
const logStream = fs.createWriteStream(LOG_FILE, { flags: 'a' });
|
||||||
|
|
@ -92,7 +93,7 @@ function handleMessage(clientId, msg, ws) {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
code: 'WRONG_PROTOCOL',
|
code: 'WRONG_PROTOCOL',
|
||||||
message: 'This is ClawdNode Gateway (port 9878), not Clawdbot Gateway (port 18789). ' +
|
message: 'This is ClawdNode Gateway (port 9878), not Clawdbot Gateway (port 18789). ' +
|
||||||
'Update your app to use ws://100.123.216.65:9878 with ClawdNode protocol.',
|
'Update your app to use ws://0.0.0.0:9878 with ClawdNode protocol.',
|
||||||
expected: PROTOCOL_VERSION,
|
expected: PROTOCOL_VERSION,
|
||||||
received: msg.method || msg.type
|
received: msg.method || msg.type
|
||||||
}));
|
}));
|
||||||
|
|
@ -148,6 +149,12 @@ function handleMessage(clientId, msg, ws) {
|
||||||
case 'result':
|
case 'result':
|
||||||
log(`✅ [RESPONSE] Command ${msg.commandId}: ${msg.success ? 'OK' : 'FAILED'}`);
|
log(`✅ [RESPONSE] Command ${msg.commandId}: ${msg.success ? 'OK' : 'FAILED'}`);
|
||||||
if (msg.error) log(` Error: ${msg.error}`);
|
if (msg.error) log(` Error: ${msg.error}`);
|
||||||
|
const pending = pendingCommands.get(msg.commandId);
|
||||||
|
if (pending) {
|
||||||
|
clearTimeout(pending.timer);
|
||||||
|
pendingCommands.delete(msg.commandId);
|
||||||
|
pending.resolve(msg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'log':
|
case 'log':
|
||||||
|
|
@ -244,7 +251,18 @@ const httpServer = http.createServer(async (req, res) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const cmdId = sendCommand(body.command, body.params || {});
|
const cmdId = sendCommand(body.command, body.params || {});
|
||||||
res.end(JSON.stringify({ status: 'sent', commandId: cmdId, clients: clients.size }));
|
if (body.wait !== false) {
|
||||||
|
const response = await new Promise((resolve) => {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
pendingCommands.delete(cmdId);
|
||||||
|
resolve({ success: false, error: 'timeout', commandId: cmdId });
|
||||||
|
}, body.timeout || 10000);
|
||||||
|
pendingCommands.set(cmdId, { resolve, timer });
|
||||||
|
});
|
||||||
|
res.end(JSON.stringify(response));
|
||||||
|
} else {
|
||||||
|
res.end(JSON.stringify({ status: 'sent', commandId: cmdId, clients: clients.size }));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '/notification/action':
|
case '/notification/action':
|
||||||
|
|
@ -314,8 +332,8 @@ httpServer.listen(HTTP_PORT, '0.0.0.0', () => {
|
||||||
log('ClawdNode Gateway - Custom Protocol');
|
log('ClawdNode Gateway - Custom Protocol');
|
||||||
log(`Protocol: ${PROTOCOL_VERSION}`);
|
log(`Protocol: ${PROTOCOL_VERSION}`);
|
||||||
log('================================================');
|
log('================================================');
|
||||||
log(`HTTP API: http://100.123.216.65:${HTTP_PORT}`);
|
log(`HTTP API: http://0.0.0.0:${HTTP_PORT}`);
|
||||||
log(`WebSocket: ws://100.123.216.65:${WS_PORT}`);
|
log(`WebSocket: ws://0.0.0.0:${WS_PORT}`);
|
||||||
log(`Log file: ${LOG_FILE}`);
|
log(`Log file: ${LOG_FILE}`);
|
||||||
log('');
|
log('');
|
||||||
log('NOTE: This is NOT Clawdbot Gateway (port 18789).');
|
log('NOTE: This is NOT Clawdbot Gateway (port 18789).');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue