diff --git a/client/src/store/turtleStore.js b/client/src/store/turtleStore.js index 26b68b1..b3332c8 100644 --- a/client/src/store/turtleStore.js +++ b/client/src/store/turtleStore.js @@ -75,6 +75,8 @@ export const useTurtleStore = create((set, get) => ({ sendCommand: async (turtleId, command, param = null) => { const { ws } = get(); + console.log(`🎮 Sending command to turtle ${turtleId}: ${command}`, param ? `(param: ${param})` : ''); + if (ws && ws.readyState === WebSocket.OPEN) { ws.send(JSON.stringify({ type: 'command', @@ -82,16 +84,19 @@ export const useTurtleStore = create((set, get) => ({ command, param })); + console.log(' ✅ Sent via WebSocket'); } else { // Fallback to REST API + console.log(' ⚠️ WebSocket not connected, using REST API fallback'); try { - await fetch(`${API_URL}/api/turtle/${turtleId}/command`, { + await fetch(`${API_URL}/turtle/${turtleId}/command`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ command, param }) }); + console.log(' ✅ Sent via REST API'); } catch (error) { - console.error('Error sending command:', error); + console.error(' ❌ Error sending command:', error); } } },