Socket
Socket
Sign inDemoInstall

webrtc

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webrtc - npm Package Compare versions

Comparing version 0.5.3 to 1.0.0

6

package.json
{
"name": "webrtc",
"version": "0.5.3",
"version": "1.0.0",
"keywords": ["webrtc", "browser"],

@@ -12,5 +12,5 @@ "repository": {

"dependencies": {
"webrtcsupport": "0.5.0",
"webrtcsupport": "0.7.0",
"wildemitter": "0.0.5",
"rtcpeerconnection": "0.3.1",
"rtcpeerconnection": "1.0.0",
"getusermedia": "0.2.1",

@@ -17,0 +17,0 @@ "hark": "0.1.1",

@@ -35,3 +35,4 @@ (function(e){if("function"==typeof bootstrap)bootstrap("webrtc",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.makeWebRTC=e}else"undefined"!=typeof window?window.WebRTC=e():global.WebRTC=e()})(function(){var define,ses,bootstrap,module,exports;

},
detectSpeakingEvents: true
detectSpeakingEvents: true,
enableDataChannels: true
};

@@ -248,2 +249,3 @@ var item, connection;

this.stream = options.stream;
this.channels = {};
// Create an RTCPeerConnection via the polyfill

@@ -253,3 +255,9 @@ this.pc = new PeerConnection(this.parent.config.peerConnectionConfig, this.parent.config.peerConnectionContraints);

this.pc.on('addStream', this.handleRemoteStreamAdded.bind(this));
this.pc.on('addChannel', this.handleDataChannelAdded.bind(this));
this.pc.on('removeStream', this.handleStreamRemoved.bind(this));
// Just fire negotiation needed events for now
// When browser re-negotiation handling seems to work
// we can use this as the trigger for starting the offer/answer process
// automatically. We'll just leave it be for now while this stabalizes.
this.pc.on('negotiationNeeded', this.emit.bind(this, 'negotiationNeeded'));
this.logger = this.parent.logger;

@@ -268,2 +276,12 @@

if (this.parent.config.enableDataChannels && webrtc.dataChannel) {
// we may not have reliable channels
try {
this.reliableChannel = this.getDataChannel('reliable', {reliable: true});
} catch (e) {
this.reliableChannel = false;
}
this.unreliableChannel = this.getDataChannel('unreliable', {reliable: false});
}
// call emitter constructor

@@ -273,4 +291,4 @@ WildEmitter.call(this);

// proxy events to parent
this.on('*', function (name, value) {
self.parent.emit(name, value, self);
this.on('*', function () {
self.parent.emit.apply(self.parent, arguments);
});

@@ -320,2 +338,25 @@ }

// Internal method registering handlers for a data channel and emitting events on the peer
Peer.prototype._observeDataChannel = function (channel) {
var self = this;
channel.onclose = this.emit.bind(this, 'channelClose', channel);
channel.onerror = this.emit.bind(this, 'channelError', channel);
channel.onmessage = function (event) {
self.emit('message', channel.label, event.data, channel, event);
};
channel.onopen = this.emit.bind(this, 'channelOpen', channel);
};
// Fetch or create a data channel by the given name
Peer.prototype.getDataChannel = function (name, opts) {
if (!webrtc.dataChannel) return this.emit('error', new Error('createDataChannel not supported'));
var channel = this.channels[name];
opts || (opts = {reliable: false});
if (channel) return channel;
// if we don't have one by this label, create it
channel = this.channels[name] = this.pc.pc.createDataChannel(name, opts);
this._observeDataChannel(channel);
return channel;
};
Peer.prototype.onIceCandidate = function (candidate) {

@@ -343,4 +384,8 @@ if (this.closed) return;

Peer.prototype.handleRemoteStreamAdded = function (event) {
this.stream = event.stream;
this.parent.emit('peerStreamAdded', this);
if (this.stream) {
this.logger.warn('Already have a remote stream');
} else {
this.stream = event.stream;
this.parent.emit('peerStreamAdded', this);
}
};

@@ -354,2 +399,6 @@

Peer.prototype.handleDataChannelAdded = function (channel) {
this.channels[channel.name] = channel;
};
module.exports = WebRTC;

@@ -359,12 +408,19 @@

// 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;

@@ -374,10 +430,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,

@@ -602,30 +659,2 @@ PeerConnection: PC,

},{}],9:[function(require,module,exports){
// created by @HenrikJoreteg
var PC = window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection;
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 screenSharing = navigator.userAgent.match('Chrome') && parseInt(navigator.userAgent.match(/Chrome\/(.*) /)[1], 10) >= 26;
var AudioContext = window.webkitAudioContext || window.AudioContext;
// export support flags and constructors.prototype && PC
module.exports = {
support: !!PC,
dataChannel: !!(PC && PC.prototype && PC.prototype.createDataChannel),
prefix: prefix,
webAudio: !!(AudioContext && AudioContext.prototype.createMediaStreamSource),
screenSharing: screenSharing,
AudioContext: AudioContext,
PeerConnection: PC,
SessionDescription: SessionDescription,
IceCandidate: IceCandidate
};
},{}],4:[function(require,module,exports){

@@ -639,9 +668,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);
});

@@ -657,2 +695,3 @@ }

// Add a stream to the peer connection object
PeerConnection.prototype.addStream = function (stream) {

@@ -663,18 +702,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) {

@@ -684,2 +709,3 @@ this.pc.addIceCandidate(new webrtc.IceCandidate(candidate));

// Generate and emit an offer with the given constraints
PeerConnection.prototype.offer = function (constraints, cb) {

@@ -696,2 +722,3 @@ var self = this;

// Actually generate the offer
this.pc.createOffer(

@@ -711,2 +738,3 @@ function (sessionDescription) {

// Answer an offer with audio only
PeerConnection.prototype.answerAudioOnly = function (offer, cb) {

@@ -719,6 +747,6 @@ var mediaConstraints = {

};
this._answer(offer, mediaConstraints, cb);
};
// Answer an offer without offering to recieve
PeerConnection.prototype.answerBroadcastOnly = function (offer, cb) {

@@ -731,22 +759,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) {

@@ -766,2 +778,3 @@ var self = this;

// Process an answer
PeerConnection.prototype.handleAnswer = function (answer) {

@@ -771,2 +784,3 @@ this.pc.setRemoteDescription(new webrtc.SessionDescription(answer));

// Close the peer connection
PeerConnection.prototype.close = function () {

@@ -777,5 +791,90 @@ 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;
},{"webrtcsupport":9,"wildemitter":5}],6:[function(require,module,exports){
},{"webrtcsupport":2,"wildemitter":5}],7:[function(require,module,exports){
var support = require('webrtcsupport');
function GainController(stream) {
this.support = support.webAudio && support.mediaStream;
// set our starting value
this.gain = 1;
if (this.support) {
var context = this.context = new support.AudioContext();
this.microphone = context.createMediaStreamSource(stream);
this.gainFilter = context.createGain();
this.destination = context.createMediaStreamDestination();
this.outputStream = this.destination.stream;
this.microphone.connect(this.gainFilter);
this.gainFilter.connect(this.destination);
stream.removeTrack(stream.getAudioTracks()[0]);
stream.addTrack(this.outputStream.getAudioTracks()[0]);
}
this.stream = stream;
}
// setting
GainController.prototype.setGain = function (val) {
// check for support
if (!this.support) return;
this.gainFilter.gain.value = val;
this.gain = val;
};
GainController.prototype.getGain = function () {
return this.gain;
};
GainController.prototype.off = function () {
return this.setGain(0);
};
GainController.prototype.on = function () {
this.setGain(1);
};
module.exports = GainController;
},{"webrtcsupport":2}],6:[function(require,module,exports){
var WildEmitter = require('wildemitter');

@@ -873,51 +972,4 @@

},{"wildemitter":5}],7:[function(require,module,exports){
var support = require('webrtcsupport');
function GainController(stream) {
this.support = support.webAudio && support.mediaStream;
// set our starting value
this.gain = 1;
if (this.support) {
var context = this.context = new support.AudioContext();
this.microphone = context.createMediaStreamSource(stream);
this.gainFilter = context.createGain();
this.destination = context.createMediaStreamDestination();
this.outputStream = this.destination.stream;
this.microphone.connect(this.gainFilter);
this.gainFilter.connect(this.destination);
stream.removeTrack(stream.getAudioTracks()[0]);
stream.addTrack(this.outputStream.getAudioTracks()[0]);
}
this.stream = stream;
}
// setting
GainController.prototype.setGain = function (val) {
// check for support
if (!this.support) return;
this.gainFilter.gain.value = val;
this.gain = val;
};
GainController.prototype.getGain = function () {
return this.gain;
};
GainController.prototype.off = function () {
return this.setGain(0);
};
GainController.prototype.on = function () {
this.setGain(1);
};
module.exports = GainController;
},{"webrtcsupport":2}]},{},[1])(1)
},{"wildemitter":5}]},{},[1])(1)
});
;

@@ -33,3 +33,4 @@ var webrtc = require('webrtcsupport');

},
detectSpeakingEvents: true
detectSpeakingEvents: true,
enableDataChannels: true
};

@@ -246,2 +247,3 @@ var item, connection;

this.stream = options.stream;
this.channels = {};
// Create an RTCPeerConnection via the polyfill

@@ -251,3 +253,9 @@ this.pc = new PeerConnection(this.parent.config.peerConnectionConfig, this.parent.config.peerConnectionContraints);

this.pc.on('addStream', this.handleRemoteStreamAdded.bind(this));
this.pc.on('addChannel', this.handleDataChannelAdded.bind(this));
this.pc.on('removeStream', this.handleStreamRemoved.bind(this));
// Just fire negotiation needed events for now
// When browser re-negotiation handling seems to work
// we can use this as the trigger for starting the offer/answer process
// automatically. We'll just leave it be for now while this stabalizes.
this.pc.on('negotiationNeeded', this.emit.bind(this, 'negotiationNeeded'));
this.logger = this.parent.logger;

@@ -266,2 +274,12 @@

if (this.parent.config.enableDataChannels && webrtc.dataChannel) {
// we may not have reliable channels
try {
this.reliableChannel = this.getDataChannel('reliable', {reliable: true});
} catch (e) {
this.reliableChannel = false;
}
this.unreliableChannel = this.getDataChannel('unreliable', {reliable: false});
}
// call emitter constructor

@@ -271,4 +289,4 @@ WildEmitter.call(this);

// proxy events to parent
this.on('*', function (name, value) {
self.parent.emit(name, value, self);
this.on('*', function () {
self.parent.emit.apply(self.parent, arguments);
});

@@ -318,2 +336,25 @@ }

// Internal method registering handlers for a data channel and emitting events on the peer
Peer.prototype._observeDataChannel = function (channel) {
var self = this;
channel.onclose = this.emit.bind(this, 'channelClose', channel);
channel.onerror = this.emit.bind(this, 'channelError', channel);
channel.onmessage = function (event) {
self.emit('message', channel.label, event.data, channel, event);
};
channel.onopen = this.emit.bind(this, 'channelOpen', channel);
};
// Fetch or create a data channel by the given name
Peer.prototype.getDataChannel = function (name, opts) {
if (!webrtc.dataChannel) return this.emit('error', new Error('createDataChannel not supported'));
var channel = this.channels[name];
opts || (opts = {reliable: false});
if (channel) return channel;
// if we don't have one by this label, create it
channel = this.channels[name] = this.pc.pc.createDataChannel(name, opts);
this._observeDataChannel(channel);
return channel;
};
Peer.prototype.onIceCandidate = function (candidate) {

@@ -341,4 +382,8 @@ if (this.closed) return;

Peer.prototype.handleRemoteStreamAdded = function (event) {
this.stream = event.stream;
this.parent.emit('peerStreamAdded', this);
if (this.stream) {
this.logger.warn('Already have a remote stream');
} else {
this.stream = event.stream;
this.parent.emit('peerStreamAdded', this);
}
};

@@ -352,2 +397,6 @@

Peer.prototype.handleDataChannelAdded = function (channel) {
this.channels[channel.name] = channel;
};
module.exports = WebRTC;
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