diff --git a/index.js b/index.js index 20b2651..b05f7bb 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,9 @@ app.put('/api/connect/:jobid', (req, res) => { ws_[id].message = data; }) ws_[id].connection.on('close', function() { - ws_[id].connection.terminate(); + if (ws_[id].connection) { + ws_[id].connection.terminate(); + } }) ws_[id].open = false; setInterval(() => { @@ -54,10 +56,10 @@ app.post("/api/send/:jobid/:id/", (req, res) => { var socket = ws_[id].connection; console.log("sent data: " + req.body) if (stats.open == true) { - socket.send(req.body); + socket.send(req.body.data); } else { socket.on('open', () => { - socket.send(req.body); + socket.send(req.body.data); }); } res.send({