Skip to content

Commit

Permalink
Add connectivity stats to spine (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Jun 26, 2017
1 parent 6798d94 commit 78599cd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
4 changes: 4 additions & 0 deletions spine/nativeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports.ErizoNativeConnection = function (spec){
oneToMany,
externalOutput;

that.connected = false;

var CONN_INITIAL = 101,
// CONN_STARTED = 102,
Expand Down Expand Up @@ -72,11 +73,13 @@ exports.ErizoNativeConnection = function (spec){

case CONN_FAILED:
log.warn('Connection failed the ICE process');
that.connected = false;
// callback('callback', {type: 'failed', sdp: mess});
break;

case CONN_READY:
log.info('Connection ready');
that.connected = true;
if (externalInput !== undefined){
log.info('Will start External Input');
externalInput.init();
Expand Down Expand Up @@ -186,6 +189,7 @@ exports.ErizoNativeConnection = function (spec){
if (syntheticInput!==undefined){
syntheticInput.close();
}
that.connected = false;
wrtc.close();
};

Expand Down
25 changes: 22 additions & 3 deletions spine/runSpineClients.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ var efc = require ('./simpleNativeConnection');

var getopt = new Getopt([
['s' , 'stream-config=ARG' , 'file containing the stream config JSON'],
['t' , 'time=ARG' , 'interval time to show stats (default 10 seconds)'],
['h' , 'help' , 'display this help']
]);

var opt = getopt.parse(process.argv.slice(2));

var streamConfig;

var statsInterval = 10000;

for (var prop in opt.options) {
if (opt.options.hasOwnProperty(prop)) {
var value = opt.options[prop];
Expand All @@ -22,6 +25,9 @@ for (var prop in opt.options) {
case 'stream-config':
streamConfig = value;
break;
case 'time':
statsInterval = value * 1000;
break;
default:
console.log('Default');
break;
Expand Down Expand Up @@ -55,7 +61,7 @@ if (streamConfig.subscribeConfig){
console.log('StreamSubscribe', streamSubscribeConfig);
}


var streams = [];

var startStreams = function(stConf, num, time){
var started = 0;
Expand All @@ -65,14 +71,27 @@ var startStreams = function(stConf, num, time){
clearInterval(interval);
}
console.log('Will start stream with config', stConf);
efc.ErizoSimpleNativeConnection (stConf, function(msg){
streams.push(efc.ErizoSimpleNativeConnection (stConf, function(msg){
console.log('Getting Callback', msg);
}, function(msg){
console.error('Error message', msg);
});
}));
}, time);
};

setInterval(function() {
var up = 0;
var down = 0;
for (var stream of streams) {
if (stream.getStatus() === 'connected') {
up++;
} else {
down++;
}
}
console.log('[STATS] up:', up, '; down:', down);
}, statsInterval);

console.log('Starting ', streamConfig.numSubscribers, 'subscriber streams',
'and', streamConfig.numPublishers, 'publisherStreams');

Expand Down
16 changes: 15 additions & 1 deletion spine/simpleNativeConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports.ErizoSimpleNativeConnection = function (spec, callback, error){
var that = {};

var localStream = {};
var subscribedStreams = [];
var room = '';
that.isActive = false;
localStream.getID = function() {return 0;};
Expand Down Expand Up @@ -108,9 +109,10 @@ exports.ErizoSimpleNativeConnection = function (spec, callback, error){

});

room.addEventListener('stream-subscribed', function() {
room.addEventListener('stream-subscribed', function(streamEvent) {
log.info('stream-subscribed');
callback('stream-subscribed');
subscribedStreams.push(streamEvent.stream);
});

room.addEventListener('room-error', function(roomEvent) {
Expand All @@ -136,6 +138,18 @@ exports.ErizoSimpleNativeConnection = function (spec, callback, error){
room.disconnect();
};

that.getStatus = function() {
if (subscribedStreams.length === 0) {
return 'disconnected';
}
for (var stream of subscribedStreams) {
if (!stream.pc || !stream.pc.peerConnection || !stream.pc.peerConnection.connected) {
return 'disconnected';
}
}
return 'connected';
};

createConnection();
return that;
};

0 comments on commit 78599cd

Please sign in to comment.