Update ads

This commit is contained in:
Sam Potts
2018-03-13 21:42:01 +11:00
parent 9981c349be
commit 1b13ddaa54
11 changed files with 28 additions and 62 deletions

View File

@ -376,7 +376,7 @@ const defaults = {
// Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
ads: {
enabled: false,
publisherId: null,
publisherId: '918848828995742',
},
};

View File

@ -256,7 +256,8 @@ class Ads {
// Proxy event
const dispatchEvent = type => {
utils.dispatchEvent.call(this.player, this.player.media, `ads${type}`);
const event = `ads${type.replace(/_/g, '').toLowerCase()}`;
utils.dispatchEvent.call(this.player, this.player.media, event);
};
switch (event.type) {
@ -266,7 +267,7 @@ class Ads {
this.trigger('loaded');
// Bubble event
dispatchEvent('loaded');
dispatchEvent(event.type);
// Start countdown
this.pollCountdown(true);
@ -286,7 +287,7 @@ class Ads {
// in case the video is re-played
// Fire event
dispatchEvent('allcomplete');
dispatchEvent(event.type);
// TODO: Example for what happens when a next video in a playlist would be loaded.
// So here we load a new video when all ads are done.
@ -319,7 +320,7 @@ class Ads {
// for example display a pause button and remaining time. Fired when content should
// be paused. This usually happens right before an ad is about to cover the content
dispatchEvent('contentpause');
dispatchEvent(event.type);
this.pauseContent();
@ -331,7 +332,7 @@ class Ads {
// Fired when content should be resumed. This usually happens when an ad finishes
// or collapses
dispatchEvent('contentresume');
dispatchEvent(event.type);
this.pollCountdown();
@ -340,23 +341,11 @@ class Ads {
break;
case google.ima.AdEvent.Type.STARTED:
dispatchEvent('started');
break;
case google.ima.AdEvent.Type.MIDPOINT:
dispatchEvent('midpoint');
break;
case google.ima.AdEvent.Type.COMPLETE:
dispatchEvent('complete');
break;
case google.ima.AdEvent.Type.IMPRESSION:
dispatchEvent('impression');
break;
case google.ima.AdEvent.Type.CLICK:
dispatchEvent('click');
dispatchEvent(event.type);
break;
default: