Merge branch 'beta' into fix/ads-blocked
# Conflicts: # dist/plyr.js # dist/plyr.js.map # src/js/plugins/ads.js # src/js/plyr.js
This commit is contained in:
@ -179,6 +179,7 @@ const defaults = {
|
||||
reset: 'Reset',
|
||||
none: 'None',
|
||||
disabled: 'Disabled',
|
||||
advertisment: 'Ad',
|
||||
},
|
||||
|
||||
// URLs
|
||||
@ -362,9 +363,10 @@ const defaults = {
|
||||
google: null,
|
||||
},
|
||||
|
||||
// Ads
|
||||
// Advertisements plugin
|
||||
// Tag is not required as publisher is determined by vi.ai using the domain
|
||||
ads: {
|
||||
tag: null,
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -8,6 +8,22 @@
|
||||
|
||||
import utils from '../utils';
|
||||
|
||||
// Build the default tag URL
|
||||
const getTagUrl = () => {
|
||||
const params = {
|
||||
AV_PUBLISHERID: '58c25bb0073ef448b1087ad6',
|
||||
AV_CHANNELID: '5a0458dc28a06145e4519d21',
|
||||
AV_URL: '127.0.0.1:3000',
|
||||
cb: 1,
|
||||
AV_WIDTH: 640,
|
||||
AV_HEIGHT: 480,
|
||||
};
|
||||
|
||||
const base = 'https://go.aniview.com/api/adserver6/vast/';
|
||||
|
||||
return `${base}?${utils.buildUrlParams(params)}`;
|
||||
};
|
||||
|
||||
class Ads {
|
||||
/**
|
||||
* Ads constructor.
|
||||
@ -16,6 +32,7 @@ class Ads {
|
||||
*/
|
||||
constructor(player) {
|
||||
this.player = player;
|
||||
this.enabled = player.config.ads.enabled;
|
||||
this.playing = false;
|
||||
this.initialized = false;
|
||||
this.blocked = false;
|
||||
@ -28,14 +45,17 @@ class Ads {
|
||||
|
||||
// Check if the Google IMA3 SDK is loaded or load it ourselves
|
||||
if (!utils.is.object(window.google)) {
|
||||
utils.loadScript(player.config.urls.googleIMA.api, () => {
|
||||
this.ready();
|
||||
}, () => {
|
||||
|
||||
// Script failed to load or is blocked
|
||||
this.blocked = true;
|
||||
this.player.debug.log('Ads error: Google IMA SDK failed to load');
|
||||
});
|
||||
utils.loadScript(
|
||||
player.config.urls.googleIMA.api,
|
||||
() => {
|
||||
this.ready();
|
||||
},
|
||||
() => {
|
||||
// Script failed to load or is blocked
|
||||
this.blocked = true;
|
||||
this.player.debug.log('Ads error: Google IMA SDK failed to load');
|
||||
},
|
||||
);
|
||||
} else {
|
||||
this.ready();
|
||||
}
|
||||
@ -128,7 +148,7 @@ class Ads {
|
||||
|
||||
// Request video ads
|
||||
const request = new google.ima.AdsRequest();
|
||||
request.adTagUrl = this.player.config.ads.tag;
|
||||
request.adTagUrl = getTagUrl();
|
||||
|
||||
// Specify the linear and nonlinear slot sizes. This helps the SDK
|
||||
// to select the correct creative if multiple are returned
|
||||
@ -161,7 +181,8 @@ class Ads {
|
||||
|
||||
const update = () => {
|
||||
const time = utils.formatTime(this.manager.getRemainingTime());
|
||||
this.elements.container.setAttribute('data-badge-text', time);
|
||||
const label = `${this.player.config.i18n.advertisment} - ${time}`;
|
||||
this.elements.container.setAttribute('data-badge-text', label);
|
||||
};
|
||||
|
||||
this.countdownTimer = window.setInterval(update, 100);
|
||||
|
@ -108,8 +108,8 @@ const youtube = {
|
||||
playsinline: 1, // Allow iOS inline playback
|
||||
|
||||
// Tracking for stats
|
||||
origin: window && window.location.hostname,
|
||||
widget_referrer: window && window.location.href,
|
||||
// origin: window ? `${window.location.protocol}//${window.location.host}` : null,
|
||||
widget_referrer: window ? window.location.href : null,
|
||||
|
||||
// Captions are flaky on YouTube
|
||||
cc_load_policy: player.captions.active ? 1 : 0,
|
||||
|
@ -1,6 +1,6 @@
|
||||
// ==========================================================================
|
||||
// Plyr
|
||||
// plyr.js v3.0.0-beta.5
|
||||
// plyr.js v3.0.0-beta.8
|
||||
// https://github.com/sampotts/plyr
|
||||
// License: The MIT License (MIT)
|
||||
// ==========================================================================
|
||||
@ -309,12 +309,14 @@ class Plyr {
|
||||
* Play the media, or play the advertisement (if they are not blocked)
|
||||
*/
|
||||
play() {
|
||||
// TODO: Always return a promise?
|
||||
if (this.ads.enabled && !this.ads.initialized && !this.ads.blocked) {
|
||||
this.ads.play();
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
this.media.play();
|
||||
// Return the promise (for HTML5)
|
||||
return this.media.play();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user