flame/Socket.js

23 lines
538 B
JavaScript
Raw Normal View History

const WebSocket = require('ws');
2021-06-22 15:49:00 +03:00
const Logger = require('./utils/Logger');
const logger = new Logger();
class Socket {
constructor(server) {
this.webSocketServer = new WebSocket.Server({ server })
this.webSocketServer.on('listening', () => {
2021-06-22 15:49:00 +03:00
logger.log('Socket: listen');
})
this.webSocketServer.on('connection', (webSocketClient) => {
// console.log('Socket: new connection');
})
}
send(msg) {
this.webSocketServer.clients.forEach(client => client.send(msg));
}
}
module.exports = Socket;