rtcpeerconnection
Advanced tools
Comparing version 0.0.0 to 0.1.0
{ | ||
"name": "rtcpeerconnection", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "A tiny browser module that gives normalizes and simplifies the API for WebRTC peer connections.", | ||
@@ -5,0 +5,0 @@ "main": "rtcpeerconnection.js", |
var WildEmitter = require('wildemitter'); | ||
var webrtc = require('webrtcsupport'); | ||
// The RTCPeerConnection object. | ||
var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; | ||
// The RTCSessionDescription object. | ||
var RTCSessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription; | ||
// The RTCIceCandidate object. | ||
var RTCIceCandidate = window.RTCIceCandidate || window.mozRTCIceCandidate; | ||
function PeerConnection(config, constraints) { | ||
this.pc = new RTCPeerConnection(config, constraints); | ||
this.pc = new webrtc.PeerConnection(config, constraints); | ||
WildEmitter.call(this); | ||
this.pc.onicemessage = this._onIce.bind(this); | ||
this.pc.onicecandidate = this._onIce.bind(this); | ||
this.pc.onaddstream = this._onAddStream.bind(this); | ||
this.pc.onremovestream = this._onRemoveStream.bind(this); | ||
if (config.debug) { | ||
this.on('*', function (eventName, event) { | ||
console.log('PeerConnection event:', eventName, event); | ||
}); | ||
} | ||
} | ||
@@ -33,15 +31,19 @@ | ||
PeerConnection.prototype._onIce = function (event) { | ||
this.emit('ice', event.candidate); | ||
if (event.candidate) { | ||
this.emit('ice', event.candidate); | ||
} else { | ||
this.emit('endOfCandidates'); | ||
} | ||
}; | ||
PeerConnection.prototype._onAddStream = function () { | ||
PeerConnection.prototype._onAddStream = function (event) { | ||
this.emit('addStream', event); | ||
}; | ||
PeerConnection.prototype._onRemoveStream = function () { | ||
PeerConnection.prototype._onRemoveStream = function (event) { | ||
this.emit('removeStream', event); | ||
}; | ||
PeerConnection.prototype.processIce = function (candidate) { | ||
this.pc.addIceCandidate(new RTCIceCandidate(candidate)); | ||
this.pc.addIceCandidate(new webrtc.IceCandidate(candidate)); | ||
}; | ||
@@ -57,2 +59,3 @@ | ||
}; | ||
var callback = arguments.length === 2 ? cb : constraints; | ||
@@ -62,3 +65,3 @@ this.pc.createOffer(function (sessionDescription) { | ||
self.emit('offer', sessionDescription); | ||
cb && cb(sessionDescription) | ||
if (callback) callback(sessionDescription); | ||
}, null, mediaConstraints); | ||
@@ -90,7 +93,8 @@ }; | ||
PeerConnection.prototype._answer = function (offer, constraints, cb) { | ||
this.setRemoteDescription(new RTCSessionDescription(offer)); | ||
this.createAnswer(function (sessionDescription) { | ||
var self = this; | ||
this.pc.setRemoteDescription(new webrtc.SessionDescription(offer)); | ||
this.pc.createAnswer(function (sessionDescription) { | ||
self.pc.setLocalDescription(sessionDescription); | ||
self.emit('answer', sessionDescription); | ||
cb && cb(sessionDescription); | ||
if (cb) cb(sessionDescription); | ||
}, null, constraints); | ||
@@ -101,5 +105,5 @@ }; | ||
var self = this; | ||
var threeArgs = arguments.length === 3; | ||
var callback = threeArgs ? cb : constraints; | ||
var mediaConstraints = threeArgs ? constraints : { | ||
var hasConstraints = arguments.length === 3; | ||
var callback = hasConstraints ? cb : constraints; | ||
var mediaConstraints = hasConstraints ? constraints : { | ||
mandatory: { | ||
@@ -111,5 +115,9 @@ OfferToReceiveAudio: true, | ||
this._answer(offer, mediaConstraints, cb); | ||
this._answer(offer, mediaConstraints, callback); | ||
}; | ||
PeerConnection.prototype.handleAnswer = function (answer) { | ||
this.pc.setRemoteDescription(new webrtc.SessionDescription(answer)); | ||
}; | ||
PeerConnection.prototype.close = function () { | ||
@@ -116,0 +124,0 @@ this.pc.close(); |
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
13058
316