diff --git a/index.js b/index.js index efc4af3..6c0e73f 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const WebSocket = require('ws'); const mode = 'host'; // 'host' or 'client' const server = 'ws://node.janderedev.xyz:8080'; -if (mode == 'client') { +if (mode == 'host') { const server = new WebSocket.Server({ port: 8080 }); @@ -52,10 +52,15 @@ let getPos = () => { return { x, y } } +let connected = false; const client = new WebSocket(mode == 'host' ? 'ws://localhost:8080' : server); -client.on('open', () => console.log('Connected')); +client.on('open', () => { + console.log('Connected'); + connected = true; +}); setInterval(() => { + if (!connected) return; let pos = getPos(); client.send(`${pos.x}:${pos.y}`); }, 50);