Nitro Powered Motorcycles

    socket.io-routers
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    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);

    Install

    npm i socket.io-routers

    DownloadsWeekly Downloads

    276

    Version

    3.0.0

    License

    ISC

    Unpacked Size

    10.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • natashkinsasha