This repository was archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Message
Gentilhomme edited this page Aug 26, 2017
·
1 revision
Send a new socket message
const {Message,Server} = require('uvyper');
const testMsg = new Message('hello',{
aVar: 'hey !'
});
const WSServer = new Server({port: 3000});
WSServer.on('connection',function(socket) {
testMsg.publish(socket,{
bVar: 'additional variable!'
}).catch( E => console.error(E) );
}); Data is an optional argument (default set to an empty Object).
socket can be a socket alone or an array of socket. Socket instance or Socket.id are only allowed.
new Message('test').exclude([socket1,socket2.id]).exclude(socket3).publish();Return this
Publish the message to the source (If source is undefined, the source has been defined to Server). Example :
new Message('broadcast',{ cost: 4 }).publish();The source can be : Socket, Server, Room (For Socket, it's like doing Socket.send method. But for Server and Room that will share the message to every sockets, it's a broadcast).