0.3.14 • Published 7 years ago

v6-ws v0.3.14

Weekly downloads
78
License
-
Repository
github
Last release
7 years ago

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 8080
  • server optional web server
  • https optional https flag, default is false
  • cert path to ssl certificate for https, optional
  • key path to ssl key for https, optional
  • pingTimeout default is 60000 ms
  • pingInterval default is 25000 ms

Events:

  • connection function(socket:#Socket) emit client connected

Socket(opts:Object)

Properties:

  • id websoket id
  • cookies #Object, key value array

Functions:

  • send function (data: #Object) sends data to socket client
  • in function (room: #String) return two functions to send data in room to other sockets: send and broadcast
  • enterRoom function (room: #String)
  • leaveRoom function (room: #String)
  • leaveAll function () leave all rooms
  • close function (reason #String) disconnect socket

Events:

  • message function (data) incoming message to socket
  • disconnect function (reason)
wss.on('connection', function(socket){
    socket.enterRoom('test room');
    socket.in('test room').send('Hi all!');
    socket.leaveRoom('test room');
});
0.3.14

7 years ago

0.3.13

8 years ago

0.3.12

9 years ago

0.3.11

9 years ago

0.3.10

9 years ago

0.3.9

9 years ago

0.3.8

9 years ago

0.3.7

9 years ago

0.3.6

9 years ago

0.3.5

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago