-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spine add stats and ES6 refactor (#1014)
- Loading branch information
Showing
9 changed files
with
650 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
const Erizo = require('./erizofc'); | ||
|
||
exports.Stream = (altConnection, specInput) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.