|
|
@ -26,10 +26,12 @@ define(['jquery', 'underscore', 'rAF'], function($, _) { |
|
|
|
var webrtc = mediaStream.webrtc; |
|
|
|
var webrtc = mediaStream.webrtc; |
|
|
|
|
|
|
|
|
|
|
|
// Consider anyting lower than this % as no audio.
|
|
|
|
// Consider anyting lower than this % as no audio.
|
|
|
|
var threshhold = 7; |
|
|
|
var threshhold = 5; |
|
|
|
// Starting from this value we are considered talking.
|
|
|
|
// Starting from this value we are considered talking.
|
|
|
|
var activityThreshold = 85; |
|
|
|
var activityThreshold = 20; |
|
|
|
var activityThresholdInactivity = 40; |
|
|
|
var activityThresholdInactivity = 12; |
|
|
|
|
|
|
|
var activityMuliplier = 1.4; |
|
|
|
|
|
|
|
var activityHistorySize = 4; |
|
|
|
|
|
|
|
|
|
|
|
// Talking status history map.
|
|
|
|
// Talking status history map.
|
|
|
|
var talkingStatus = {}; |
|
|
|
var talkingStatus = {}; |
|
|
@ -58,20 +60,26 @@ define(['jquery', 'underscore', 'rAF'], function($, _) { |
|
|
|
this.update(); |
|
|
|
this.update(); |
|
|
|
|
|
|
|
|
|
|
|
// Talking state.
|
|
|
|
// Talking state.
|
|
|
|
this.audioActivityHistory = [0,0,0,0,0,0,0,0,0,0]; |
|
|
|
this.audioActivityHistory = []; |
|
|
|
this.audioActivityMeter = 0; |
|
|
|
this.audioActivityMeter = 0; |
|
|
|
this.audioActivityCount = 0; |
|
|
|
|
|
|
|
this.meter = _.bind(function() { |
|
|
|
this.meter = _.bind(function() { |
|
|
|
|
|
|
|
|
|
|
|
var talking; |
|
|
|
var talking; |
|
|
|
if (this.active) { |
|
|
|
if (this.active) { |
|
|
|
var level = Math.round(100 * webrtc.usermedia.audioLevel); |
|
|
|
var level = Math.round(100 * webrtc.usermedia.audioLevel); |
|
|
|
if (level < threshhold) { |
|
|
|
if (level < threshhold) { |
|
|
|
level = 0; |
|
|
|
level = 0; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
level = level*activityMuliplier; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.audioActivityHistory.push(level); |
|
|
|
|
|
|
|
if (this.audioActivityHistory.length > activityHistorySize) { |
|
|
|
|
|
|
|
this.audioActivityHistory.shift(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.audioActivityMeter = this.audioActivityMeter - this.audioActivityHistory[this.audioActivityCount] + level; |
|
|
|
this.audioActivityMeter = this.audioActivityHistory.reduce(function(a, b) { |
|
|
|
this.audioActivityHistory[this.audioActivityCount] = level; |
|
|
|
return a + b; |
|
|
|
this.audioActivityCount += 1; |
|
|
|
}) / this.audioActivityHistory.length; |
|
|
|
this.audioActivityCount = this.audioActivityCount % 10; |
|
|
|
|
|
|
|
//console.log("audioActivityMeter", this.audioActivityMeter, $scope.talking);
|
|
|
|
//console.log("audioActivityMeter", this.audioActivityMeter, $scope.talking);
|
|
|
|
if (!$scope.talking) { |
|
|
|
if (!$scope.talking) { |
|
|
|
talking = this.audioActivityMeter > activityThreshold ? true : false; |
|
|
|
talking = this.audioActivityMeter > activityThreshold ? true : false; |
|
|
@ -81,13 +89,13 @@ define(['jquery', 'underscore', 'rAF'], function($, _) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Clean up.
|
|
|
|
// Clean up.
|
|
|
|
//console.log("cleaning up");
|
|
|
|
//console.log("cleaning up");
|
|
|
|
this.audioActivityHistory = [0,0,0,0,0,0,0,0,0,0]; |
|
|
|
this.audioActivityHistory = []; |
|
|
|
this.audioActivityMeter = 0; |
|
|
|
this.audioActivityMeter = 0; |
|
|
|
this.audioActivityCount = 0; |
|
|
|
|
|
|
|
talking = false; |
|
|
|
talking = false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (talking !== $scope.talking) { |
|
|
|
if (talking !== $scope.talking) { |
|
|
|
// Apply to scope.
|
|
|
|
// Apply to scope.
|
|
|
|
|
|
|
|
//console.log("talking changed", talking);
|
|
|
|
safeApply($scope, function() { |
|
|
|
safeApply($scope, function() { |
|
|
|
$scope.talking = talking; |
|
|
|
$scope.talking = talking; |
|
|
|
}); |
|
|
|
}); |
|
|
|