Emulating peer connection in node & browser
JavaScript
Switch branches/tags
Nothing to show
Latest commit cfb5698 Dec 12, 2012 @Raynos 0.7.2
Permalink
Failed to load latest commit information.
example
utils
.gitignore
LICENCE
README.md
dataChannel.js
index.js
open.js
package.json

README.md

peer-connection-shim

Emulating peer connection in node & browser

Example

Works on either server or client.

var PeerConnection = require("peer-connection")
    , WriteStream = require("write-stream")
    , SignalChannel = require("signal-channel")

    , RTCPeerConnection = require("peer-connection-shim")

var pc1 = PeerConnection(RTCPeerConnection({
    stream: SignalChannel(null, "/v1/relay")
}))

var pc2 = PeerConnection(RTCPeerConnection({
    stream: SignalChannel(null, "/v1/relay")
}))

pc1.createOffer(function (err, offer) {
    pc2.createAnswer(offer, function (err, answer) {
        pc1.setRemote(answer)

        open()
    })
})

pc1.on("connection", function (stream) {
    console.log("open channel", stream.meta)

    stream.pipe(WriteStream(function (chunk) {
        console.log("pc1", chunk)

        stream.write(chunk)
    }))
})

function open() {
    var stream = pc2.createStream("channel name")

    stream.write("hello world!")

    stream.pipe(WriteStream(function (chunk) {
        console.log("pc2", chunk)
    }))
}

Installation

npm install peer-connection-shim

Contributors

  • Raynos

MIT Licenced