Skip to content

Commit

Permalink
1.0 PLAT 6006 (#241)
Browse files Browse the repository at this point in the history
* PLAT-6006

use wowza flavors instead of API flavour list

* detect flavour changes in WWZ adapter
  • Loading branch information
kalturaguy authored Aug 31, 2016
1 parent 3216f54 commit 60b98ba
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions lib/Adapters/WowzaAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,45 @@ WowzaAdapter.prototype.getLiveEntries = function() {
if (incomingStreams.length === 0) {
logger.debug("No streams are currently playing");
}
// Erase duplicated stream names, e.g. 0_12345_1 and 0_12345_32
var uniqueList = _.uniq(incomingStreams, function(item) {
// Search for index of '_' and start from the second char. This fix is to _publish entries
var i = item.name.indexOf('_', 2);
var entryId;
if (i != -1) {
entryId = item.name.substr(0, i);
item.entryId = entryId;

let uniqueList={};

//filter out all unique entries and build a flavor map per entry
_.each(incomingStreams, (item) => {
let re=/([01]_[^_]+)_(?:publish_)?(.*)/.exec(item.name);
if (re && re.length===3) {
let entryId=re[1];
let flavor=re[2];
if (!uniqueList[entryId])
uniqueList[entryId]={ 'entryId': entryId,
'sourceIp': item.sourceIp,
'flavors': []};

if (item.sourceIp === "local (Transcoder)") {
uniqueList[entryId]['flavors'].push(flavor);
}
} else {
logger.warn("Unidentified stream %j",item);
}
return entryId
});
// Make sure module's entries list doesn't contain entries that are no longer streaming
logger.debug("Check for streams that are no longer playing and update list");
deleteInactiveStreams.call(that, uniqueList);
var promises = _.map(uniqueList, function(stream) {
var entryId = stream.entryId;
let flavorParamsIds = stream.flavors.join(",");
var cachedEntryInfo = that.entries[entryId];
if (cachedEntryInfo) {
//no need for API call if nothing has changed
if (cachedEntryInfo && cachedEntryInfo.flavorParamsIds===flavorParamsIds) {
return Q.resolve(cachedEntryInfo);
}
return backendClient.getEntryInfo(entryId)
.then(function(entryInfo) {
if (entryInfo) {
that.entries[entryId] = entryInfo;
entryInfo.sourceIp = stream.sourceIp;
//override flavorParamsIds with real flavors
entryInfo.flavorParamsIds = flavorParamsIds;
entryInfo.getStreamInfo = getStreamInfo;
logger.info("Received stream info for entry %s %j", entryId,entryInfo);
return Q.resolve(entryInfo);
Expand Down

0 comments on commit 60b98ba

Please sign in to comment.