From bf99bf6a5c4f4800e5212508007bc61fd1589912 Mon Sep 17 00:00:00 2001 From: Chris Sinchok Date: Thu, 6 Nov 2014 16:06:14 -0600 Subject: [PATCH] Pulling the trackers out into a separate method --- Gruntfile.js | 2 - spec/VastPluginSpec.js | 1 - spec/desireds.js | 82 --------------------------------- spec/sauce-wd.js | 100 ----------------------------------------- videojs.vast.js | 87 ++++++++++++++++++----------------- 5 files changed, 47 insertions(+), 225 deletions(-) delete mode 100644 spec/desireds.js delete mode 100644 spec/sauce-wd.js diff --git a/Gruntfile.js b/Gruntfile.js index d18b3d7..1999291 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -5,8 +5,6 @@ var specs = "spec/*Spec.js", var _ = require('lodash'); -var desireds = require('./spec/desireds.js'); - var gruntConfig = { env: { // dynamically filled diff --git a/spec/VastPluginSpec.js b/spec/VastPluginSpec.js index f967ee9..a6bff6d 100644 --- a/spec/VastPluginSpec.js +++ b/spec/VastPluginSpec.js @@ -236,6 +236,5 @@ describe('videojs.vast plugin', function() { }); }); - }); }); \ No newline at end of file diff --git a/spec/desireds.js b/spec/desireds.js deleted file mode 100644 index bb01d31..0000000 --- a/spec/desireds.js +++ /dev/null @@ -1,82 +0,0 @@ -'use strict'; - -module.exports = { - chrome_mav: { - browserName: 'chrome', - version: '31', - platform: 'Mac 10.9', - name: "Chrome 31 on Mavericks" - }, - chrome_snow: { - browserName: 'chrome', - version: '27', - platform: 'Mac 10.6', - name: "Chrome 27 on Snow Leopard" - }, - firefox_mav: { - browserName: 'firefox', - version: '26', - platform: 'Mac 10.9', - name: "Firefox 26 on Mavericks" - }, - // firefox_snow: { - // browserName: 'firefox', - // version: '15', - // platform: 'Mac 10.6', - // name: "Firefox 15 on Snow Leopard" - // }, - // ie8: { - // browserName: 'internet explorer', - // version: '8', - // platform: 'Windows XP', - // name: "IE 8 on Windows XP" - // }, - // ie9: { - // browserName: 'internet explorer', - // version: '9', - // platform: 'Windows 7', - // name: "IE 9 on Windows 7" - // }, - // ie10: { - // browserName: 'internet explorer', - // version: '10', - // platform: 'Windows 8', - // name: "IE 10 on Windows 8" - // }, - // ie11: { - // browserName: 'internet explorer', - // version: '11', - // platform: 'Windows 8.1', - // name: "IE 11 on Windows 8.1" - // }, - // io5: { - // browserName: 'iphone', - // version: '5.0', - // platform: 'Mac 10.6', - // name: "iPhone 5 test" - // }, - // io6: { - // browserName: 'iphone', - // version: '6.0', - // platform: 'Mac 10.8', - // name: "iPhone 6 test" - // }, - // io7: { - // browserName: 'iphone', - // version: '7.0', - // platform: 'Mac 10.9', - // name: "iPhone 7 test" - // }, - // android4: { - // browserName: 'android', - // version: '4.0', - // platform: 'Linux', - // name: "Android 4.0 test" - // }, - // android4_3: { - // browserName: 'android', - // version: '4.3', - // platform: 'Linux', - // name: "Android 4.3 test" - // } -}; \ No newline at end of file diff --git a/spec/sauce-wd.js b/spec/sauce-wd.js deleted file mode 100644 index be549a5..0000000 --- a/spec/sauce-wd.js +++ /dev/null @@ -1,100 +0,0 @@ -var wd = require('wd'); -require('colors'); -var _ = require("lodash"); -var chai = require("chai"); -var chaiAsPromised = require("chai-as-promised"); - -chai.use(chaiAsPromised); -chai.should(); -chaiAsPromised.transferPromiseness = wd.transferPromiseness; - -// checking sauce credential -if(!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY){ - console.warn( - '\nPlease configure your sauce credential:\n\n' + - 'export SAUCE_USERNAME=\n' + - 'export SAUCE_ACCESS_KEY=\n\n' - ); - throw new Error("Missing sauce credentials"); -} - -// http configuration, not needed for simple runs -wd.configureHttp( { - timeout: 60000, - retryDelay: 15000, - retries: 5 -}); - -var desired = JSON.parse(process.env.DESIRED || '{browserName: "chrome"}'); - -desired.tags = [process.env.TRAVIS_NODE_VERSION.toString(), 'CI']; -desired["tunnel-identifier"] = process.env.TRAVIS_JOB_NUMBER; - -describe('tutorial (' + desired.browserName + ')', function() { - var browser; - var allPassed = true; - - before(function(done) { - var username = process.env.SAUCE_USERNAME; - var accessKey = process.env.SAUCE_ACCESS_KEY; - browser = wd.promiseChainRemote("ondemand.saucelabs.com", 80, username, accessKey); - if(process.env.VERBOSE){ - // optional logging - browser.on('status', function(info) { - console.log(info.cyan); - }); - browser.on('command', function(meth, path, data) { - console.log(' > ' + meth.yellow, path.grey, data || ''); - }); - } - browser - .init(desired) - .nodeify(done); - }); - - afterEach(function(done) { - allPassed = allPassed && (this.currentTest.state === 'passed'); - done(); - }); - - after(function(done) { - browser - .quit() - .sauceJobStatus(allPassed) - .nodeify(done); - }); - - it("should get home page", function(done) { - browser - .get("http://nodejs.org/") - .title() - .should.become("node.js") - .elementById("intro") - .text() - .should.eventually.include('JavaScript runtime') - .nodeify(done); - }); - - _(2).times(function(i) { // repeat twice - - it("should go to the doc page (" + i + ")", function(done) { - browser - .elementById('docsbutton') - .click() - .waitForElementByCss("#content header", wd.asserters.textInclude('Manual'), 10000) - .title() - .should.eventually.include("Manual") - .nodeify(done); - }); - - it("should return to the home page(" + i + ")", function(done) { - browser - .elementById('logo') - .click() - .waitForElementById("intro", wd.asserters.textInclude('JavaScript runtime'), 10000) - .title() - .should.not.eventually.include("Manual") - .nodeify(done); - }); - }); -}); diff --git a/videojs.vast.js b/videojs.vast.js index 39c39e0..1fecb5f 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -93,46 +93,6 @@ player.vastTracker = new vast.tracker(ad, creative); - var errorOccurred = false, - canplayFn = function() { - this.vastTracker.load(); - }, - timeupdateFn = function() { - if (isNaN(this.vastTracker.assetDuration)) { - this.vastTracker.assetDuration = this.duration(); - } - this.vastTracker.setProgress(this.currentTime()); - }, - playFn = function() { - this.vastTracker.setPaused(false); - }, - pauseFn = function() { - this.vastTracker.setPaused(true); - }, - errorFn = function() { - // Inform ad server we couldn't play the media file for this ad - vast.util.track(ad.errorURLTemplates, {ERRORCODE: 405}); - errorOccurred = true; - player.trigger('ended'); - }; - - player.on('canplay', canplayFn); - player.on('timeupdate', timeupdateFn); - player.on('play', playFn); - player.on('pause', pauseFn); - player.on('error', errorFn); - - player.one('ended', function() { - player.off('canplay', canplayFn); - player.off('timeupdate', timeupdateFn); - player.off('play', playFn); - player.off('pause', pauseFn); - player.off('error', errorFn); - if (!errorOccurred) { - this.vastTracker.complete(); - } - }); - foundCreative = true; } @@ -163,6 +123,51 @@ }); }, + setupEvents: function() { + + var errorOccurred = false, + canplayFn = function() { + player.vastTracker.load(); + }, + timeupdateFn = function() { + if (isNaN(player.vastTracker.assetDuration)) { + player.vastTracker.assetDuration = player.duration(); + } + player.vastTracker.setProgress(player.currentTime()); + }, + playFn = function() { + if (player.ads.state === 'ad-playback') { + player.vastTracker.setPaused(false); + } + }, + pauseFn = function() { + player.vastTracker.setPaused(true); + }, + errorFn = function() { + // Inform ad server we couldn't play the media file for this ad + vast.util.track(player.vastTracker.ad.errorURLTemplates, {ERRORCODE: 405}); + errorOccurred = true; + player.trigger('ended'); + }; + + player.on('canplay', canplayFn); + player.on('timeupdate', timeupdateFn); + player.on('play', playFn); + player.on('pause', pauseFn); + player.on('error', errorFn); + + player.one('ended', function() { + player.off('canplay', canplayFn); + player.off('timeupdate', timeupdateFn); + player.off('play', playFn); + player.off('pause', pauseFn); + player.off('error', errorFn); + if (!errorOccurred) { + player.vastTracker.complete(); + } + }); + }, + preroll: function() { player.ads.startLinearAdMode(); player.vast.showControls = player.controls(); @@ -223,6 +228,8 @@ } }; + player.vast.setupEvents(); + player.one('ended', player.vast.tearDown); player.trigger('vast-preroll-ready');