chore: auto-commit uncommitted changes
This commit is contained in:
parent
60a6d973f5
commit
d039be46a4
24
server.js
24
server.js
|
|
@ -23,6 +23,7 @@ const PROTOCOL_VERSION = 'clawdnode/1.0';
|
|||
// Connected clients
|
||||
const clients = new Map();
|
||||
let commandQueue = [];
|
||||
const pendingCommands = new Map(); // commandId -> { resolve, timer }
|
||||
|
||||
// Logging
|
||||
const logStream = fs.createWriteStream(LOG_FILE, { flags: 'a' });
|
||||
|
|
@ -92,7 +93,7 @@ function handleMessage(clientId, msg, ws) {
|
|||
type: 'error',
|
||||
code: 'WRONG_PROTOCOL',
|
||||
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,
|
||||
received: msg.method || msg.type
|
||||
}));
|
||||
|
|
@ -148,6 +149,12 @@ function handleMessage(clientId, msg, ws) {
|
|||
case 'result':
|
||||
log(`✅ [RESPONSE] Command ${msg.commandId}: ${msg.success ? 'OK' : 'FAILED'}`);
|
||||
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;
|
||||
|
||||
case 'log':
|
||||
|
|
@ -244,7 +251,18 @@ const httpServer = http.createServer(async (req, res) => {
|
|||
return;
|
||||
}
|
||||
const cmdId = sendCommand(body.command, body.params || {});
|
||||
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;
|
||||
|
||||
case '/notification/action':
|
||||
|
|
@ -314,8 +332,8 @@ httpServer.listen(HTTP_PORT, '0.0.0.0', () => {
|
|||
log('ClawdNode Gateway - Custom Protocol');
|
||||
log(`Protocol: ${PROTOCOL_VERSION}`);
|
||||
log('================================================');
|
||||
log(`HTTP API: http://100.123.216.65:${HTTP_PORT}`);
|
||||
log(`WebSocket: ws://100.123.216.65:${WS_PORT}`);
|
||||
log(`HTTP API: http://0.0.0.0:${HTTP_PORT}`);
|
||||
log(`WebSocket: ws://0.0.0.0:${WS_PORT}`);
|
||||
log(`Log file: ${LOG_FILE}`);
|
||||
log('');
|
||||
log('NOTE: This is NOT Clawdbot Gateway (port 18789).');
|
||||
|
|
|
|||
Loading…
Reference in New Issue