Skip to content

Raynos/peer-nodes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

peer-nodes

A replicated list of peers

Example

var Peers = require("peer-nodes")

var p1 = Peers({
        interval: 100
        , timeout: 600
    })
    , p2 = Peers({
        interval: 100
        , timeout: 600
    })

p1.on("join", function (peer) {
    console.log("joined 1", peer.id)
})

p2.on("join", function (peer) {
    console.log("joined 2", peer.id)
})

p1.on("leave", function (peer) {
    console.log("leave 1", peer.id)

    if (peer.id === "peer2 id") {
        setTimeout(function () {
            console.log("closing p1")
            p1.close()
        }, 1000)
    }
})

p2.on("leave", function (peer) {
    console.log("leave 2", peer.id)
})

var stream1 = p1.createStream()
    , stream2 = p2.createStream()

stream1.pipe(stream2).pipe(stream1)

p1.join({
    id: "peer1 id"
    , "arbitary meta data": "here"
})
p2.join({
    id: "peer2 id"
})

setTimeout(function () {
    console.log("closing p2")
    p2.close()
}, 1000)

Installation

npm install peer-nodes

Contributors

  • Raynos

MIT Licenced

About

A replicated list of peers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published