socketio-bus

0.1.1 • Public • Published

Server

const {server, client} = require('./index')

const busServer = new server();

busServer.init({
    host: 'localhost',
    port: 5080
})

Client-1

const {server, client} = require('./index')

const busClient = new client();
(async ()=>{
    await busClient.initAsync({
        host: 'localhost',
        port: 5080,
        nName: 'test-01'
    })

    busClient.registerName({
        nName: 'test-01'
    })

    busClient.joinGroup({
        gName: 'TEST-G'
    });
    busClient.joinGroup({
        gName: 'TEST-G-2'
    });

    busClient.on({
        eventName: 'test',
        callback: ({x})=>{
            console.log('test: ', x);
        }
    })

    busClient.sub({
        topic: 'mysub',
        callback: ({x})=>{
            console.log(x);
        }
    })

    setTimeout(()=>{
        busClient.toGroup({
            gName: 'TEST-G',
            gEventName: 'test',
            x: 'toGroup:1'
        })

        busClient.toNode({
            nName: 'test-02',
            nEventName: 'test',
            x: 'toNode:2'
        })
        busClient.toNodes({
            nNameArr: ['test-01', 'test-02'],
            nEventName: 'test',
            x: 'toNodes:22'
        })

    }, 5000)

})()

Client-2

const {server, client} = require('./index')

const busClient = new client();
(async ()=>{
    await busClient.initAsync({
        host: 'localhost',
        port: 5080,
        nName: 'test-02'
    })

    busClient.registerName({
        nName: 'test-02'
    })

    busClient.joinGroup({
        gName: 'TEST-G',
        callback: (ackData)=>{
            console.log('callback: ', ackData);
        }
    });

    busClient.on({
        eventName: 'test',
        callback: ({x})=>{
            console.log('test: ', x);
        }
    })

    setTimeout(()=>{
        
        busClient.toGroup({
            gName: 'TEST-G',
            gEventName: 'test',
            x: 'toGroup:11'
        })

        busClient.toGroups({
            gNameArr: ['TEST-G', 'TEST-G-2'],
            gEventName: 'test',
            x: 'toGroups:22'
        })

        busClient.pub({
            topic: 'mysub',
            x: 'mysub:888'
        })
    }, 5000)
    
})()

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.1
    1

Package Sidebar

Install

npm i socketio-bus

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

20.7 kB

Total Files

9

Last publish

Collaborators

  • liufanghua2012