Skip to content

Commit

Permalink
spine add stats and ES6 refactor (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Aug 24, 2017
1 parent 0cd22e5 commit adcf2f5
Show file tree
Hide file tree
Showing 9 changed files with 650 additions and 504 deletions.
4 changes: 2 additions & 2 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nuve/nuveClient/build
nuve/nuveClient/dist
erizo_controller/erizoClient
spine/erizofc.js
erizo_controller/erizoClient/**/*.js
spine/**/*.js
extras/basic_example/public/erizo.js
extras/basic_example/nuve.js
extras/basic_example/public/lib/
149 changes: 73 additions & 76 deletions spine/NativeStack.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,82 @@
'use strict';
var ErizoNativeConnection = require ('./nativeClient');
// Logger
var logger = require('./logger').logger;
var log = logger.getLogger('NativeStack');

var NativeStack = function (spec) {
var that = {};
log.info('Creating a NativeStack', spec);

that.pcConfig = {
'iceServers': []
};

if (spec.iceServers !== undefined) {
that.pcConfig.iceServers = spec.iceServers;
}
const ErizoNativeConnection = require('./nativeClient');
const logger = require('./logger').logger;

const log = logger.getLogger('NativeStack');

let sessionId = 0;

const NativeStack = (config) => {
const that = {};
const configuration = Object.assign({}, config);
log.info('Creating a NativeStack', configuration);

that.pcConfig = {
iceServers: [],
};

if (config.iceServers !== undefined) {
that.pcConfig.iceServers = configuration.iceServers;
}

configuration.audio = configuration.audio || false;
configuration.video = configuration.video || false;

that.peerConnection = ErizoNativeConnection.ErizoNativeConnection(configuration);
that.desc = {};
that.callback = undefined;

if (spec.audio === undefined) {
spec.audio = false;
that.close = () => {
log.info('Close NATIVE');
if (that.peerConnection) {
that.peerConnection.close();
} else {
log.error('Trying to close with no underlying PC!');
}
};

if (spec.video === undefined) {
spec.video = false;
that.stop = () => {
that.close();
};

that.createOffer = () => {
log.info('NATIVESTACK: CreateOffer');
};

that.addStream = () => {
log.info('NATIVESTACK: addStream');
};

that.processSignalingMessage = (msg) => {
log.info('NATIVESTACK: processSignaling', msg.type);
that.peerConnection.processSignallingMessage(msg);
};

that.sendSignalingMessage = () => {
log.info('NATIVESTACK: Sending signaling Message');
};

that.peerConnection.onaddstream = (stream) => {
if (that.onaddstream) {
that.onaddstream(stream);
}
};

that.peerConnection = ErizoNativeConnection.ErizoNativeConnection(spec) ;
that.desc = {};
that.callback = undefined;

that.close = function(){
log.info('Close NATIVE');
if (that.peerConnection){
that.peerConnection.close();
} else {
log.error('Trying to close with no underlying PC!');
}
};

that.stop = function(){
that.close();
};

that.createOffer = function(){
log.info('NATIVESTACK: CreateOffer');
};

that.addStream = function(){
log.info('NATIVESTACK: addStream');
};

that.processSignalingMessage = function(msg){
log.info('NATIVESTACK: processSignaling', msg.type);
that.peerConnection.processSignallingMessage(msg);
};

that.sendSignalingMessage = function(){
log.info('NATIVESTACK: Sending signaling Message');
};

that.peerConnection.onaddstream = function (stream) {
if (that.onaddstream) {
that.onaddstream(stream);
}
};

return that;
return that;
};
var sessionId = 0;
exports.buildConnection = function(spec){
log.info('Creating Connection');
spec.sessionId = sessionId++;
return NativeStack(spec); // jshint ignore:line
exports.buildConnection = (config) => {
log.info('Creating Connection');
const configuration = Object.assign({}, config);
configuration.sessionId = sessionId;
sessionId += 1;
return NativeStack(configuration); // jshint ignore:line
};

exports.GetUserMedia = function(opt, callback){
log.info('Fake getUserMedia to use with files', opt);
// if (that.peerConnection && opt.video.file){
// that.peerConnection.prepareVideo(opt.video.file);
// }
callback('');
};
exports.getBrowser = function() {
return 'fake';
exports.GetUserMedia = (opt, callback) => {
log.info('Fake getUserMedia to use with files', opt);
// if (that.peerConnection && opt.video.file){
// that.peerConnection.prepareVideo(opt.video.file);
// }
callback('');
};

exports.getBrowser = () => 'fake';
2 changes: 0 additions & 2 deletions spine/NativeStream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const Erizo = require('./erizofc');

exports.Stream = (altConnection, specInput) => {
Expand Down
88 changes: 88 additions & 0 deletions spine/Spine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const nativeConnection = require('./simpleNativeConnection');
const logger = require('./logger').logger;

exports.buildSpine = (configuration) => {
const that = {};
that.nativeConnections = [];

const log = logger.getLogger('Spine');
const streamConfig = Object.assign({}, configuration);

let streamPublishConfig;
let streamSubscribeConfig;

if (streamConfig.publishConfig) {
streamPublishConfig = {
publishConfig: streamConfig.publishConfig,
serverUrl: streamConfig.basicExampleUrl,
};
if (streamConfig.publishersAreSubscribers) {
streamPublishConfig.subscribeConfig = streamConfig.subscribeConfig;
}
log.info('publish Configuration: ', streamSubscribeConfig);
}

if (streamConfig.subscribeConfig) {
streamSubscribeConfig = {
subscribeConfig: streamConfig.subscribeConfig,
serverUrl: streamConfig.basicExampleUrl,
};
log.info('Subscribe Configuration: ', streamSubscribeConfig);
}

const startSingleNativeClient = (clientConfig) => {
const nativeClient = nativeConnection.ErizoSimpleNativeConnection(clientConfig,
(msg) => {
log.debug('Callback from nativeClient', msg);
},
(msg) => {
log.debug('Error from nativeClient', msg);
});
that.nativeConnections.push(nativeClient);
};

const startStreams = (stConf, num, time) => {
let started = 0;
const interval = setInterval(() => {
started += 1;
if (started >= num) {
log.info('All streams have been started');
clearInterval(interval);
}
log.info('Will start stream with config', stConf);
startSingleNativeClient(stConf);
}, time);
};

that.getAllStreamStats = () => {
const promises = [];
that.nativeConnections.forEach((connection) => {
promises.push(connection.getStats());
});
return Promise.all(promises);
};

that.getAllStreamStatuses = () => {
const statuses = [];
that.nativeConnections.forEach((connection) => {
statuses.push(connection.getStatus());
});
return statuses;
};

that.run = () => {
log.info('Starting ', streamConfig.numSubscribers, 'subscriber streams',
'and', streamConfig.numPublishers, 'publisherStreams');
if (streamSubscribeConfig && streamConfig.numSubscribers) {
startStreams(streamSubscribeConfig,
streamConfig.numSubscribers,
streamConfig.connectionCreationInterval);
}
if (streamPublishConfig && streamConfig.numPublishers) {
startStreams(streamPublishConfig,
streamConfig.numPublishers,
streamConfig.connectionCreationInterval);
}
};
return that;
};
5 changes: 3 additions & 2 deletions spine/logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var log4js = require('log4js');
var logFile = './log4js_configuration.json';
const log4js = require('log4js'); // eslint-disable-line import/no-extraneous-dependencies

const logFile = './log4js_configuration.json';

log4js.configure(logFile);

Expand Down
Loading

0 comments on commit adcf2f5

Please sign in to comment.