mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-18 19:19:36 +02:00
Added WebSockets with funcionality to send messages from any module
This commit is contained in:
parent
4510a709d4
commit
38f5d3b66a
7 changed files with 84 additions and 21 deletions
21
Socket.js
Normal file
21
Socket.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const WebSocket = require('ws');
|
||||
|
||||
class Socket {
|
||||
constructor(server) {
|
||||
this.webSocketServer = new WebSocket.Server({ server })
|
||||
|
||||
this.webSocketServer.on('listening', () => {
|
||||
console.log('socket listen');
|
||||
})
|
||||
|
||||
this.webSocketServer.on('connection', (webSocketClient) => {
|
||||
console.log('new connection');
|
||||
})
|
||||
}
|
||||
|
||||
send(msg) {
|
||||
this.webSocketServer.clients.forEach(client => client.send(msg));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Socket;
|
Loading…
Add table
Add a link
Reference in a new issue