Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "webrtc", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"keywords": ["webrtc", "browser"], | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -34,3 +34,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; | ||
video: true | ||
} | ||
}, | ||
detectSpeakingEvents: true | ||
}; | ||
@@ -110,3 +111,3 @@ var item, connection; | ||
if (!err) { | ||
if (constraints.audio) { | ||
if (constraints.audio && self.config.detectSpeakingEvents) { | ||
self.setupAudioMonitor(stream); | ||
@@ -116,7 +117,8 @@ } | ||
self.gainController = new GainController(stream); | ||
if (self.config.autoAdjustMic) { | ||
self.gainController = new GainController(stream); | ||
// start out somewhat muted if we can track audio | ||
self.setMicIfEnabled(0.5); | ||
} | ||
// start out somewhat muted if we can track audio | ||
self.setMicIfEnabled(0.5); | ||
self.emit('localStream', stream); | ||
@@ -350,3 +352,3 @@ } | ||
},{"getusermedia":3,"hark":6,"mediastream-gain":8,"mockconsole":7,"rtcpeerconnection":4,"webrtcsupport":2,"wildemitter":5}],2:[function(require,module,exports){ | ||
},{"getusermedia":3,"hark":6,"mediastream-gain":7,"mockconsole":8,"rtcpeerconnection":4,"webrtcsupport":2,"wildemitter":5}],2:[function(require,module,exports){ | ||
// created by @HenrikJoreteg | ||
@@ -582,3 +584,3 @@ var PC = window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection; | ||
},{}],7:[function(require,module,exports){ | ||
},{}],8:[function(require,module,exports){ | ||
var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","); | ||
@@ -623,97 +625,4 @@ var l = methods.length; | ||
},{}],6:[function(require,module,exports){ | ||
},{}],4:[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'); | ||
@@ -855,3 +764,96 @@ | ||
},{"webrtcsupport":9,"wildemitter":5}],8:[function(require,module,exports){ | ||
},{"webrtcsupport":9,"wildemitter":5}],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}],7:[function(require,module,exports){ | ||
var support = require('webrtcsupport'); | ||
@@ -858,0 +860,0 @@ |
@@ -32,3 +32,4 @@ var webrtc = require('webrtcsupport'); | ||
video: true | ||
} | ||
}, | ||
detectSpeakingEvents: true | ||
}; | ||
@@ -108,3 +109,3 @@ var item, connection; | ||
if (!err) { | ||
if (constraints.audio) { | ||
if (constraints.audio && self.config.detectSpeakingEvents) { | ||
self.setupAudioMonitor(stream); | ||
@@ -114,7 +115,8 @@ } | ||
self.gainController = new GainController(stream); | ||
if (self.config.autoAdjustMic) { | ||
self.gainController = new GainController(stream); | ||
// start out somewhat muted if we can track audio | ||
self.setMicIfEnabled(0.5); | ||
} | ||
// start out somewhat muted if we can track audio | ||
self.setMicIfEnabled(0.5); | ||
self.emit('localStream', stream); | ||
@@ -121,0 +123,0 @@ } |
39048
1070