You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
844 B

5 years ago
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const WebSocket = require("ws");
5 years ago
// let connections = new Map()
// let connectionCounter = 0
let lastConn;
5 years ago
const connect = (server) => {
server = new WebSocket.Server({ server });
console.log('=> [socket] connected to server');
5 years ago
server.on('connection', socket => {
console.log('=> [socket] connection received');
5 years ago
// var id = connectionCounter++;
// connections.set(id, socket)
lastConn = socket;
5 years ago
});
};
exports.connect = connect;
const send = (body) => {
5 years ago
// connections.forEach((socket, index) => {
// socket.send(body)
// })
lastConn.send(body);
5 years ago
};
exports.send = send;
const sendJson = (object) => {
send(JSON.stringify(object));
};
exports.sendJson = sendJson;
//# sourceMappingURL=socket.js.map