From 78309ae133f778a4a9e234b9c4722ae855794c55 Mon Sep 17 00:00:00 2001 From: KahWee Teng Date: Fri, 28 Oct 2016 10:18:54 -0700 Subject: [PATCH] Fix VPAID methods not found and removeEventListeners * Fix vpaid-methods not being compiled into babel by using `.js` instead of `.json` * `removeEventListener` is previously not working due to incorrect bindings. --- CHANGELOG.md | 4 ++++ dist/vpaid-ad.js | 46 ++++++++++++------------------------- lib/linear.js | 4 ++-- lib/video-tracker.js | 14 +++++++---- lib/vpaid-methods.js | 3 +++ package.json | 12 +++++----- src/linear.js | 2 +- src/video-tracker.js | 12 ++++++---- src/vpaid-methods.js | 23 +++++++++++++++++++ src/vpaid-methods.json | 23 ------------------- tests/linear-spec.js | 1 - tests/video-tracker-spec.js | 4 ++-- 12 files changed, 73 insertions(+), 75 deletions(-) create mode 100644 lib/vpaid-methods.js create mode 100644 src/vpaid-methods.js delete mode 100644 src/vpaid-methods.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b76d04..9709842 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v2.1.3 -- 2016-10-28 +* Fix vpaid-methods not being compiled into babel by using `.js` instead of `.json` +* `removeEventListener` is previously not working due to incorrect bindings. + # v2.1.2 -- 2016-09-26 * Cleanup & refactor diff --git a/dist/vpaid-ad.js b/dist/vpaid-ad.js index aef3b53..e07506c 100644 --- a/dist/vpaid-ad.js +++ b/dist/vpaid-ad.js @@ -87,7 +87,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var TinyEmitter = require('tiny-emitter'); -var vpaidMethods = require('./vpaid-methods.json'); +var vpaidMethods = require('./vpaid-methods'); var VideoTracker = require('./video-tracker'); var isSupported = require('./util/is-supported'); @@ -102,7 +102,7 @@ var Linear = function (_TinyEmitter) { _inherits(Linear, _TinyEmitter); function Linear() { - var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, Linear); @@ -600,7 +600,7 @@ var Linear = function (_TinyEmitter) { Linear.prototype.setSize = require('./util/set-size'); module.exports = Linear; -},{"./util/is-supported":4,"./util/set-size":5,"./video-tracker":6,"./vpaid-methods.json":8,"tiny-emitter":1}],4:[function(require,module,exports){ +},{"./util/is-supported":4,"./util/set-size":5,"./video-tracker":6,"./vpaid-methods":8,"tiny-emitter":1}],4:[function(require,module,exports){ 'use strict'; var el = void 0; @@ -669,7 +669,7 @@ var VideoTracker = function () { * @return {[type]} [description] */ function VideoTracker(el, emitter) { - var prefix = arguments.length <= 2 || arguments[2] === undefined ? 'AdVideo' : arguments[2]; + var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'AdVideo'; _classCallCheck(this, VideoTracker); @@ -693,14 +693,18 @@ var VideoTracker = function () { }, { key: 'addEventListeners', value: function addEventListeners() { - this.el.addEventListener('timeupdate', handleTimeupdate.bind(this)); - this.el.addEventListener('ended', handleEnded.bind(this)); + this.events = { + handleTimeupdate: handleTimeupdate.bind(this), + handleEnded: handleEnded.bind(this) + }; + this.el.addEventListener('timeupdate', this.events.handleTimeupdate); + this.el.addEventListener('ended', this.events.handleEnded); } }, { key: 'removeEventListeners', value: function removeEventListeners() { - this.el.removeEventListener('timeupdate', handleTimeupdate); - this.el.removeEventListener('ended', handleEnded); + this.el.removeEventListener('timeupdate', this.events.handleTimeupdate); + this.el.removeEventListener('ended', this.events.handleEnded); } }]); @@ -715,28 +719,8 @@ module.exports = VideoTracker; module.exports = ['Start', 'FirstQuartile', 'Midpoint', 'ThirdQuartile', 'Complete']; },{}],8:[function(require,module,exports){ -module.exports=[ - "handshakeVersion", - "initAd", - "startAd", - "stopAd", - "skipAd", - "resizeAd", - "pauseAd", - "resumeAd", - "expandAd", - "collapseAd", - "getAdLinear", - "getAdWidth", - "getAdHeight", - "getAdExpanded", - "getAdadSkippableState", - "getAdRemainingTime", - "getAdDuration", - "getAdVolume", - "getAdCompanions", - "getAdIcons", - "setAdVolume" -] +'use strict'; + +module.exports = ['handshakeVersion', 'initAd', 'startAd', 'stopAd', 'skipAd', 'resizeAd', 'pauseAd', 'resumeAd', 'expandAd', 'collapseAd', 'getAdLinear', 'getAdWidth', 'getAdHeight', 'getAdExpanded', 'getAdadSkippableState', 'getAdRemainingTime', 'getAdDuration', 'getAdVolume', 'getAdCompanions', 'getAdIcons', 'setAdVolume']; },{}]},{},[2]); diff --git a/lib/linear.js b/lib/linear.js index 67b186a..703cacf 100644 --- a/lib/linear.js +++ b/lib/linear.js @@ -9,7 +9,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var TinyEmitter = require('tiny-emitter'); -var vpaidMethods = require('./vpaid-methods.json'); +var vpaidMethods = require('./vpaid-methods'); var VideoTracker = require('./video-tracker'); var isSupported = require('./util/is-supported'); @@ -24,7 +24,7 @@ var Linear = function (_TinyEmitter) { _inherits(Linear, _TinyEmitter); function Linear() { - var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, Linear); diff --git a/lib/video-tracker.js b/lib/video-tracker.js index 193cbce..139e630 100644 --- a/lib/video-tracker.js +++ b/lib/video-tracker.js @@ -41,7 +41,7 @@ var VideoTracker = function () { * @return {[type]} [description] */ function VideoTracker(el, emitter) { - var prefix = arguments.length <= 2 || arguments[2] === undefined ? 'AdVideo' : arguments[2]; + var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'AdVideo'; _classCallCheck(this, VideoTracker); @@ -65,14 +65,18 @@ var VideoTracker = function () { }, { key: 'addEventListeners', value: function addEventListeners() { - this.el.addEventListener('timeupdate', handleTimeupdate.bind(this)); - this.el.addEventListener('ended', handleEnded.bind(this)); + this.events = { + handleTimeupdate: handleTimeupdate.bind(this), + handleEnded: handleEnded.bind(this) + }; + this.el.addEventListener('timeupdate', this.events.handleTimeupdate); + this.el.addEventListener('ended', this.events.handleEnded); } }, { key: 'removeEventListeners', value: function removeEventListeners() { - this.el.removeEventListener('timeupdate', handleTimeupdate); - this.el.removeEventListener('ended', handleEnded); + this.el.removeEventListener('timeupdate', this.events.handleTimeupdate); + this.el.removeEventListener('ended', this.events.handleEnded); } }]); diff --git a/lib/vpaid-methods.js b/lib/vpaid-methods.js new file mode 100644 index 0000000..ecfd32c --- /dev/null +++ b/lib/vpaid-methods.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = ['handshakeVersion', 'initAd', 'startAd', 'stopAd', 'skipAd', 'resizeAd', 'pauseAd', 'resumeAd', 'expandAd', 'collapseAd', 'getAdLinear', 'getAdWidth', 'getAdHeight', 'getAdExpanded', 'getAdadSkippableState', 'getAdRemainingTime', 'getAdDuration', 'getAdVolume', 'getAdCompanions', 'getAdIcons', 'setAdVolume']; \ No newline at end of file diff --git a/package.json b/package.json index 53640b8..6570cbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vpaid-ad", - "version": "2.1.2", + "version": "2.1.3", "description": "VPAID ad class for extending purposes.", "main": "lib/index.js", "scripts": { @@ -24,13 +24,13 @@ }, "homepage": "https://github.com/kahwee/vpaid-ad#readme", "devDependencies": { - "babel-cli": "^6.16.0", - "babel-core": "^6.17.0", + "babel-cli": "^6.18.0", + "babel-core": "^6.18.0", "babel-istanbul": "^0.11.0", "babel-polyfill": "^6.16.0", - "babel-preset-es2015": "^6.16.0", + "babel-preset-es2015": "^6.18.0", "babelify": "^7.3.0", - "browserify": "^13.1.0", + "browserify": "^13.1.1", "browserify-istanbul": "^2.0.0", "chai": "^3.5.0", "codecov": "^1.0.1", @@ -43,7 +43,7 @@ "karma-mocha": "^1.2.0", "karma-mocha-reporter": "^2.2.0", "mocha": "^3.1.2", - "standard": "^8.4.0", + "standard": "^8.5.0", "watchify": "^3.7.0" }, "browserify": { diff --git a/src/linear.js b/src/linear.js index 722ef46..f3c2551 100644 --- a/src/linear.js +++ b/src/linear.js @@ -1,5 +1,5 @@ const TinyEmitter = require('tiny-emitter') -const vpaidMethods = require('./vpaid-methods.json') +const vpaidMethods = require('./vpaid-methods') const VideoTracker = require('./video-tracker') const isSupported = require('./util/is-supported') diff --git a/src/video-tracker.js b/src/video-tracker.js index 8166c59..b81f614 100644 --- a/src/video-tracker.js +++ b/src/video-tracker.js @@ -53,13 +53,17 @@ class VideoTracker { } addEventListeners () { - this.el.addEventListener('timeupdate', handleTimeupdate.bind(this)) - this.el.addEventListener('ended', handleEnded.bind(this)) + this.events = { + handleTimeupdate: handleTimeupdate.bind(this), + handleEnded: handleEnded.bind(this) + } + this.el.addEventListener('timeupdate', this.events.handleTimeupdate) + this.el.addEventListener('ended', this.events.handleEnded) } removeEventListeners () { - this.el.removeEventListener('timeupdate', handleTimeupdate) - this.el.removeEventListener('ended', handleEnded) + this.el.removeEventListener('timeupdate', this.events.handleTimeupdate) + this.el.removeEventListener('ended', this.events.handleEnded) } } diff --git a/src/vpaid-methods.js b/src/vpaid-methods.js new file mode 100644 index 0000000..1937b8d --- /dev/null +++ b/src/vpaid-methods.js @@ -0,0 +1,23 @@ +module.exports = [ + 'handshakeVersion', + 'initAd', + 'startAd', + 'stopAd', + 'skipAd', + 'resizeAd', + 'pauseAd', + 'resumeAd', + 'expandAd', + 'collapseAd', + 'getAdLinear', + 'getAdWidth', + 'getAdHeight', + 'getAdExpanded', + 'getAdadSkippableState', + 'getAdRemainingTime', + 'getAdDuration', + 'getAdVolume', + 'getAdCompanions', + 'getAdIcons', + 'setAdVolume' +] diff --git a/src/vpaid-methods.json b/src/vpaid-methods.json deleted file mode 100644 index 2f53a59..0000000 --- a/src/vpaid-methods.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - "handshakeVersion", - "initAd", - "startAd", - "stopAd", - "skipAd", - "resizeAd", - "pauseAd", - "resumeAd", - "expandAd", - "collapseAd", - "getAdLinear", - "getAdWidth", - "getAdHeight", - "getAdExpanded", - "getAdadSkippableState", - "getAdRemainingTime", - "getAdDuration", - "getAdVolume", - "getAdCompanions", - "getAdIcons", - "setAdVolume" -] diff --git a/tests/linear-spec.js b/tests/linear-spec.js index 658daf1..0711888 100644 --- a/tests/linear-spec.js +++ b/tests/linear-spec.js @@ -129,7 +129,6 @@ describe('Linear', function () { it('should emit getAdWidth() when it is called', function (done) { let handler = function () { linear.unsubscribe(handler, 'Hello') - console.log('hi') done() } linear.subscribe(handler, 'Hello') diff --git a/tests/video-tracker-spec.js b/tests/video-tracker-spec.js index 8f988e5..5645f95 100644 --- a/tests/video-tracker-spec.js +++ b/tests/video-tracker-spec.js @@ -54,14 +54,14 @@ describe('VideoTracker', function () { describe('life cycle #2 (for staggering)', function () { it('should emit "AdVideoFirstQuartile"', function (done) { - emitter2.on('AdVideoFirstQuartile', function () { + emitter2.once('AdVideoFirstQuartile', function () { done() }) videoSlot2.play() }) it('should emit "AdVideoThirdQuartile"', function (done) { - emitter2.on('AdVideoThirdQuartile', function () { + emitter2.once('AdVideoThirdQuartile', function () { done() }) })