Skip to content

whitesharx/socket.io-routers

 
 

Repository files navigation

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 [email protected] 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);

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%