3.0.0 • Published 3 years ago

socket.io-routers v3.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
3 years ago

socket.io-routers

Router to use with socket.io

Installation

Npm

npm install socket.io-routers

Yarn

yarn add socket.io-routers

Support

This library is quite fresh, and maybe has bugs. Write me an email to natashkinsash@gmail.com and I will fix the bug in a few working days.

Quick start

const {RouterContext, createRouter} = require('socket.io-routers');
const Server = require('socket.io');

const io = Server();

const routerContext = new RouterContext();

routerContext.onConnect((io, socket, next) => {
    doSmth();
});

routerContext.onDisconnect((io, socket, reason, next) => {
    doSmth();
});

routerContext.use("test", (socket, event, params, ack, next) => {
        doSmth()
            .then((msg)=>{
                ack(msg);
            })
            .catch((err)=>{
                next(err);
            })
});

routerContext.use((io, socket, err, ack) => {
    socket.emit("error", err.message)
});

server.use(createRouter(routerContext));


io.listen(3000);
3.0.0

3 years ago

0.2.0

4 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago