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 1.0.0 to 1.0.1

4

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

@@ -14,3 +14,3 @@ "repository": {

"wildemitter": "0.0.5",
"rtcpeerconnection": "1.0.0",
"rtcpeerconnection": "1.0.1",
"getusermedia": "0.2.1",

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

@@ -649,4 +649,97 @@ (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;

},{}],4:[function(require,module,exports){
},{}],6:[function(require,module,exports){
var WildEmitter = require('wildemitter');
function getMaxVolume (analyser, fftBins) {
var maxVolume = -Infinity;
analyser.getFloatFrequencyData(fftBins);
for(var i=0, ii=fftBins.length; i < ii; i++) {
if (fftBins[i] > maxVolume && fftBins[i] < 0) {
maxVolume = fftBins[i];
}
};
return maxVolume;
}
module.exports = function(stream, options) {
var harker = new WildEmitter();
// make it not break in non-supported browsers
if (!window.webkitAudioContext) return harker;
//Config
var options = options || {},
smoothing = (options.smoothing || 0.5),
interval = (options.interval || 100),
threshold = options.threshold,
play = options.play;
//Setup Audio Context
var audioContext = new webkitAudioContext();
var sourceNode, fftBins, analyser;
analyser = audioContext.createAnalyser();
analyser.fftSize = 512;
analyser.smoothingTimeConstant = smoothing;
fftBins = new Float32Array(analyser.fftSize);
if (stream.jquery) stream = stream[0];
if (stream instanceof HTMLAudioElement) {
//Audio Tag
sourceNode = audioContext.createMediaElementSource(stream);
if (typeof play === 'undefined') play = true;
threshold = threshold || -65;
} else {
//WebRTC Stream
sourceNode = audioContext.createMediaStreamSource(stream);
threshold = threshold || -45;
}
sourceNode.connect(analyser);
if (play) analyser.connect(audioContext.destination);
harker.speaking = false;
harker.setThreshold = function(t) {
threshold = t;
};
harker.setInterval = function(i) {
interval = i;
};
// Poll the analyser node to determine if speaking
// and emit events if changed
var looper = function() {
setTimeout(function() {
var currentVolume = getMaxVolume(analyser, fftBins);
harker.emit('volume_change', currentVolume, threshold);
if (currentVolume > threshold) {
if (!harker.speaking) {
harker.speaking = true;
harker.emit('speaking');
}
} else {
if (harker.speaking) {
harker.speaking = false;
harker.emit('stopped_speaking');
}
}
looper();
}, interval);
};
looper();
return harker;
}
},{"wildemitter":5}],4:[function(require,module,exports){
var WildEmitter = require('wildemitter');
var webrtc = require('webrtcsupport');

@@ -656,2 +749,3 @@

function PeerConnection(config, constraints) {
var item;
this.pc = new webrtc.PeerConnection(config, constraints);

@@ -671,3 +765,14 @@ WildEmitter.call(this);

if (config.debug) {
// whether to use SDP hack for faster data transfer
this.config = {
debug: false,
sdpHack: true
};
// apply our config
for (item in config) {
this.config[item] = config[item];
}
if (this.config.debug) {
this.on('*', function (eventName, event) {

@@ -712,6 +817,7 @@ var logger = config.logger || console;

this.pc.createOffer(
function (sessionDescription) {
self.pc.setLocalDescription(sessionDescription);
self.emit('offer', sessionDescription);
if (callback) callback(null, sessionDescription);
function (offer) {
offer.sdp = self._applySdpHack(offer.sdp);
self.pc.setLocalDescription(offer);
self.emit('offer', offer);
if (callback) callback(null, offer);
},

@@ -779,6 +885,7 @@ function (err) {

this.pc.createAnswer(
function (sessionDescription) {
self.pc.setLocalDescription(sessionDescription);
self.emit('answer', sessionDescription);
if (cb) cb(null, sessionDescription);
function (answer) {
answer.sdp = self._applySdpHack(answer.sdp);
self.pc.setLocalDescription(answer);
self.emit('answer', answer);
if (cb) cb(null, answer);
}, function (err) {

@@ -813,2 +920,14 @@ self.emit('error', err);

// SDP hack for increasing AS (application specific) data transfer speed allowed in chrome
PeerConnection.prototype._applySdpHack = function (sdp) {
if (!this.config.sdpHack) return sdp;
var parts = sdp.split('b=AS:30');
if (parts.length === 2) {
// increase max data transfer bandwidth to 100 Mbps
return parts[0] + 'b=AS:102400' + parts[1];
} else {
return sdp;
}
};
module.exports = PeerConnection;

@@ -863,97 +982,4 @@

},{"webrtcsupport":2}],6:[function(require,module,exports){
var WildEmitter = require('wildemitter');
function getMaxVolume (analyser, fftBins) {
var maxVolume = -Infinity;
analyser.getFloatFrequencyData(fftBins);
for(var i=0, ii=fftBins.length; i < ii; i++) {
if (fftBins[i] > maxVolume && fftBins[i] < 0) {
maxVolume = fftBins[i];
}
};
return maxVolume;
}
module.exports = function(stream, options) {
var harker = new WildEmitter();
// make it not break in non-supported browsers
if (!window.webkitAudioContext) return harker;
//Config
var options = options || {},
smoothing = (options.smoothing || 0.5),
interval = (options.interval || 100),
threshold = options.threshold,
play = options.play;
//Setup Audio Context
var audioContext = new webkitAudioContext();
var sourceNode, fftBins, analyser;
analyser = audioContext.createAnalyser();
analyser.fftSize = 512;
analyser.smoothingTimeConstant = smoothing;
fftBins = new Float32Array(analyser.fftSize);
if (stream.jquery) stream = stream[0];
if (stream instanceof HTMLAudioElement) {
//Audio Tag
sourceNode = audioContext.createMediaElementSource(stream);
if (typeof play === 'undefined') play = true;
threshold = threshold || -65;
} else {
//WebRTC Stream
sourceNode = audioContext.createMediaStreamSource(stream);
threshold = threshold || -45;
}
sourceNode.connect(analyser);
if (play) analyser.connect(audioContext.destination);
harker.speaking = false;
harker.setThreshold = function(t) {
threshold = t;
};
harker.setInterval = function(i) {
interval = i;
};
// Poll the analyser node to determine if speaking
// and emit events if changed
var looper = function() {
setTimeout(function() {
var currentVolume = getMaxVolume(analyser, fftBins);
harker.emit('volume_change', currentVolume, threshold);
if (currentVolume > threshold) {
if (!harker.speaking) {
harker.speaking = true;
harker.emit('speaking');
}
} else {
if (harker.speaking) {
harker.speaking = false;
harker.emit('stopped_speaking');
}
}
looper();
}, interval);
};
looper();
return harker;
}
},{"wildemitter":5}]},{},[1])(1)
},{"webrtcsupport":2}]},{},[1])(1)
});
;
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