Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const WebSocketServer = new require('ws');
- const wSS = new WebSocketServer.Server( { port: 8081 } );
- wSS.broadcast = function(data, clientValidator = () => true) {
- this.clients.forEach(client => {
- client.send(data);
- });
- };
- wSS.on("connection", ws => {
- // событие будет вызвано, когда клиент отправит сообщение
- ws.on('message', message => {
- // отправляем сообщение всем, кроме автора
- wSS.broadcast(message, client => client !== ws);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement