const ws = require('ws');
const wss = new ws.Server({
port: 6000
}, () => {console.log('Websocket started on port 6000')});
wss.on('connection', function connection(ws) {
ws.on('mesage', function (message) {
message = JSON.parse(message);
switch (message.event) {
case 'message':
broadcastMessage();
break;
case 'connection':
broadcastMessage(message);
break;
}
})
})
function broadcastMessage(message) {
wss.clients.forEach(client => {
client.send(JSON.stringify(message));
})
}