socketier
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Socketier

Small, but useful wrapper around ws package. API similar to Socket.io, but without performance issues and long-polling.

Full documentation can be found here.

Server usage

import { SocketierServer } from 'socketier';

const server = new SocketierServer();

server.on('listening', () => console.log('Server listening'));

server.subscribe<string>('hello-world', (socket, data) => {
    console.log(`Socket data recieved: ${data}`);
    // Process data...
});

server.listen();   // DO NOT FORGET THIS LINE!!!

Client usage

For more convenient usage please use along with some bundling tool.

import { SocketierClient } from 'socketier/dist/client';

const client = new SocketierClient('ws://localhost:300');

client.on('connected', () => {
    console.log('Connection estabilished');
    // Send 'Hello world!' to the server
    client.send('hello-world', 'Hello world!');
});

client.connect();   // DO NOT FORGET THIS LINE!!!

You can also use client on server-side to connect server/node.js app to another Socketier server.

import { SocketierServer } from 'socketier';
import { SocketierClient } from 'socketier/dist/client';

const server = new SocketierServer();
const client = new SocketierClient('ws://another-socketier.com');

server.on('listening', () => {
    // Make connection, when server is ready
    client.connect();
});

server.subscribe<string>('hello-world', (socket, data) => {
    // Resend data to another server
    client.send('hello-world', data);
});

server.listen();

Package Sidebar

Install

npm i socketier

Weekly Downloads

2

Version

1.0.6

License

ISC

Unpacked Size

43.2 kB

Total Files

48

Last publish

Collaborators

  • mbedna