1.0.11 • Published 7 years ago

websocketizer v1.0.11

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

Websocketizer

Simple websocket client with reconnecter and server using 'ws' (https://github.com/websockets/ws)

Server use

import { Server } from 'websocketizer';

// same options of 'ws'
const server = new Server({
	port: 7001,
});

server.onConnection((socket) => {
	console.log(`${socket.id} connected`);

    // send to all connections
    server.emit('receivedConnection', socket.id);

    // send to specific connection
    socket.emit('youAreConnected');
});

server.onDisconnection((socket) => {
	console.log(`${socket.id} disconnected`);

    // send to all connections
    server.emit('receivedDisconnection', socket.id);
});

// execute on receive packet 'ping'
server.on('ping', (socket) => {
	console.log(`${socket.id} pinged`);

    // respond with packet 'pong'
	socket.emit('pong');
});

server.start();

Build Setup

# install dependencies
npm install

# build for production with minification
npm run build

# start compiled version.
npm run start

# run lint in code
npm run lint
1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.0

7 years ago