1.0.11 • Published 10 years ago

websocketizer v1.0.11

Weekly downloads
1
License
ISC
Repository
-
Last release
10 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

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.0

10 years ago