diff --git a/api/utils/socket.ts b/api/utils/socket.ts index dccf58dbf..ab981fadd 100644 --- a/api/utils/socket.ts +++ b/api/utils/socket.ts @@ -1,7 +1,9 @@ import * as WebSocket from 'ws' -let connections = new Map() -let connectionCounter = 0 +// let connections = new Map() +// let connectionCounter = 0 + +let lastConn: any const connect = (server) => { server = new WebSocket.Server({ server }) @@ -10,16 +12,18 @@ const connect = (server) => { server.on('connection', socket => { console.log('=> [socket] connection received') - var id = connectionCounter++; - connections.set(id, socket) + // var id = connectionCounter++; + // connections.set(id, socket) + lastConn = socket }) } const send = (body) => { - connections.forEach((socket, index) => { - socket.send(body) - }) + // connections.forEach((socket, index) => { + // socket.send(body) + // }) + lastConn.send(body) } const sendJson = (object) => { diff --git a/dist/api/utils/socket.js b/dist/api/utils/socket.js index 827aff864..0bc158761 100644 --- a/dist/api/utils/socket.js +++ b/dist/api/utils/socket.js @@ -1,22 +1,25 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const WebSocket = require("ws"); -let connections = new Map(); -let connectionCounter = 0; +// let connections = new Map() +// let connectionCounter = 0 +let lastConn; const connect = (server) => { server = new WebSocket.Server({ server }); console.log('=> [socket] connected to server'); server.on('connection', socket => { console.log('=> [socket] connection received'); - var id = connectionCounter++; - connections.set(id, socket); + // var id = connectionCounter++; + // connections.set(id, socket) + lastConn = socket; }); }; exports.connect = connect; const send = (body) => { - connections.forEach((socket, index) => { - socket.send(body); - }); + // connections.forEach((socket, index) => { + // socket.send(body) + // }) + lastConn.send(body); }; exports.send = send; const sendJson = (object) => { diff --git a/dist/api/utils/socket.js.map b/dist/api/utils/socket.js.map index a7b476fb7..1ee86a141 100644 --- a/dist/api/utils/socket.js.map +++ b/dist/api/utils/socket.js.map @@ -1 +1 @@ -{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../api/utils/socket.ts"],"names":[],"mappings":";;AAAA,gCAA+B;AAE/B,IAAI,WAAW,GAAG,IAAI,GAAG,EAAE,CAAA;AAC3B,IAAI,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AC,EAAE;QAC/B,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAA;QAC9C,gCAAgC;QAChC,8BAA8B;QAC9B,QAAQ,GAAG,MAAM,CAAA;IACnB,CAAC,CAAC,CAAA;AAEJ,CAAC,CAAA;AAcC,0BAAO;AAZT,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;IACpB,2CAA2C;IAC3C,sBAAsB;IACtB,KAAK;IACL,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACrB,CAAC,CAAA;AAQC,oBAAI;AANN,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE;IAC1B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AAC9B,CAAC,CAAA;AAKC,4BAAQ"} \ No newline at end of file