diff --git a/dist/vast-client-browser.min.js b/dist/vast-client-browser.min.js index ddb85cfd..483183fe 100644 --- a/dist/vast-client-browser.min.js +++ b/dist/vast-client-browser.min.js @@ -1 +1 @@ -var VAST=function(e){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r=s.maxWrapperDepth||-1!==s.parentURLs.indexOf(i.nextWrapperURL))return i.errorCode=302,delete i.nextWrapperURL,t(i);i.nextWrapperURL=k.resolveVastAdTagURI(i.nextWrapperURL,a);var r=i.sequence;a=i.nextWrapperURL,s.fetchVAST(i.nextWrapperURL,n,a).then(function(e){return s.parse(e,{originalUrl:a,wrapperSequence:r,wrapperDepth:n}).then(function(e){if(delete i.nextWrapperURL,0===e.length)return i.creatives=[],t(i);e.forEach(function(e){e&&k.mergeWrapperAdData(e,i)}),t(e)})}).catch(function(e){i.errorCode=301,i.errorMessage=e.message,t(i)})})}},{key:"completeWrapperResolving",value:function(e){if(0===e.ads.length)this.trackVastError(e.errorURLTemplates,{ERRORCODE:303});else for(var t=e.ads.length-1;0<=t;t--){var r=e.ads[t];(r.errorCode||0===r.creatives.length)&&(this.trackVastError(r.errorURLTemplates.concat(e.errorURLTemplates),{ERRORCODE:r.errorCode||303},{ERRORMESSAGE:r.errorMessage||""},{extensions:r.extensions},{system:r.system}),e.ads.splice(t,1))}}}]),t}(),q=null,W={data:{},length:0,getItem:function(e){return this.data[e]},setItem:function(e,t){this.data[e]=t,this.length=Object.keys(this.data).length},removeItem:function(e){delete this.data[e],this.length=Object.keys(this.data).length},clear:function(){this.data={},this.length=0}},_=function(){function e(){l(this,e),this.storage=this.initStorage()}return n(e,[{key:"initStorage",value:function(){if(q)return q;try{q="undefined"!=typeof window&&null!==window?window.localStorage||window.sessionStorage:null}catch(e){q=null}return q&&!this.isStorageDisabled(q)||(q=W).clear(),q}},{key:"isStorageDisabled",value:function(e){var t="__VASTStorage__";try{if(e.setItem(t,t),e.getItem(t)!==t)return e.removeItem(t),!0}catch(e){return!0}return e.removeItem(t),!1}},{key:"getItem",value:function(e){return this.storage.getItem(e)}},{key:"setItem",value:function(e,t){return this.storage.setItem(e,t)}},{key:"removeItem",value:function(e){return this.storage.removeItem(e)}},{key:"clear",value:function(){return this.storage.clear()}}]),e}(),j=function(){function i(e,t,r){l(this,i),this.cappingFreeLunch=e||0,this.cappingMinimumTimeInterval=t||0,this.defaultOptions={withCredentials:!1,timeout:0},this.vastParser=new H,this.storage=r||new _,void 0===this.lastSuccessfulAd&&(this.lastSuccessfulAd=0),void 0===this.totalCalls&&(this.totalCalls=0),void 0===this.totalCallsTimeout&&(this.totalCallsTimeout=0)}return n(i,[{key:"getParser",value:function(){return this.vastParser}},{key:"hasRemainingAds",value:function(){return 0=n.totalCalls)return r(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(n.totalCalls,"/").concat(n.cappingFreeLunch)));var e=s-n.lastSuccessfulAd;if(e<0)n.lastSuccessfulAd=0;else if(e=s.maxWrapperDepth||-1!==s.parentURLs.indexOf(r.nextWrapperURL))return r.errorCode=302,delete r.nextWrapperURL,t(r);r.nextWrapperURL=R.resolveVastAdTagURI(r.nextWrapperURL,a);var i=r.sequence;a=r.nextWrapperURL,s.fetchVAST(r.nextWrapperURL,n,a).then(function(e){return s.parse(e,{originalUrl:a,wrapperSequence:i,wrapperDepth:n}).then(function(e){if(delete r.nextWrapperURL,0===e.length)return r.creatives=[],t(r);e.forEach(function(e){e&&R.mergeWrapperAdData(e,r)}),t(e)})}).catch(function(e){r.errorCode=301,r.errorMessage=e.message,t(r)})})}},{key:"completeWrapperResolving",value:function(e){if(0===e.ads.length)this.trackVastError(e.errorURLTemplates,{ERRORCODE:303});else for(var t=e.ads.length-1;0<=t;t--){var i=e.ads[t];(i.errorCode||0===i.creatives.length)&&(this.trackVastError(i.errorURLTemplates.concat(e.errorURLTemplates),{ERRORCODE:i.errorCode||303},{ERRORMESSAGE:i.errorMessage||""},{extensions:i.extensions},{system:i.system}),e.ads.splice(t,1))}}}]),t}(),X=null,z={data:{},length:0,getItem:function(e){return this.data[e]},setItem:function(e,t){this.data[e]=t,this.length=Object.keys(this.data).length},removeItem:function(e){delete this.data[e],this.length=Object.keys(this.data).length},clear:function(){this.data={},this.length=0}},Q=function(){function e(){l(this,e),this.storage=this.initStorage()}return n(e,[{key:"initStorage",value:function(){if(X)return X;try{X="undefined"!=typeof window&&null!==window?window.localStorage||window.sessionStorage:null}catch(e){X=null}return X&&!this.isStorageDisabled(X)||(X=z).clear(),X}},{key:"isStorageDisabled",value:function(e){var t="__VASTStorage__";try{if(e.setItem(t,t),e.getItem(t)!==t)return e.removeItem(t),!0}catch(e){return!0}return e.removeItem(t),!1}},{key:"getItem",value:function(e){return this.storage.getItem(e)}},{key:"setItem",value:function(e,t){return this.storage.setItem(e,t)}},{key:"removeItem",value:function(e){return this.storage.removeItem(e)}},{key:"clear",value:function(){return this.storage.clear()}}]),e}(),G=function(){function r(e,t,i){l(this,r),this.cappingFreeLunch=e||0,this.cappingMinimumTimeInterval=t||0,this.defaultOptions={withCredentials:!1,timeout:0},this.vastParser=new j,this.storage=i||new Q,void 0===this.lastSuccessfulAd&&(this.lastSuccessfulAd=0),void 0===this.totalCalls&&(this.totalCalls=0),void 0===this.totalCallsTimeout&&(this.totalCallsTimeout=0)}return n(r,[{key:"getParser",value:function(){return this.vastParser}},{key:"hasRemainingAds",value:function(){return 0=n.totalCalls)return i(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(n.totalCalls,"/").concat(n.cappingFreeLunch)));var e=s-n.lastSuccessfulAd;if(e<0)n.lastSuccessfulAd=0;else if(e 0 && arguments[0] !== undefined ? arguments[0] : {}; @@ -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. @@ -593,6 +628,7 @@ var parserUtils = { parseAttributes: parseAttributes, parseDuration: parseDuration, splitVAST: splitVAST, + assignAttributes: assignAttributes, mergeWrapperAdData: mergeWrapperAdData }; @@ -678,6 +714,7 @@ function (_Creative) { _this.duration = 0; _this.skipDelay = null; _this.mediaFiles = []; + _this.mezzanine = null; _this.videoClickThroughURLTemplate = null; _this.videoClickTrackingURLTemplates = []; _this.videoCustomClickURLTemplates = []; @@ -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. */ @@ -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'); @@ -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__*/ @@ -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), @@ -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} + */ + + +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 @@ -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) { diff --git a/dist/vast-client-node.min.js b/dist/vast-client-node.min.js index d0c195bc..149c332e 100644 --- a/dist/vast-client-node.min.js +++ b/dist/vast-client-node.min.js @@ -1 +1 @@ -"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r=s.maxWrapperDepth||-1!==s.parentURLs.indexOf(i.nextWrapperURL))return i.errorCode=302,delete i.nextWrapperURL,t(i);i.nextWrapperURL=parserUtils.resolveVastAdTagURI(i.nextWrapperURL,a);var r=i.sequence;a=i.nextWrapperURL,s.fetchVAST(i.nextWrapperURL,n,a).then(function(e){return s.parse(e,{originalUrl:a,wrapperSequence:r,wrapperDepth:n}).then(function(e){if(delete i.nextWrapperURL,0===e.length)return i.creatives=[],t(i);e.forEach(function(e){e&&parserUtils.mergeWrapperAdData(e,i)}),t(e)})}).catch(function(e){i.errorCode=301,i.errorMessage=e.message,t(i)})})}},{key:"completeWrapperResolving",value:function(e){if(0===e.ads.length)this.trackVastError(e.errorURLTemplates,{ERRORCODE:303});else for(var t=e.ads.length-1;0<=t;t--){var r=e.ads[t];(r.errorCode||0===r.creatives.length)&&(this.trackVastError(r.errorURLTemplates.concat(e.errorURLTemplates),{ERRORCODE:r.errorCode||303},{ERRORMESSAGE:r.errorMessage||""},{extensions:r.extensions},{system:r.system}),e.ads.splice(t,1))}}}]),t}(),storage=null,DEFAULT_STORAGE={data:{},length:0,getItem:function(e){return this.data[e]},setItem:function(e,t){this.data[e]=t,this.length=Object.keys(this.data).length},removeItem:function(e){delete this.data[e],this.length=Object.keys(this.data).length},clear:function(){this.data={},this.length=0}},Storage=function(){function e(){_classCallCheck(this,e),this.storage=this.initStorage()}return _createClass(e,[{key:"initStorage",value:function(){if(storage)return storage;try{storage="undefined"!=typeof window&&null!==window?window.localStorage||window.sessionStorage:null}catch(e){storage=null}return storage&&!this.isStorageDisabled(storage)||(storage=DEFAULT_STORAGE).clear(),storage}},{key:"isStorageDisabled",value:function(e){var t="__VASTStorage__";try{if(e.setItem(t,t),e.getItem(t)!==t)return e.removeItem(t),!0}catch(e){return!0}return e.removeItem(t),!1}},{key:"getItem",value:function(e){return this.storage.getItem(e)}},{key:"setItem",value:function(e,t){return this.storage.setItem(e,t)}},{key:"removeItem",value:function(e){return this.storage.removeItem(e)}},{key:"clear",value:function(){return this.storage.clear()}}]),e}(),VASTClient=function(){function i(e,t,r){_classCallCheck(this,i),this.cappingFreeLunch=e||0,this.cappingMinimumTimeInterval=t||0,this.defaultOptions={withCredentials:!1,timeout:0},this.vastParser=new VASTParser,this.storage=r||new Storage,void 0===this.lastSuccessfulAd&&(this.lastSuccessfulAd=0),void 0===this.totalCalls&&(this.totalCalls=0),void 0===this.totalCallsTimeout&&(this.totalCallsTimeout=0)}return _createClass(i,[{key:"getParser",value:function(){return this.vastParser}},{key:"hasRemainingAds",value:function(){return 0=n.totalCalls)return r(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(n.totalCalls,"/").concat(n.cappingFreeLunch)));var e=s-n.lastSuccessfulAd;if(e<0)n.lastSuccessfulAd=0;else if(e=s.maxWrapperDepth||-1!==s.parentURLs.indexOf(i.nextWrapperURL))return i.errorCode=302,delete i.nextWrapperURL,t(i);i.nextWrapperURL=parserUtils.resolveVastAdTagURI(i.nextWrapperURL,a);var r=i.sequence;a=i.nextWrapperURL,s.fetchVAST(i.nextWrapperURL,n,a).then(function(e){return s.parse(e,{originalUrl:a,wrapperSequence:r,wrapperDepth:n}).then(function(e){if(delete i.nextWrapperURL,0===e.length)return i.creatives=[],t(i);e.forEach(function(e){e&&parserUtils.mergeWrapperAdData(e,i)}),t(e)})}).catch(function(e){i.errorCode=301,i.errorMessage=e.message,t(i)})})}},{key:"completeWrapperResolving",value:function(e){if(0===e.ads.length)this.trackVastError(e.errorURLTemplates,{ERRORCODE:303});else for(var t=e.ads.length-1;0<=t;t--){var r=e.ads[t];(r.errorCode||0===r.creatives.length)&&(this.trackVastError(r.errorURLTemplates.concat(e.errorURLTemplates),{ERRORCODE:r.errorCode||303},{ERRORMESSAGE:r.errorMessage||""},{extensions:r.extensions},{system:r.system}),e.ads.splice(t,1))}}}]),t}(),storage=null,DEFAULT_STORAGE={data:{},length:0,getItem:function(e){return this.data[e]},setItem:function(e,t){this.data[e]=t,this.length=Object.keys(this.data).length},removeItem:function(e){delete this.data[e],this.length=Object.keys(this.data).length},clear:function(){this.data={},this.length=0}},Storage=function(){function e(){_classCallCheck(this,e),this.storage=this.initStorage()}return _createClass(e,[{key:"initStorage",value:function(){if(storage)return storage;try{storage="undefined"!=typeof window&&null!==window?window.localStorage||window.sessionStorage:null}catch(e){storage=null}return storage&&!this.isStorageDisabled(storage)||(storage=DEFAULT_STORAGE).clear(),storage}},{key:"isStorageDisabled",value:function(e){var t="__VASTStorage__";try{if(e.setItem(t,t),e.getItem(t)!==t)return e.removeItem(t),!0}catch(e){return!0}return e.removeItem(t),!1}},{key:"getItem",value:function(e){return this.storage.getItem(e)}},{key:"setItem",value:function(e,t){return this.storage.setItem(e,t)}},{key:"removeItem",value:function(e){return this.storage.removeItem(e)}},{key:"clear",value:function(){return this.storage.clear()}}]),e}(),VASTClient=function(){function i(e,t,r){_classCallCheck(this,i),this.cappingFreeLunch=e||0,this.cappingMinimumTimeInterval=t||0,this.defaultOptions={withCredentials:!1,timeout:0},this.vastParser=new VASTParser,this.storage=r||new Storage,void 0===this.lastSuccessfulAd&&(this.lastSuccessfulAd=0),void 0===this.totalCalls&&(this.totalCalls=0),void 0===this.totalCallsTimeout&&(this.totalCallsTimeout=0)}return _createClass(i,[{key:"getParser",value:function(){return this.vastParser}},{key:"hasRemainingAds",value:function(){return 0=n.totalCalls)return r(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(n.totalCalls,"/").concat(n.cappingFreeLunch)));var e=s-n.lastSuccessfulAd;if(e<0)n.lastSuccessfulAd=0;else if(e 0 && arguments[0] !== undefined ? arguments[0] : {}; @@ -517,6 +528,30 @@ }); 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. @@ -595,6 +630,7 @@ parseAttributes: parseAttributes, parseDuration: parseDuration, splitVAST: splitVAST, + assignAttributes: assignAttributes, mergeWrapperAdData: mergeWrapperAdData }; @@ -680,6 +716,7 @@ _this.duration = 0; _this.skipDelay = null; _this.mediaFiles = []; + _this.mezzanine = null; _this.videoClickThroughURLTemplate = null; _this.videoClickTrackingURLTemplates = []; _this.videoCustomClickURLTemplates = []; @@ -730,6 +767,20 @@ 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. */ @@ -842,6 +893,22 @@ 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'); @@ -911,6 +978,26 @@ 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__*/ @@ -1124,6 +1211,10 @@ 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), @@ -1318,13 +1409,45 @@ return ext.isEmpty() ? null : ext; } + /** + * Parses the AdVerifications Element. + * @param {Array} verifications - The array of verifications to parse. + * @return {Array} + */ + + + 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 @@ -2919,10 +3042,12 @@ 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) { diff --git a/dist/vast-client.min.js b/dist/vast-client.min.js index 567260ae..835c2222 100644 --- a/dist/vast-client.min.js +++ b/dist/vast-client.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).VAST={})}(this,function(e){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r=s.maxWrapperDepth||-1!==s.parentURLs.indexOf(i.nextWrapperURL))return i.errorCode=302,delete i.nextWrapperURL,t(i);i.nextWrapperURL=k.resolveVastAdTagURI(i.nextWrapperURL,a);var r=i.sequence;a=i.nextWrapperURL,s.fetchVAST(i.nextWrapperURL,n,a).then(function(e){return s.parse(e,{originalUrl:a,wrapperSequence:r,wrapperDepth:n}).then(function(e){if(delete i.nextWrapperURL,0===e.length)return i.creatives=[],t(i);e.forEach(function(e){e&&k.mergeWrapperAdData(e,i)}),t(e)})}).catch(function(e){i.errorCode=301,i.errorMessage=e.message,t(i)})})}},{key:"completeWrapperResolving",value:function(e){if(0===e.ads.length)this.trackVastError(e.errorURLTemplates,{ERRORCODE:303});else for(var t=e.ads.length-1;0<=t;t--){var r=e.ads[t];(r.errorCode||0===r.creatives.length)&&(this.trackVastError(r.errorURLTemplates.concat(e.errorURLTemplates),{ERRORCODE:r.errorCode||303},{ERRORMESSAGE:r.errorMessage||""},{extensions:r.extensions},{system:r.system}),e.ads.splice(t,1))}}}]),t}(),q=null,W={data:{},length:0,getItem:function(e){return this.data[e]},setItem:function(e,t){this.data[e]=t,this.length=Object.keys(this.data).length},removeItem:function(e){delete this.data[e],this.length=Object.keys(this.data).length},clear:function(){this.data={},this.length=0}},_=function(){function e(){l(this,e),this.storage=this.initStorage()}return n(e,[{key:"initStorage",value:function(){if(q)return q;try{q="undefined"!=typeof window&&null!==window?window.localStorage||window.sessionStorage:null}catch(e){q=null}return q&&!this.isStorageDisabled(q)||(q=W).clear(),q}},{key:"isStorageDisabled",value:function(e){var t="__VASTStorage__";try{if(e.setItem(t,t),e.getItem(t)!==t)return e.removeItem(t),!0}catch(e){return!0}return e.removeItem(t),!1}},{key:"getItem",value:function(e){return this.storage.getItem(e)}},{key:"setItem",value:function(e,t){return this.storage.setItem(e,t)}},{key:"removeItem",value:function(e){return this.storage.removeItem(e)}},{key:"clear",value:function(){return this.storage.clear()}}]),e}(),j=function(){function i(e,t,r){l(this,i),this.cappingFreeLunch=e||0,this.cappingMinimumTimeInterval=t||0,this.defaultOptions={withCredentials:!1,timeout:0},this.vastParser=new H,this.storage=r||new _,void 0===this.lastSuccessfulAd&&(this.lastSuccessfulAd=0),void 0===this.totalCalls&&(this.totalCalls=0),void 0===this.totalCallsTimeout&&(this.totalCallsTimeout=0)}return n(i,[{key:"getParser",value:function(){return this.vastParser}},{key:"hasRemainingAds",value:function(){return 0=n.totalCalls)return r(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(n.totalCalls,"/").concat(n.cappingFreeLunch)));var e=s-n.lastSuccessfulAd;if(e<0)n.lastSuccessfulAd=0;else if(e=s.maxWrapperDepth||-1!==s.parentURLs.indexOf(r.nextWrapperURL))return r.errorCode=302,delete r.nextWrapperURL,t(r);r.nextWrapperURL=R.resolveVastAdTagURI(r.nextWrapperURL,a);var i=r.sequence;a=r.nextWrapperURL,s.fetchVAST(r.nextWrapperURL,n,a).then(function(e){return s.parse(e,{originalUrl:a,wrapperSequence:i,wrapperDepth:n}).then(function(e){if(delete r.nextWrapperURL,0===e.length)return r.creatives=[],t(r);e.forEach(function(e){e&&R.mergeWrapperAdData(e,r)}),t(e)})}).catch(function(e){r.errorCode=301,r.errorMessage=e.message,t(r)})})}},{key:"completeWrapperResolving",value:function(e){if(0===e.ads.length)this.trackVastError(e.errorURLTemplates,{ERRORCODE:303});else for(var t=e.ads.length-1;0<=t;t--){var i=e.ads[t];(i.errorCode||0===i.creatives.length)&&(this.trackVastError(i.errorURLTemplates.concat(e.errorURLTemplates),{ERRORCODE:i.errorCode||303},{ERRORMESSAGE:i.errorMessage||""},{extensions:i.extensions},{system:i.system}),e.ads.splice(t,1))}}}]),t}(),X=null,z={data:{},length:0,getItem:function(e){return this.data[e]},setItem:function(e,t){this.data[e]=t,this.length=Object.keys(this.data).length},removeItem:function(e){delete this.data[e],this.length=Object.keys(this.data).length},clear:function(){this.data={},this.length=0}},Q=function(){function e(){l(this,e),this.storage=this.initStorage()}return n(e,[{key:"initStorage",value:function(){if(X)return X;try{X="undefined"!=typeof window&&null!==window?window.localStorage||window.sessionStorage:null}catch(e){X=null}return X&&!this.isStorageDisabled(X)||(X=z).clear(),X}},{key:"isStorageDisabled",value:function(e){var t="__VASTStorage__";try{if(e.setItem(t,t),e.getItem(t)!==t)return e.removeItem(t),!0}catch(e){return!0}return e.removeItem(t),!1}},{key:"getItem",value:function(e){return this.storage.getItem(e)}},{key:"setItem",value:function(e,t){return this.storage.setItem(e,t)}},{key:"removeItem",value:function(e){return this.storage.removeItem(e)}},{key:"clear",value:function(){return this.storage.clear()}}]),e}(),G=function(){function r(e,t,i){l(this,r),this.cappingFreeLunch=e||0,this.cappingMinimumTimeInterval=t||0,this.defaultOptions={withCredentials:!1,timeout:0},this.vastParser=new j,this.storage=i||new Q,void 0===this.lastSuccessfulAd&&(this.lastSuccessfulAd=0),void 0===this.totalCalls&&(this.totalCalls=0),void 0===this.totalCallsTimeout&&(this.totalCallsTimeout=0)}return n(r,[{key:"getParser",value:function(){return this.vastParser}},{key:"hasRemainingAds",value:function(){return 0=n.totalCalls)return i(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(n.totalCalls,"/").concat(n.cappingFreeLunch)));var e=s-n.lastSuccessfulAd;if(e<0)n.lastSuccessfulAd=0;else if(e