From 10f8f3054b8045e0d3649d289f905e68eacf9960 Mon Sep 17 00:00:00 2001 From: Michael Vial Date: Fri, 7 Nov 2014 11:31:22 +0100 Subject: [PATCH] version 1.3.1 --- bower.json | 2 +- package.json | 2 +- vast-client.js | 69 +++++++++++++++++++++++++++++++++++--------------- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/bower.json b/bower.json index f2b58376..589a3cb0 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "vast-client-js", "author": ["Olivier Poitrey "], - "version": "1.3.0", + "version": "1.3.1", "main": "vast-client.js", "licenses": [{"type": "MIT", "url": "https://github.com/rs/vast-client-js/raw/master/LICENSE"}], "ignore": [ diff --git a/package.json b/package.json index 06b02549..20a26be7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vast-client-js", "author": "Olivier Poitrey ", - "version": "1.3.0", + "version": "1.3.1", "description": "Javascript VAST Client", "keywords": ["vast", "ad", "advertising", "iab", "in-stream", "video"], "repository": {"type": "git", "url": "https://github.com/rs/vast-client-js"}, diff --git a/vast-client.js b/vast-client.js index 1eda934e..679016d7 100644 --- a/vast-client.js +++ b/vast-client.js @@ -509,7 +509,7 @@ module.exports = VASTMediaFile; },{}],8:[function(_dereq_,module,exports){ // Generated by CoffeeScript 1.7.1 -var URLHandler, VASTAd, VASTCompanionAd, VASTCreativeCompanion, VASTCreativeLinear, VASTMediaFile, VASTParser, VASTResponse, VASTUtil, +var EventEmitter, URLHandler, VASTAd, VASTCompanionAd, VASTCreativeCompanion, VASTCreativeLinear, VASTMediaFile, VASTParser, VASTResponse, VASTUtil, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; URLHandler = _dereq_('./urlhandler.coffee'); @@ -528,6 +528,8 @@ VASTMediaFile = _dereq_('./mediafile.coffee'); VASTCompanionAd = _dereq_('./companionad.coffee'); +EventEmitter = _dereq_('events').EventEmitter; + VASTParser = (function() { var URLTemplateFilters; @@ -559,6 +561,21 @@ VASTParser = (function() { }); }; + VASTParser.vent = new EventEmitter(); + + VASTParser.track = function(templates, errorCode) { + this.vent.emit('VAST-error', errorCode); + return VASTUtil.track(templates, errorCode); + }; + + VASTParser.on = function(eventName, cb) { + return this.vent.on(eventName, cb); + }; + + VASTParser.once = function(eventName, cb) { + return this.vent.once(eventName, cb); + }; + VASTParser._parse = function(url, parentURLs, cb) { var filter, _i, _len; for (_i = 0, _len = URLTemplateFilters.length; _i < _len; _i++) { @@ -594,14 +611,17 @@ VASTParser = (function() { if (ad != null) { response.ads.push(ad); } else { - VASTUtil.track(response.errorURLTemplates, { + _this.track(response.errorURLTemplates, { ERRORCODE: 101 }); } } } - complete = function() { + complete = function(errorAlreadyRaised) { var _l, _len3, _ref2; + if (errorAlreadyRaised == null) { + errorAlreadyRaised = false; + } if (!response) { return; } @@ -613,9 +633,11 @@ VASTParser = (function() { } } if (response.ads.length === 0) { - VASTUtil.track(response.errorURLTemplates, { - ERRORCODE: 303 - }); + if (!errorAlreadyRaised) { + _this.track(response.errorURLTemplates, { + ERRORCODE: 303 + }); + } response = null; } return cb(null, response); @@ -629,7 +651,7 @@ VASTParser = (function() { (function(ad) { var baseURL, _ref2; if (parentURLs.length >= 10 || (_ref2 = ad.nextWrapperURL, __indexOf.call(parentURLs, _ref2) >= 0)) { - VASTUtil.track(ad.errorURLTemplates, { + _this.track(ad.errorURLTemplates, { ERRORCODE: 302 }); response.ads.splice(response.ads.indexOf(ad), 1); @@ -641,17 +663,20 @@ VASTParser = (function() { ad.nextWrapperURL = "" + baseURL + "/" + ad.nextWrapperURL; } return _this._parse(ad.nextWrapperURL, parentURLs, function(err, wrappedResponse) { - var creative, eventName, index, wrappedAd, _base, _l, _len3, _len4, _len5, _len6, _m, _n, _o, _ref3, _ref4, _ref5, _ref6; + var creative, errorAlreadyRaised, eventName, index, wrappedAd, _base, _l, _len3, _len4, _len5, _len6, _m, _n, _o, _ref3, _ref4, _ref5, _ref6; + errorAlreadyRaised = false; if (err != null) { - VASTUtil.track(ad.errorURLTemplates, { + _this.track(ad.errorURLTemplates, { ERRORCODE: 301 }); response.ads.splice(response.ads.indexOf(ad), 1); + errorAlreadyRaised = true; } else if (wrappedResponse == null) { - VASTUtil.track(ad.errorURLTemplates, { + _this.track(ad.errorURLTemplates, { ERRORCODE: 303 }); response.ads.splice(response.ads.indexOf(ad), 1); + errorAlreadyRaised = true; } else { response.errorURLTemplates = response.errorURLTemplates.concat(wrappedResponse.errorURLTemplates); index = response.ads.indexOf(ad); @@ -688,7 +713,7 @@ VASTParser = (function() { } } delete ad.nextWrapperURL; - return complete(); + return complete(errorAlreadyRaised); }); })(ad); } @@ -937,7 +962,7 @@ VASTParser = (function() { module.exports = VASTParser; -},{"./ad.coffee":2,"./companionad.coffee":4,"./creative.coffee":5,"./mediafile.coffee":7,"./response.coffee":9,"./urlhandler.coffee":11,"./util.coffee":14}],9:[function(_dereq_,module,exports){ +},{"./ad.coffee":2,"./companionad.coffee":4,"./creative.coffee":5,"./mediafile.coffee":7,"./response.coffee":9,"./urlhandler.coffee":11,"./util.coffee":14,"events":1}],9:[function(_dereq_,module,exports){ // Generated by CoffeeScript 1.7.1 var VASTResponse; @@ -1265,14 +1290,18 @@ XHRURLHandler = (function() { XHRURLHandler.get = function(url, cb) { var xhr; - xhr = this.xhr(); - xhr.open('GET', url); - xhr.send(); - return xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - return cb(null, xhr.responseXML); - } - }; + try { + xhr = this.xhr(); + xhr.open('GET', url); + xhr.send(); + return xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + return cb(null, xhr.responseXML); + } + }; + } catch (_error) { + return cb(); + } }; return XHRURLHandler;