Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Message

Gentilhomme edited this page Aug 26, 2017 · 1 revision

Message

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) ); 
}); 

Methods

constructor(eventName,data = {})

Data is an optional argument (default set to an empty Object).

exclude(socket)

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(source,data)

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).

Clone this wiki locally