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