Skip to content

Commit

Permalink
Enabling rtcp stats subscriptions (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Alonso authored Jun 6, 2017
1 parent 33c7f5a commit c813ef2
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 6 deletions.
5 changes: 3 additions & 2 deletions erizo_controller/erizoClient/src/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Erizo.getBrowser = function () {
} else if (window.navigator.userAgent.match('Chrome') !== null) {
browser = 'chrome-stable';
if (window.navigator.userAgent.match('Electron') !== null) {
browser = 'electron'
browser = 'electron';
}
} else if (window.navigator.userAgent.match('Safari') !== null) {
browser = 'bowser';
Expand Down Expand Up @@ -119,7 +119,8 @@ Erizo.GetUserMedia = function (config, callback, error) {
}
L.Logger.debug('Screen access on chrome stable, looking for extension');
try {
chrome.runtime.sendMessage(extensionId, {getStream: true}, function (response){
chrome.runtime.sendMessage(extensionId, {getStream: true},
function (response){
var theConfig = {};
if (response === undefined){
L.Logger.error('Access to screen denied');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Erizo.ChromeStableStack = function (spec) {

localDesc.sdp = setMaxBW(localDesc.sdp);
if (config.Sdp || config.maxAudioBW){
L.Logger.debug ('Updating with SDP renegotiation', spec.maxVideoBW, spec.maxAudioBW);
L.Logger.debug('Updating with SDP renegotiation', spec.maxVideoBW, spec.maxAudioBW);
that.peerConnection.setLocalDescription(localDesc, function () {
remoteDesc.sdp = setMaxBW(remoteDesc.sdp);
that.peerConnection.setRemoteDescription(
Expand Down
1 change: 1 addition & 0 deletions erizo_controller/erizoJS/erizoJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ amqper.connect(function () {

log.info('message: Started, erizoId: ' + rpcID);

amqper.bindBroadcast('ErizoJS');
amqper.bind('ErizoJS_' + rpcID, function() {
log.debug('message: bound to amqp queue, queueId: ErizoJS_' + rpcID );

Expand Down
67 changes: 66 additions & 1 deletion erizo_controller/erizoJS/erizoJSController.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ exports.ErizoJSController = function (threadPool) {
var that = {},
// {id1: Publisher, id2: Publisher}
publishers = {},
// {streamId: {timeout: timeout, interval: interval}}
statsSubscriptions = {},

MIN_SLIDESHOW_PERIOD = 2000,
MAX_SLIDESHOW_PERIOD = 10000,
Expand All @@ -33,6 +35,7 @@ exports.ErizoJSController = function (threadPool) {
WARN_CONFLICT = 409,
WARN_PRECOND_FAILED = 412,
WARN_BAD_CONNECTION = 502;

that.publishers = publishers;

/*
Expand Down Expand Up @@ -556,5 +559,67 @@ exports.ErizoJSController = function (threadPool) {
}
};

that.subscribeToStats = function (to, timeout, interval, callback) {

var publisher;
log.debug('message: Requested subscription to stream stats, streamID: ' + to);

if (to && publishers[to]) {
publisher = publishers[to];

if (GLOBAL.config.erizoController.reportSubscriptions &&
GLOBAL.config.erizoController.reportSubscriptions.maxSubscriptions > 0) {

if (timeout > GLOBAL.config.erizoController.reportSubscriptions.maxTimeout)
timeout = GLOBAL.config.erizoController.reportSubscriptions.maxTimeout;
if (interval < GLOBAL.config.erizoController.reportSubscriptions.minInterval)
interval = GLOBAL.config.erizoController.reportSubscriptions.minInterval;

if (statsSubscriptions[to]) {
log.debug('message: Renewing subscription to stream: ' + to);
clearTimeout(statsSubscriptions[to].timeout);
clearInterval(statsSubscriptions[to].interval);
} else if (Object.keys(statsSubscriptions).length <
GLOBAL.config.erizoController.reportSubscriptions.maxSubscriptions){
statsSubscriptions[to] = {};
}

if (!statsSubscriptions[to]) {
log.debug('message: Max Subscriptions limit reached, ignoring message');
return;
}

statsSubscriptions[to].interval = setInterval(function () {
let promises = [];
let stats = {};

stats.streamId = to;
promises.push(getWrtcStats('publisher', stats, publisher.wrtc));

for (var sub in publisher.subscribers) {
promises.push(getWrtcStats(sub, stats, publisher.subscribers[sub]));
}

Promise.all(promises).then(() => {
amqper.broadcast('stats_subscriptions', stats);
});

}, interval*1000);

statsSubscriptions[to].timeout = setTimeout(function () {
clearInterval(statsSubscriptions[to].interval);
delete statsSubscriptions[to];
}, timeout*1000);

callback('success');

} else {
log.debug('message: Report subscriptions disabled by config, ignoring message');
}
} else {
log.debug('message: Im not handling this stream, ignoring message, streamID: ' + to);
}
};

return that;
};
};
5 changes: 3 additions & 2 deletions extras/basic_example/public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ window.onload = function () {
} else {
var div = document.createElement('div');
div.setAttribute('style', 'width: 320px; height: 240px; float:left');
div.setAttribute('id', 'myVideo');
document.getElementById('videoContainer').appendChild(div);

localStream.addEventListener('access-accepted', function () {
room.connect();
localStream.show('myVideo');
});
localStream.init();
}
div.setAttribute('id', 'myVideo');
document.getElementById('videoContainer').appendChild(div);
});
};
7 changes: 7 additions & 0 deletions scripts/licode_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ config.erizoController.report = {
rtcp_stats: false // RTCP stats -- default value: false
};

// Subscriptions to rtcp_stats via AMQP
config.erizoController.reportSubscriptions = {
maxSubscriptions: 10, // per ErizoJS -- set 0 to disable subscriptions -- default 10
minInterval: 1, // in seconds -- default 1
maxTimeout: 60 // in seconds -- default 60
};

// If undefined, the path will be /tmp/
config.erizoController.recording_path = undefined; // default value: undefined

Expand Down

0 comments on commit c813ef2

Please sign in to comment.