README
WebSocket server
Simple WebSocket server with rooms, clients timeout and namespace.
Server side: SocketServer Client side: default websocket
Example
var Server = require('v6-ws').SocketServer;
wss = new Server({port: 8080, path:'/ws', pingTimeout:10000, pingInterval:5000});
wss.init(function(error){});
wss.on('connection', handler)
function handler(ws) {}
API
SocketServer(opts:Object)
Options:
path
namespace websocket server for connection, default is '\ws'port
listening port, optional, default is 8080server
optional web serverhttps
optional https flag, default is falsecert
path to ssl certificate for https, optionalkey
path to ssl key for https, optionalpingTimeout
default is 60000 mspingInterval
default is 25000 ms
Events:
connection
function(socket:#Socket) emit client connected
Socket(opts:Object)
Properties:
id
websoket idcookies
#Object, key value array
Functions:
send
function (data: #Object) sends data to socket clientin
function (room: #String) return two functions to send data in room to other sockets: send and broadcastenterRoom
function (room: #String)leaveRoom
function (room: #String)leaveAll
function () leave all roomsclose
function (reason #String) disconnect socket
Events:
message
function (data) incoming message to socketdisconnect
function (reason)
wss.on('connection', function(socket){
socket.enterRoom('test room');
socket.in('test room').send('Hi all!');
socket.leaveRoom('test room');
});