From 9d6ace35221d1cd9fede877252aa259158be4844 Mon Sep 17 00:00:00 2001 From: NhJm Date: Thu, 29 May 2014 16:40:58 -0500 Subject: [PATCH 1/8] Add showSkipButton option --- videojs.vast.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/videojs.vast.js b/videojs.vast.js index b5ced25..0acc301 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -15,6 +15,7 @@ }, defaults = { + showSkipButton: true, skip: 5, }, @@ -124,6 +125,9 @@ var skipButton = document.createElement("div"); skipButton.className = "vast-skip-button"; + if (settings.showSkipButton === false) { + skipButton.style.display = "none"; + } player.vast.skipButton = skipButton; player.el().appendChild(skipButton); From b3f8bc5ebfc97f59e0740b1d9fad4c4331d75920 Mon Sep 17 00:00:00 2001 From: NhJm Date: Thu, 29 May 2014 16:44:47 -0500 Subject: [PATCH 2/8] Fix clicktracker trackURLs call --- videojs.vast.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/videojs.vast.js b/videojs.vast.js index 0acc301..3578fbf 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -117,7 +117,7 @@ blocker.onclick = function() { var clicktrackers = player.vastTracker.clickTrackingURLTemplate; if (clicktrackers) { - player.vastTracker.trackURLs(clicktrackers); + player.vastTracker.trackURLs([clicktrackers]); } }; player.vast.blocker = blocker; From c3a2f1fc11c65b05bc619459ef626365d7066069 Mon Sep 17 00:00:00 2001 From: NhJm Date: Thu, 29 May 2014 16:45:07 -0500 Subject: [PATCH 3/8] Trigger an adclick event when the ad is clicked --- videojs.vast.js | 1 + 1 file changed, 1 insertion(+) diff --git a/videojs.vast.js b/videojs.vast.js index 3578fbf..c4097b8 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -119,6 +119,7 @@ if (clicktrackers) { player.vastTracker.trackURLs([clicktrackers]); } + player.trigger("adclick"); }; player.vast.blocker = blocker; player.el().insertBefore(blocker, player.controlBar.el()); From 8487a5eee2ad3c94996a398cc28e5c0b3a67232f Mon Sep 17 00:00:00 2001 From: NhJm Date: Thu, 29 May 2014 16:46:15 -0500 Subject: [PATCH 4/8] Add contentupdate comment --- videojs.vast.js | 1 + 1 file changed, 1 insertion(+) diff --git a/videojs.vast.js b/videojs.vast.js index c4097b8..05db3af 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -34,6 +34,7 @@ return; } + // videojs-ads triggers this when src changes player.on('contentupdate', function(){ player.vast.getContent(settings.url); }); From 7b1139c66533a8458a3a04264fc4339d4d53a857 Mon Sep 17 00:00:00 2001 From: NhJm Date: Thu, 29 May 2014 16:49:14 -0500 Subject: [PATCH 5/8] Export companion ad via player.vast.companion Unhook canplay/timeupdate/play/pause events when the ad ends Add error tracking Trigger the complete event when the ad ends --- videojs.vast.js | 78 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/videojs.vast.js b/videojs.vast.js index 05db3af..51dbab1 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -48,31 +48,71 @@ if (response) { for (var adIdx = 0; adIdx < response.ads.length; adIdx++) { var ad = response.ads[adIdx]; + player.vast.companion = undefined; for (var creaIdx = 0; creaIdx < ad.creatives.length; creaIdx++) { - var linearCreative = ad.creatives[creaIdx]; - if (linearCreative.type !== "linear") continue; - - if (linearCreative.mediaFiles.length) { + var creative = ad.creatives[creaIdx], foundCreative = false, foundCompanion = false; + if (creative.type === "linear" && !foundCreative) { - player.vast.sources = player.vast.createSourceObjects(linearCreative.mediaFiles); + if (creative.mediaFiles.length) { - if (!player.vast.sources.length) { - player.trigger('adtimeout'); - return; - } + player.vast.sources = player.vast.createSourceObjects(creative.mediaFiles); - player.vastTracker = new vast.tracker(ad, linearCreative); - player.on('canplay', function() {this.vastTracker.load();}); - player.on('timeupdate', function() { - if (isNaN(this.vastTracker.assetDuration)) { - this.vastTracker.assetDuration = this.duration(); + if (!player.vast.sources.length) { + player.trigger('adtimeout'); + return; } - this.vastTracker.setProgress(this.currentTime()); - }); - player.on('play', function() {this.vastTracker.setPaused(false);}); - player.on('pause', function() {this.vastTracker.setPaused(true);}); - break; + 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; + } + + } else if (creative.type === "companion" && !foundCompanion) { + + player.vast.companion = creative; + + foundCompanion = true; + } } From 1a2f794ff4bbebdee14ddd3d790b3e7d3c1a349d Mon Sep 17 00:00:00 2001 From: NhJm Date: Thu, 29 May 2014 16:55:24 -0500 Subject: [PATCH 6/8] Add support for multiple sources of the same type to player.vast.createSourceObjects().. also keep width/height. --- videojs.vast.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/videojs.vast.js b/videojs.vast.js index 51dbab1..e2d32de 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -210,28 +210,34 @@ } }; player.vast.createSourceObjects = function(media_files) { - var fileURLs = {}; + var sourcesByFormat = {}; var vidFormats = ['video/mp4', 'video/webm', 'video/ogv']; // get a list of files with unique formats for (var i = 0; i < media_files.length; i++) { var file_url = media_files[i].fileURL; - var mime_type = media_files[i].mimeType; + var format = media_files[i].mimeType; - if (vidFormats.indexOf(mime_type) >= 0) { - if(fileURLs[mime_type] === undefined) { - fileURLs[mime_type] = file_url; - } + if (vidFormats.indexOf(format) >= 0) { + if(sourcesByFormat[format] === undefined) { + sourcesByFormat[format] = []; + } + sourcesByFormat[format].push({ + type: format, + src: file_url, + width: media_files[i].width, + height: media_files[i].height + }); } } + // Create sources in preferred format order var sources = []; for (var j=0; j < vidFormats.length; j++) { var format = vidFormats[j]; - if (fileURLs[format] !== undefined) { - sources.push({ - type: format, - src: fileURLs[format] - }); + if (sourcesByFormat[format] !== undefined) { + for (var i = 0; i < sourcesByFormat[format].length; i++) { + sources.push(sourcesByFormat[format][i]); + } } } return sources; From 0ec444f987904f1cff716fcf35e67e2b5f613d46 Mon Sep 17 00:00:00 2001 From: NhJm Date: Fri, 30 May 2014 12:29:46 -0500 Subject: [PATCH 7/8] createSourceObjects: update spec file, silence jshint --- spec/VastPluginSpec.js | 52 ++++++++++++++++++++++++++++++------------ videojs.vast.js | 13 +++++------ 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/spec/VastPluginSpec.js b/spec/VastPluginSpec.js index 20705e3..52505f6 100644 --- a/spec/VastPluginSpec.js +++ b/spec/VastPluginSpec.js @@ -84,21 +84,27 @@ describe("createSourceObjects", function() { - it("should return objects with 'src' and 'type' properties", function() { + it("should return objects with 'src', 'type', 'width', and 'height' properties", function() { var media_files = [ { fileURL: "TRL", - mimeType: "video/webm" + mimeType: "video/webm", + width: 640, + height: 360 }, { fileURL: "BuddhaForRill", - mimeType: "video/mp4" + mimeType: "video/mp4", + width: 0, + height: 0 } ]; var sources = player.vast.createSourceObjects(media_files); for (var s in sources) { expect(sources[s].src).toBeDefined(); expect(sources[s].type).toBeDefined(); + expect(sources[s].width).toBeDefined(); + expect(sources[s].height).toBeDefined(); } }); @@ -106,50 +112,68 @@ var media_files = [ { fileURL: "TRL", - mimeType: "video/flv" + mimeType: "video/flv", + width: 640, + height: 360 }, { fileURL: "So Trill", - mimeType: "video/x-flv" + mimeType: "video/x-flv", + width: 512, + height: 288 }, { fileURL: "Skrill, WHERES MY SKRILL", - mimeType: "video/mpeg" + mimeType: "video/mpeg", + width: 0, + height: 0 }, { fileURL: "Jack and Jill", - mimeType: "video/ogg" + mimeType: "video/ogg", + width: 1280, + height: 720 }, { fileURL: "-- Code Raps -- ", - mimeType: "hls/playlist.m3u8" + mimeType: "hls/playlist.m3u8", + width: 640, + height: 480 }, { fileURL: "I'm tapped", - mimeType: "video/avi" + mimeType: "video/avi", + width: 512, + height: 384 }, { fileURL: "BuddhaForRill", - mimeType: "video/mp4" + mimeType: "video/mp4", + width: 1920, + height: 1080 } ]; var sources = player.vast.createSourceObjects(media_files); expect(sources.length).toBe(1); }); - it("returns sources with unique formats", function() { + it("can return sources with duplicate formats", function() { var media_files = [ { fileURL: "TRL", - mimeType: "video/mp4" + mimeType: "video/mp4", + width: 640, + height: 360 }, { fileURL: "BuddhaForRill", - mimeType: "video/mp4" + mimeType: "video/mp4", + width: 853, + height: 480 } ]; var sources = player.vast.createSourceObjects(media_files); - expect(sources.length).toBe(1); + expect(sources.length).toBe(2); }); }); diff --git a/videojs.vast.js b/videojs.vast.js index e2d32de..a096814 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -210,12 +210,11 @@ } }; player.vast.createSourceObjects = function(media_files) { - var sourcesByFormat = {}; + var sourcesByFormat = {}, format, i; var vidFormats = ['video/mp4', 'video/webm', 'video/ogv']; // get a list of files with unique formats - for (var i = 0; i < media_files.length; i++) { - var file_url = media_files[i].fileURL; - var format = media_files[i].mimeType; + for (i = 0; i < media_files.length; i++) { + format = media_files[i].mimeType; if (vidFormats.indexOf(format) >= 0) { if(sourcesByFormat[format] === undefined) { @@ -223,7 +222,7 @@ } sourcesByFormat[format].push({ type: format, - src: file_url, + src: media_files[i].fileURL, width: media_files[i].width, height: media_files[i].height }); @@ -233,9 +232,9 @@ // Create sources in preferred format order var sources = []; for (var j=0; j < vidFormats.length; j++) { - var format = vidFormats[j]; + format = vidFormats[j]; if (sourcesByFormat[format] !== undefined) { - for (var i = 0; i < sourcesByFormat[format].length; i++) { + for (i = 0; i < sourcesByFormat[format].length; i++) { sources.push(sourcesByFormat[format][i]); } } From 4a98fec842e7751a963c726fab8694897a8a9b59 Mon Sep 17 00:00:00 2001 From: NhJm Date: Fri, 30 May 2014 12:41:45 -0500 Subject: [PATCH 8/8] Replace options.showSkipButton=false with options.skip=negative --- videojs.vast.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/videojs.vast.js b/videojs.vast.js index a096814..f1c34a5 100644 --- a/videojs.vast.js +++ b/videojs.vast.js @@ -15,8 +15,7 @@ }, defaults = { - showSkipButton: true, - skip: 5, + skip: 5 // negative disables }, vastPlugin = function(options) { @@ -167,7 +166,7 @@ var skipButton = document.createElement("div"); skipButton.className = "vast-skip-button"; - if (settings.showSkipButton === false) { + if (settings.skip < 0) { skipButton.style.display = "none"; } player.vast.skipButton = skipButton;