Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:theonion/videojs-vast-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sinchok committed Nov 18, 2014
2 parents 342af6e + ebe59f0 commit 565e0ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"dependencies": {
"videojs": "4.4.3",
"vast-client-js": "1.1.2",
"videojs-contrib-ads": "0.4.0"
"videojs-contrib-ads": "0.5.0"
}
}
22 changes: 12 additions & 10 deletions spec/VastPluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ describe('videojs.vast plugin', function() {
}
})();
player = videojs(id);
player.ads();
player.vast({
url: ""
});
// player.ads();
// player.vast({
// url: ""
// });
});


Expand Down Expand Up @@ -70,11 +70,11 @@ describe('videojs.vast plugin', function() {
});

it("should bail out if no url is provided", function() {
spyOn(this.p, "trigger");
this.p.ads();
var result = this.p.vast({});
expect(result).toBe(null);
expect(this.p.trigger).toHaveBeenCalledWith("adtimeout");
spyOn(this.p, "trigger").and.callThrough();
this.p.trigger('readyforpreroll');
expect(this.p.trigger).toHaveBeenCalledWith("adscanceled");
});

it("should request an ad if a source is already loaded", function() {
Expand Down Expand Up @@ -122,6 +122,7 @@ describe('videojs.vast plugin', function() {
describe("tearDown", function() {

it("should end the linear ad", function() {
player.ads();
player.vast({ url: 'balhbahblhab' });

spyOn(player.ads, "endLinearAdMode");
Expand All @@ -143,6 +144,7 @@ describe('videojs.vast plugin', function() {
describe("preroll", function() {

beforeEach(function() {
player.ads();
player.vast({ url: 'balhbahblhab' });
player.vastTracker = {
clickThroughURLTemplate: "a whole new page",
Expand All @@ -163,7 +165,7 @@ describe('videojs.vast plugin', function() {
});

it("should end the ad", function() {
spyOn(player, "one");
spyOn(player, "one");
player.vast.preroll();
expect(player.one).toHaveBeenCalledWith("ended", jasmine.any(Function));
});
Expand All @@ -187,7 +189,7 @@ describe('videojs.vast plugin', function() {

spyOn(player, "trigger");
player.vast.getContent("some url");
expect(player.trigger).toHaveBeenCalledWith("adtimeout");
expect(player.trigger).toHaveBeenCalledWith("adscanceled");
});

describe("linear ads", function() {
Expand Down Expand Up @@ -231,7 +233,7 @@ describe('videojs.vast plugin', function() {
expect(DMVAST.util.track).toHaveBeenCalledWith(
jasmine.any(String), jasmine.any(Object)
);
expect(player.trigger).toHaveBeenCalledWith("adtimeout");
expect(player.trigger).toHaveBeenCalledWith("adscanceled");
});
});

Expand Down
27 changes: 11 additions & 16 deletions videojs.vast.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
player.vast.sources = player.vast.createSourceObjects(creative.mediaFiles);

if (!player.vast.sources.length) {
player.trigger('adtimeout');
player.trigger('adscanceled');
return;
}

Expand Down Expand Up @@ -118,7 +118,7 @@

if (!player.vastTracker) {
// No pre-roll, start video
player.trigger('adtimeout');
player.trigger('adscanceled');
}
});
},
Expand All @@ -135,13 +135,11 @@
}
player.vastTracker.setProgress(player.currentTime());
},
playFn = function() {
if (player.ads.state === 'ad-playback') {
player.vastTracker.setPaused(false);
}
},
pauseFn = function() {
player.vastTracker.setPaused(true);
player.one('play', function(){
player.vastTracker.setPaused(false);
});
},
errorFn = function() {
// Inform ad server we couldn't play the media file for this ad
Expand All @@ -152,14 +150,12 @@

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.one('vast-preroll-removed', function() {
player.off('canplay', canplayFn);
player.off('timeupdate', timeupdateFn);
player.off('play', playFn);
player.off('pause', pauseFn);
player.off('error', errorFn);
if (!errorOccurred) {
Expand Down Expand Up @@ -281,12 +277,6 @@
return null;
}

// if we don't have a vast url, just bail out
if (!settings.url) {
player.trigger('adtimeout');
return null;
}

// set up vast plugin, then set up events here
player.vast = new Vast(player, settings);

Expand All @@ -313,6 +303,11 @@
});

player.on('readyforpreroll', function() {
// if we don't have a vast url, just bail out
if (!settings.url) {
player.trigger('adscanceled');
return null;
}
// set up and start playing preroll
player.vast.preroll();
});
Expand Down

0 comments on commit 565e0ac

Please sign in to comment.