Socket
Socket
Sign inDemoInstall

rtcpeerconnection

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rtcpeerconnection - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

2

package.json
{
"name": "rtcpeerconnection",
"version": "0.1.3",
"version": "0.2.0",
"description": "A tiny browser module that gives normalizes and simplifies the API for WebRTC peer connections.",

@@ -5,0 +5,0 @@ "main": "rtcpeerconnection.js",

@@ -1,2 +0,2 @@

# PeerConnection
# RTCPeerConnection

@@ -23,2 +23,3 @@

### Instantiation
Instantiation takes the same options as a normal peer connection constructor:

@@ -82,2 +83,6 @@

Note that all callbacks follow the "error first" convention. Meaning, rather than pass a success and fail callback, you pass a single callback.
If there is an error, the first argument passed to the callback will be a truthy value (the error itself).
The whole offer/answer cycle looks like this:

@@ -104,4 +109,4 @@

},
function (offer) {
// offer
function (err, offer) {
if (!err) connection.send('offer, offer);
}

@@ -114,9 +119,9 @@ );

// you can just call answer
pc.answer(offer, function (answer) {
connection.send('answer', answer);
pc.answer(offer, function (err, answer) {
if (!err) connection.send('answer', answer);
});
// you can call answer with contstraints
pc.answer(offer, MY_CONSTRAINTS, function (answer) {
connection.send('answer', answer);
pc.answer(offer, MY_CONSTRAINTS, function (err, answer) {
if (!err) connection.send('answer', answer);
});

@@ -127,6 +132,6 @@

// for video only
pc.answerVideoOnly(offer, function (answer) { ... });
pc.answerVideoOnly(offer, function (err, answer) { ... });
// and audio only
pc.answerAudioOnly(offer, function (answer) { ... });
pc.answerAudioOnly(offer, function (err, answer) { ... });
});

@@ -133,0 +138,0 @@

(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){
var WildEmitter = require('wildemitter');
var webrtc = require('webrtcsupport');
function PeerConnection(config, constraints) {
this.pc = new webrtc.PeerConnection(config, constraints);
WildEmitter.call(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);
});
}
}
PeerConnection.prototype = Object.create(WildEmitter.prototype, {
constructor: {
value: PeerConnection
}
});
PeerConnection.prototype.addStream = function (stream) {
this.localStream = stream;
this.pc.addStream(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);
};
PeerConnection.prototype.processIce = function (candidate) {
this.pc.addIceCandidate(new webrtc.IceCandidate(candidate));
};
PeerConnection.prototype.offer = function (constraints, cb) {
var self = this;
var hasConstraints = arguments.length === 2;
var mediaConstraints = hasConstraints ? constraints : {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
};
var callback = hasConstraints ? cb : constraints;
this.pc.createOffer(
function (sessionDescription) {
self.pc.setLocalDescription(sessionDescription);
self.emit('offer', sessionDescription);
if (callback) callback(null, sessionDescription);
},
function (err) {
self.emit('error', err);
if (callback) callback(err);
},
mediaConstraints
);
};
PeerConnection.prototype.answerAudioOnly = function (offer, cb) {
var mediaConstraints = {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: false
}
};
this._answer(offer, mediaConstraints, cb);
};
PeerConnection.prototype.answerVideoOnly = function (offer, cb) {
var mediaConstraints = {
mandatory: {
OfferToReceiveAudio: false,
OfferToReceiveVideo: true
}
};
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
);
};
PeerConnection.prototype.answer = function (offer, constraints, cb) {
var self = this;
var hasConstraints = arguments.length === 3;
var callback = hasConstraints ? cb : constraints;
var mediaConstraints = hasConstraints ? constraints : {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
};
this._answer(offer, mediaConstraints, callback);
};
PeerConnection.prototype.handleAnswer = function (answer) {
this.pc.setRemoteDescription(new webrtc.SessionDescription(answer));
};
PeerConnection.prototype.close = function () {
this.pc.close();
this.emit('close');
};
module.exports = PeerConnection;
},{"wildemitter":2,"webrtcsupport":3}],2:[function(require,module,exports){
/*

@@ -139,128 +277,3 @@ WildEmitter.js is a slim little event emitter by @henrikjoreteg largely based

},{}],2:[function(require,module,exports){
var WildEmitter = require('wildemitter');
var webrtc = require('webrtcsupport');
function PeerConnection(config, constraints) {
this.pc = new webrtc.PeerConnection(config, constraints);
WildEmitter.call(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);
});
}
}
PeerConnection.prototype = Object.create(WildEmitter.prototype, {
constructor: {
value: PeerConnection
}
});
PeerConnection.prototype.addStream = function (stream) {
this.localStream = stream;
this.pc.addStream(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);
};
PeerConnection.prototype.processIce = function (candidate) {
this.pc.addIceCandidate(new webrtc.IceCandidate(candidate));
};
PeerConnection.prototype.offer = function (constraints, cb) {
var self = this;
var hasConstraints = arguments.length === 2;
var mediaConstraints = hasConstraints ? constraints : {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
};
var callback = hasConstraints ? cb : constraints;
this.pc.createOffer(function (sessionDescription) {
self.pc.setLocalDescription(sessionDescription);
self.emit('offer', sessionDescription);
if (callback) callback(sessionDescription);
}, null, mediaConstraints);
};
PeerConnection.prototype.answerAudioOnly = function (offer, cb) {
var mediaConstraints = {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: false
}
};
this._answer(offer, mediaConstraints, cb);
};
PeerConnection.prototype.answerVideoOnly = function (offer, cb) {
var mediaConstraints = {
mandatory: {
OfferToReceiveAudio: false,
OfferToReceiveVideo: true
}
};
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(sessionDescription);
}, null, constraints);
};
PeerConnection.prototype.answer = function (offer, constraints, cb) {
var self = this;
var hasConstraints = arguments.length === 3;
var callback = hasConstraints ? cb : constraints;
var mediaConstraints = hasConstraints ? constraints : {
mandatory: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true
}
};
this._answer(offer, mediaConstraints, callback);
};
PeerConnection.prototype.handleAnswer = function (answer) {
this.pc.setRemoteDescription(new webrtc.SessionDescription(answer));
};
PeerConnection.prototype.close = function () {
this.pc.close();
this.emit('close');
};
module.exports = PeerConnection;
},{"wildemitter":1,"webrtcsupport":3}],3:[function(require,module,exports){
},{}],3:[function(require,module,exports){
// created by @HenrikJoreteg

@@ -292,4 +305,4 @@ var PC = window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection;

},{}]},{},[2])(2)
},{}]},{},[1])(1)
});
;

@@ -61,7 +61,14 @@ var WildEmitter = require('wildemitter');

this.pc.createOffer(function (sessionDescription) {
self.pc.setLocalDescription(sessionDescription);
self.emit('offer', sessionDescription);
if (callback) callback(sessionDescription);
}, null, mediaConstraints);
this.pc.createOffer(
function (sessionDescription) {
self.pc.setLocalDescription(sessionDescription);
self.emit('offer', sessionDescription);
if (callback) callback(null, sessionDescription);
},
function (err) {
self.emit('error', err);
if (callback) callback(err);
},
mediaConstraints
);
};

@@ -94,7 +101,13 @@

this.pc.setRemoteDescription(new webrtc.SessionDescription(offer));
this.pc.createAnswer(function (sessionDescription) {
self.pc.setLocalDescription(sessionDescription);
self.emit('answer', sessionDescription);
if (cb) cb(sessionDescription);
}, null, constraints);
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
);
};

@@ -101,0 +114,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc