Skip to content

Commit

Permalink
Bundle release 3.0.0-alpha.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kobawan committed Aug 28, 2019
1 parent bae4ecf commit e40d15c
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/vast-client-browser.min.js

Large diffs are not rendered by default.

131 changes: 128 additions & 3 deletions dist/vast-client-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var Ad = function Ad() {
this.impressionURLTemplates = [];
this.creatives = [];
this.extensions = [];
this.adVerifications = [];
};

var AdExtension =
Expand All @@ -124,6 +125,16 @@ function () {
return AdExtension;
}();

var AdVerification = function AdVerification() {
_classCallCheck(this, AdVerification);

this.resource = null;
this.vendor = null;
this.browserOptional = false;
this.apiFramework = null;
this.parameters = null;
};

var CompanionAd = function CompanionAd() {
var creativeAttributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

Expand Down Expand Up @@ -515,6 +526,30 @@ function splitVAST(ads) {
});
return splittedVAST;
}
/**
* Parses the attributes and assign them to object
* @param {Object} attributes attribute
* @param {Object} verificationObject with properties which can be assigned
*/


function assignAttributes(attributes, verificationObject) {
if (attributes) {
for (var attrKey in attributes) {
var attribute = attributes[attrKey];

if (attribute.nodeName && attribute.nodeValue && verificationObject.hasOwnProperty(attribute.nodeName)) {
var value = attribute.nodeValue;

if (typeof verificationObject[attribute.nodeName] === 'boolean') {
value = parseBoolean(value);
}

verificationObject[attribute.nodeName] = value;
}
}
}
}
/**
* Merges the data between an unwrapped ad and his wrapper.
* @param {Ad} unwrappedAd - The 'unwrapped' Ad.
Expand Down Expand Up @@ -593,6 +628,7 @@ var parserUtils = {
parseAttributes: parseAttributes,
parseDuration: parseDuration,
splitVAST: splitVAST,
assignAttributes: assignAttributes,
mergeWrapperAdData: mergeWrapperAdData
};

Expand Down Expand Up @@ -678,6 +714,7 @@ function (_Creative) {
_this.duration = 0;
_this.skipDelay = null;
_this.mediaFiles = [];
_this.mezzanine = null;
_this.videoClickThroughURLTemplate = null;
_this.videoClickTrackingURLTemplates = [];
_this.videoCustomClickURLTemplates = [];
Expand Down Expand Up @@ -728,6 +765,20 @@ var MediaFile = function MediaFile() {
this.maintainAspectRatio = null;
};

var Mezzanine = function Mezzanine() {
_classCallCheck(this, Mezzanine);

this.id = null;
this.fileURL = null;
this.delivery = null;
this.codec = null;
this.type = null;
this.width = 0;
this.height = 0;
this.fileSize = 0;
this.mediaType = '2D';
};

/**
* This module provides methods to parse a VAST Linear Element.
*/
Expand Down Expand Up @@ -840,6 +891,22 @@ function parseCreativeLinear(creativeElement, creativeAttributes) {

creative.mediaFiles.push(mediaFile);
});
var mezzanineElement = parserUtils.childByName(mediaFilesElement, 'Mezzanine');
var requiredAttributes = getRequiredAttributes(mezzanineElement, ['delivery', 'type', 'width', 'height']);

if (requiredAttributes) {
var mezzanine = new Mezzanine();
mezzanine.id = mezzanineElement.getAttribute('id');
mezzanine.fileURL = parserUtils.parseNodeText(mezzanineElement);
mezzanine.delivery = requiredAttributes.delivery;
mezzanine.codec = mezzanineElement.getAttribute('codec');
mezzanine.type = requiredAttributes.type;
mezzanine.width = parseInt(requiredAttributes.width, 10);
mezzanine.height = parseInt(requiredAttributes.height, 10);
mezzanine.fileSize = parseInt(mezzanineElement.getAttribute('fileSize'), 10);
mezzanine.mediaType = mezzanineElement.getAttribute('mediaType') || '2D';
creative.mezzanine = mezzanine;
}
});
var iconsElement = parserUtils.childByName(creativeElement, 'Icons');

Expand Down Expand Up @@ -909,6 +976,26 @@ function parseYPosition(yPosition) {

return parseInt(yPosition || 0);
}
/**
* Getting required attributes from element
* @param {Object} element - DOM element
* @param {Array} attributes - list of attributes
* @return {Object|null} null if a least one element not present
*/


function getRequiredAttributes(element, attributes) {
var values = {};
var error = false;
attributes.forEach(function (name) {
if (!element || !element.getAttribute(name)) {
error = true;
} else {
values[name] = element.getAttribute(name);
}
});
return error ? null : values;
}

var CreativeNonLinear =
/*#__PURE__*/
Expand Down Expand Up @@ -1122,6 +1209,10 @@ function parseInLine(inLineElement) {
ad.extensions = _parseExtensions(parserUtils.childrenByName(node, 'Extension'));
break;

case 'AdVerifications':
ad.adVerifications = _parseAdVerifications(parserUtils.childrenByName(node, 'Verification'));
break;

case 'AdSystem':
ad.system = {
value: parserUtils.parseNodeText(node),
Expand Down Expand Up @@ -1316,13 +1407,45 @@ function _parseExtension(extNode) {

return ext.isEmpty() ? null : ext;
}
/**
* Parses the AdVerifications Element.
* @param {Array} verifications - The array of verifications to parse.
* @return {Array<AdVerification>}
*/


function _parseAdVerifications(verifications) {
var ver = [];
verifications.forEach(function (verificationNode) {
var verification = new AdVerification();
var childNodes = verificationNode.childNodes;
parserUtils.assignAttributes(verificationNode.attributes, verification);

for (var nodeKey in childNodes) {
var node = childNodes[nodeKey];

switch (node.nodeName) {
case 'JavaScriptResource':
verification.resource = parserUtils.parseNodeText(node);
parserUtils.assignAttributes(node.attributes, verification);
break;

case 'VerificationParameters':
verification.parameters = parserUtils.parseNodeText(node);
break;
}
}

ver.push(verification);
});
return ver;
}
/**
* Parses the creative adId Attribute.
* @param {any} creativeElement - The creative element to retrieve the adId from.
* @return {String|null}
*/


function parseCreativeAdIdAttribute(creativeElement) {
return creativeElement.getAttribute('AdID') || // VAST 2 spec
creativeElement.getAttribute('adID') || // VAST 3 spec
Expand Down Expand Up @@ -2964,10 +3087,12 @@ function (_EventEmitter) {
var isAlwaysEmitEvent = this.emitAlwaysEvents.indexOf(eventName) > -1;

if (trackingURLTemplates) {
this.emit(eventName, '');
this.emit(eventName, {
trackingURLTemplates: trackingURLTemplates
});
this.trackURLs(trackingURLTemplates);
} else if (isAlwaysEmitEvent) {
this.emit(eventName, '');
this.emit(eventName, null);
}

if (once) {
Expand Down
2 changes: 1 addition & 1 deletion dist/vast-client-node.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e40d15c

Please sign in to comment.