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

Commit

Permalink
Pulling the trackers out into a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sinchok committed Nov 6, 2014
1 parent a61fc1b commit bf99bf6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 225 deletions.
2 changes: 0 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ var specs = "spec/*Spec.js",

var _ = require('lodash');

var desireds = require('./spec/desireds.js');

var gruntConfig = {
env: {
// dynamically filled
Expand Down
1 change: 0 additions & 1 deletion spec/VastPluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,5 @@ describe('videojs.vast plugin', function() {
});

});

});
});
82 changes: 0 additions & 82 deletions spec/desireds.js

This file was deleted.

100 changes: 0 additions & 100 deletions spec/sauce-wd.js

This file was deleted.

87 changes: 47 additions & 40 deletions videojs.vast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -223,6 +228,8 @@
}
};

player.vast.setupEvents();

player.one('ended', player.vast.tearDown);

player.trigger('vast-preroll-ready');
Expand Down

0 comments on commit bf99bf6

Please sign in to comment.