0.3.0 • Published 6 years ago

tiny-websock v0.3.0

Weekly downloads
4
License
WTFPL
Repository
github
Last release
6 years ago

Tiny WebSocket

This library is intend to wrap the WebSocket library with a more flexible and more extendable interface.

Install

Just type the following command to install the package

npm install tiny-websock

Example

const {WebSocketServer} = require( 'tiney-websock' );
const server = new WebSocketServer();   // Create a server instance
server.acceptOrigin( '*' );             // Accept request from anywhere

// Process messages and events under protocols
const protocol = server.protocol( 'accepted_protocol' );
protocol.on( 'message', (conn, msg)=>{
    console.log( "Received msg from connection under protocol 'accepted_protocol'" );
})
.on( 'say_hello', (e, name)=>{
    console.log( 'Receved `say_hello` event from connection.' );
});


// Intercept all protocols' events
server.on( 'message', (conn, msg)=>{
    console.log( "Some protocol received message from connection" );
})
.on( 'say_hello', (e, name)=>{
    console.log( 'Some protocol received `say_hello` event from connection' );
});
0.3.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago