Skip to content

willCode2Surf/peer-connection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

peer-connection

A nicer peer connection api

Example

var PeerConnection = require("peer-connection")
    , shim = require("peer-connection-shim")
    , realDeal = window.RTCPeerConnection
    , signal = someSignalChannel()

// Either use the shim to open a peer connection
var pc = PeerConnection(shim({
    uri: "http://discoverynetwork.co"
}))

// or use the real deal
var pc = PeerConnection(realDeal({
    iceServers: [...]
}))

// Get a pair of peer connections
var pc1, pc2 = ...

// Then use the simplified api!
pc1.createOffer(function (err, offer) {
    signal.send("offer", offer)
})

signal.on("offer", function () {
    pc2.createAnswer(offer, function (err, answer) {
        signal.send("answer", answer)
    })
})

signal.on("answer", function (answer) {
    pc1.setRemote(answer)
})

// With data channels!
pc2.on("connection", function (stream) {
    ...
})

var stream = pc1.createStream("some label")
stream.write("hello world!")

Installation

npm install peer-connection

Contributors

  • Raynos

MIT Licenced

About

A nicer peer connection api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published