rtcpeerconnection
Advanced tools
Comparing version 0.3.2 to 1.0.0
{ | ||
"name": "rtcpeerconnection", | ||
"version": "0.3.2", | ||
"version": "1.0.0", | ||
"description": "A tiny browser module that gives normalizes and simplifies the API for WebRTC peer connections.", | ||
@@ -19,3 +19,3 @@ "main": "rtcpeerconnection.js", | ||
"wildemitter": "0.0.5", | ||
"webrtcsupport": "0.5.0" | ||
"webrtcsupport": "0.7.0" | ||
}, | ||
@@ -22,0 +22,0 @@ "devDependencies": { |
@@ -8,3 +8,3 @@ # RTCPeerConnection | ||
It gives us a cleaner (cross-browser) way to handle offer/answer and is based on an Event Emitter. | ||
It gives us a cleaner (cross-browser) way to handle offer/answer and is based on an event emitter. | ||
@@ -40,3 +40,3 @@ If you're not using browserify or you want AMD support use `rtcpeerconnection.bundle.js`. | ||
Unlike stock Peer Connections this is an event emitter. Powered by [WildEmitter](http://github.com/henrikjoreteg/wildemitter) which has a very familiar API if you're used to node.js/jQUery/Backbone but also includes a wildcard handler so you can easily debug events. Just do `emitter.on('*')` to log them out or whatnot. | ||
Unlike stock Peer Connections this inherits from a generic event emitter. Powered by [WildEmitter](http://github.com/henrikjoreteg/wildemitter) which has a very familiar API if you're used to node.js/jQUery/Backbone but also includes a wildcard handler so you can easily debug events. Just do `emitter.on('*')` to log them out or whatnot. | ||
@@ -114,3 +114,3 @@ But instead of doing `pc.onicecandidate = function () {}` on a peer connection you listen for events like this: | ||
// when you get an offer, you can answer | ||
// when you recieve an offer, you can answer | ||
// with various options | ||
@@ -169,5 +169,5 @@ connection.on('offer', function (offer) { | ||
## Created By | ||
## Credits | ||
If you like this, follow: [@HenrikJoreteg](http://twitter.com/henrikjoreteg) on twitter. | ||
(function(e){if("function"==typeof bootstrap)bootstrap("peerconnection",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makePeerConnection=e}else"undefined"!=typeof window?window.PeerConnection=e():global.PeerConnection=e()})(function(){var define,ses,bootstrap,module,exports; | ||
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ | ||
// created by @HenrikJoreteg | ||
var PC = window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection; | ||
var prefix; | ||
var isChrome = false; | ||
var isFirefox = false; | ||
var ua = navigator.userAgent.toLowerCase(); | ||
// basic sniffing | ||
if (ua.indexOf('firefox') !== -1) { | ||
prefix = 'moz'; | ||
isFirefox = true; | ||
} else if (ua.indexOf('chrome') !== -1) { | ||
prefix = 'webkit'; | ||
isChrome = true; | ||
} | ||
var PC = window.mozRTCPeerConnection || window.webkitRTCPeerConnection; | ||
var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate; | ||
var SessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription; | ||
var prefix = function () { | ||
if (window.mozRTCPeerConnection) { | ||
return 'moz'; | ||
} else if (window.webkitRTCPeerConnection) { | ||
return 'webkit'; | ||
} | ||
}(); | ||
var MediaStream = window.webkitMediaStream || window.MediaStream; | ||
@@ -18,10 +25,11 @@ var screenSharing = navigator.userAgent.match('Chrome') && parseInt(navigator.userAgent.match(/Chrome\/(.*) /)[1], 10) >= 26; | ||
// export support flags and constructors.prototype && PC | ||
module.exports = { | ||
support: !!PC, | ||
dataChannel: !!(PC && PC.prototype && PC.prototype.createDataChannel), | ||
dataChannel: isChrome || isFirefox || (PC.prototype && PC.prototype.createDataChannel), | ||
prefix: prefix, | ||
webAudio: !!(AudioContext && AudioContext.prototype.createMediaStreamSource), | ||
mediaStream: !!(MediaStream && MediaStream.prototype.removeTrack), | ||
screenSharing: screenSharing, | ||
screenSharing: !!screenSharing, | ||
AudioContext: AudioContext, | ||
@@ -33,2 +41,3 @@ PeerConnection: PC, | ||
},{}],2:[function(require,module,exports){ | ||
@@ -179,9 +188,18 @@ /* | ||
WildEmitter.call(this); | ||
// proxy some events directly | ||
this.pc.onremovestream = this.emit.bind(this, 'removeStream'); | ||
this.pc.onnegotiationneeded = this.emit.bind(this, 'negotiationNeeded'); | ||
this.pc.oniceconnectionstatechange = this.emit.bind(this, 'iceConnectionStateChange'); | ||
this.pc.onsignalingstatechange = this.emit.bind(this, 'signalingStateChange'); | ||
// handle incoming ice and data channel events | ||
this.pc.onaddstream = this._onAddStream.bind(this); | ||
this.pc.onicecandidate = this._onIce.bind(this); | ||
this.pc.onaddstream = this._onAddStream.bind(this); | ||
this.pc.onremovestream = this._onRemoveStream.bind(this); | ||
this.pc.ondatachannel = this._onDataChannel.bind(this); | ||
if (config.debug) { | ||
this.on('*', function (eventName, event) { | ||
console.log('PeerConnection event:', eventName, event); | ||
var logger = config.logger || console; | ||
logger.log('PeerConnection event:', arguments); | ||
}); | ||
@@ -197,2 +215,3 @@ } | ||
// Add a stream to the peer connection object | ||
PeerConnection.prototype.addStream = function (stream) { | ||
@@ -203,18 +222,4 @@ this.localStream = stream; | ||
PeerConnection.prototype._onIce = function (event) { | ||
if (event.candidate) { | ||
this.emit('ice', event.candidate); | ||
} else { | ||
this.emit('endOfCandidates'); | ||
} | ||
}; | ||
PeerConnection.prototype._onAddStream = function (event) { | ||
this.emit('addStream', event); | ||
}; | ||
PeerConnection.prototype._onRemoveStream = function (event) { | ||
this.emit('removeStream', event); | ||
}; | ||
// Init and add ice candidate object with correct constructor | ||
PeerConnection.prototype.processIce = function (candidate) { | ||
@@ -224,2 +229,3 @@ this.pc.addIceCandidate(new webrtc.IceCandidate(candidate)); | ||
// Generate and emit an offer with the given constraints | ||
PeerConnection.prototype.offer = function (constraints, cb) { | ||
@@ -236,2 +242,3 @@ var self = this; | ||
// Actually generate the offer | ||
this.pc.createOffer( | ||
@@ -251,2 +258,3 @@ function (sessionDescription) { | ||
// Answer an offer with audio only | ||
PeerConnection.prototype.answerAudioOnly = function (offer, cb) { | ||
@@ -259,6 +267,6 @@ var mediaConstraints = { | ||
}; | ||
this._answer(offer, mediaConstraints, cb); | ||
}; | ||
// Answer an offer without offering to recieve | ||
PeerConnection.prototype.answerBroadcastOnly = function (offer, cb) { | ||
@@ -271,22 +279,6 @@ var mediaConstraints = { | ||
}; | ||
this._answer(offer, mediaConstraints, cb); | ||
}; | ||
PeerConnection.prototype._answer = function (offer, constraints, cb) { | ||
var self = this; | ||
this.pc.setRemoteDescription(new webrtc.SessionDescription(offer)); | ||
this.pc.createAnswer( | ||
function (sessionDescription) { | ||
self.pc.setLocalDescription(sessionDescription); | ||
self.emit('answer', sessionDescription); | ||
if (cb) cb(null, sessionDescription); | ||
}, function (err) { | ||
self.emit('error', err); | ||
if (cb) cb(err); | ||
}, | ||
constraints | ||
); | ||
}; | ||
// Answer an offer with given constraints default is audio/video | ||
PeerConnection.prototype.answer = function (offer, constraints, cb) { | ||
@@ -306,2 +298,3 @@ var self = this; | ||
// Process an answer | ||
PeerConnection.prototype.handleAnswer = function (answer) { | ||
@@ -311,2 +304,3 @@ this.pc.setRemoteDescription(new webrtc.SessionDescription(answer)); | ||
// Close the peer connection | ||
PeerConnection.prototype.close = function () { | ||
@@ -317,2 +311,40 @@ this.pc.close(); | ||
// Internal code sharing for various types of answer methods | ||
PeerConnection.prototype._answer = function (offer, constraints, cb) { | ||
var self = this; | ||
this.pc.setRemoteDescription(new webrtc.SessionDescription(offer)); | ||
this.pc.createAnswer( | ||
function (sessionDescription) { | ||
self.pc.setLocalDescription(sessionDescription); | ||
self.emit('answer', sessionDescription); | ||
if (cb) cb(null, sessionDescription); | ||
}, function (err) { | ||
self.emit('error', err); | ||
if (cb) cb(err); | ||
}, | ||
constraints | ||
); | ||
}; | ||
// Internal method for emitting ice candidates on our peer object | ||
PeerConnection.prototype._onIce = function (event) { | ||
if (event.candidate) { | ||
this.emit('ice', event.candidate); | ||
} else { | ||
this.emit('endOfCandidates'); | ||
} | ||
}; | ||
// Internal method for processing a new data channel being added by the | ||
// other peer. | ||
PeerConnection.prototype._onDataChannel = function (event) { | ||
this.emit('addChannel', event.channel); | ||
}; | ||
// Internal handling of adding stream | ||
PeerConnection.prototype._onAddStream = function (event) { | ||
this.remoteStream = event.stream; | ||
this.emit('addStream', event); | ||
}; | ||
module.exports = PeerConnection; | ||
@@ -319,0 +351,0 @@ |
@@ -8,9 +8,18 @@ var WildEmitter = require('wildemitter'); | ||
WildEmitter.call(this); | ||
// proxy some events directly | ||
this.pc.onremovestream = this.emit.bind(this, 'removeStream'); | ||
this.pc.onnegotiationneeded = this.emit.bind(this, 'negotiationNeeded'); | ||
this.pc.oniceconnectionstatechange = this.emit.bind(this, 'iceConnectionStateChange'); | ||
this.pc.onsignalingstatechange = this.emit.bind(this, 'signalingStateChange'); | ||
// handle incoming ice and data channel events | ||
this.pc.onaddstream = this._onAddStream.bind(this); | ||
this.pc.onicecandidate = this._onIce.bind(this); | ||
this.pc.onaddstream = this._onAddStream.bind(this); | ||
this.pc.onremovestream = this._onRemoveStream.bind(this); | ||
this.pc.ondatachannel = this._onDataChannel.bind(this); | ||
if (config.debug) { | ||
this.on('*', function (eventName, event) { | ||
console.log('PeerConnection event:', eventName, event); | ||
var logger = config.logger || console; | ||
logger.log('PeerConnection event:', arguments); | ||
}); | ||
@@ -26,2 +35,3 @@ } | ||
// Add a stream to the peer connection object | ||
PeerConnection.prototype.addStream = function (stream) { | ||
@@ -32,18 +42,4 @@ this.localStream = stream; | ||
PeerConnection.prototype._onIce = function (event) { | ||
if (event.candidate) { | ||
this.emit('ice', event.candidate); | ||
} else { | ||
this.emit('endOfCandidates'); | ||
} | ||
}; | ||
PeerConnection.prototype._onAddStream = function (event) { | ||
this.emit('addStream', event); | ||
}; | ||
PeerConnection.prototype._onRemoveStream = function (event) { | ||
this.emit('removeStream', event); | ||
}; | ||
// Init and add ice candidate object with correct constructor | ||
PeerConnection.prototype.processIce = function (candidate) { | ||
@@ -53,2 +49,3 @@ this.pc.addIceCandidate(new webrtc.IceCandidate(candidate)); | ||
// Generate and emit an offer with the given constraints | ||
PeerConnection.prototype.offer = function (constraints, cb) { | ||
@@ -65,2 +62,3 @@ var self = this; | ||
// Actually generate the offer | ||
this.pc.createOffer( | ||
@@ -80,2 +78,3 @@ function (sessionDescription) { | ||
// Answer an offer with audio only | ||
PeerConnection.prototype.answerAudioOnly = function (offer, cb) { | ||
@@ -88,6 +87,6 @@ var mediaConstraints = { | ||
}; | ||
this._answer(offer, mediaConstraints, cb); | ||
}; | ||
// Answer an offer without offering to recieve | ||
PeerConnection.prototype.answerBroadcastOnly = function (offer, cb) { | ||
@@ -100,22 +99,6 @@ var mediaConstraints = { | ||
}; | ||
this._answer(offer, mediaConstraints, cb); | ||
}; | ||
PeerConnection.prototype._answer = function (offer, constraints, cb) { | ||
var self = this; | ||
this.pc.setRemoteDescription(new webrtc.SessionDescription(offer)); | ||
this.pc.createAnswer( | ||
function (sessionDescription) { | ||
self.pc.setLocalDescription(sessionDescription); | ||
self.emit('answer', sessionDescription); | ||
if (cb) cb(null, sessionDescription); | ||
}, function (err) { | ||
self.emit('error', err); | ||
if (cb) cb(err); | ||
}, | ||
constraints | ||
); | ||
}; | ||
// Answer an offer with given constraints default is audio/video | ||
PeerConnection.prototype.answer = function (offer, constraints, cb) { | ||
@@ -135,2 +118,3 @@ var self = this; | ||
// Process an answer | ||
PeerConnection.prototype.handleAnswer = function (answer) { | ||
@@ -140,2 +124,3 @@ this.pc.setRemoteDescription(new webrtc.SessionDescription(answer)); | ||
// Close the peer connection | ||
PeerConnection.prototype.close = function () { | ||
@@ -146,2 +131,40 @@ this.pc.close(); | ||
// Internal code sharing for various types of answer methods | ||
PeerConnection.prototype._answer = function (offer, constraints, cb) { | ||
var self = this; | ||
this.pc.setRemoteDescription(new webrtc.SessionDescription(offer)); | ||
this.pc.createAnswer( | ||
function (sessionDescription) { | ||
self.pc.setLocalDescription(sessionDescription); | ||
self.emit('answer', sessionDescription); | ||
if (cb) cb(null, sessionDescription); | ||
}, function (err) { | ||
self.emit('error', err); | ||
if (cb) cb(err); | ||
}, | ||
constraints | ||
); | ||
}; | ||
// Internal method for emitting ice candidates on our peer object | ||
PeerConnection.prototype._onIce = function (event) { | ||
if (event.candidate) { | ||
this.emit('ice', event.candidate); | ||
} else { | ||
this.emit('endOfCandidates'); | ||
} | ||
}; | ||
// Internal method for processing a new data channel being added by the | ||
// other peer. | ||
PeerConnection.prototype._onDataChannel = function (event) { | ||
this.emit('addChannel', event.channel); | ||
}; | ||
// Internal handling of adding stream | ||
PeerConnection.prototype._onAddStream = function (event) { | ||
this.remoteStream = event.stream; | ||
this.emit('addStream', event); | ||
}; | ||
module.exports = PeerConnection; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21401
432
1
+ Addedwebrtcsupport@0.7.0(transitive)
- Removedwebrtcsupport@0.5.0(transitive)
Updatedwebrtcsupport@0.7.0