Normalised event names and removed unused

This commit is contained in:
Sam Potts
2018-03-11 12:54:51 +11:00
parent 9a0c1c830d
commit b3365a7373
9 changed files with 196 additions and 172 deletions
+77 -66
View File
@@ -3710,7 +3710,6 @@ var controls = {
// Plyr Event Listeners // Plyr Event Listeners
// ========================================================================== // ==========================================================================
// Sniff out the browser
var browser$1 = utils.getBrowser(); var browser$1 = utils.getBrowser();
var Listeners = function () { var Listeners = function () {
@@ -4411,22 +4410,34 @@ var Ads = function () {
// Setup a promise to resolve when the IMA manager is ready // Setup a promise to resolve when the IMA manager is ready
this.managerPromise = new Promise(function (resolve, reject) { this.managerPromise = new Promise(function (resolve, reject) {
// The ad is pre-loaded and ready // The ad is loaded and ready
_this.on('ADS_MANAGER_LOADED', resolve); _this.on('loaded', resolve);
// Ads failed // Ads failed
_this.on('ERROR', reject); _this.on('error', reject);
}); });
this.load();
}
/**
* Load the IMA SDK
*/
createClass(Ads, [{
key: 'load',
value: function load() {
var _this2 = this;
if (this.enabled) { if (this.enabled) {
// Check if the Google IMA3 SDK is loaded or load it ourselves // Check if the Google IMA3 SDK is loaded or load it ourselves
if (!utils.is.object(window.google)) { if (!utils.is.object(window.google)) {
utils.loadScript(player.config.urls.googleIMA.api).then(function () { utils.loadScript(this.player.config.urls.googleIMA.api).then(function () {
_this.ready(); _this2.ready();
}).catch(function () { }).catch(function () {
// Script failed to load or is blocked // Script failed to load or is blocked
_this.trigger('ERROR'); _this2.trigger('error', new Error('Google IMA SDK failed to load'));
_this.player.debug.error('Google IMA SDK failed to load');
}); });
} else { } else {
this.ready(); this.ready();
@@ -4435,14 +4446,13 @@ var Ads = function () {
} }
/** /**
* Get the ads instance ready. * Get the ads instance ready
*/ */
}, {
createClass(Ads, [{
key: 'ready', key: 'ready',
value: function ready() { value: function ready() {
var _this2 = this; var _this3 = this;
// Start ticking our safety timer. If the whole advertisement // Start ticking our safety timer. If the whole advertisement
// thing doesn't resolve within our set time; we bail // thing doesn't resolve within our set time; we bail
@@ -4450,7 +4460,7 @@ var Ads = function () {
// Clear the safety timer // Clear the safety timer
this.managerPromise.then(function () { this.managerPromise.then(function () {
_this2.clearSafetyTimer('onAdsManagerLoaded()'); _this3.clearSafetyTimer('onAdsManagerLoaded()');
}); });
// Set listeners on the Plyr instance // Set listeners on the Plyr instance
@@ -4502,7 +4512,7 @@ var Ads = function () {
}, { }, {
key: 'requestAds', key: 'requestAds',
value: function requestAds() { value: function requestAds() {
var _this3 = this; var _this4 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -4513,10 +4523,10 @@ var Ads = function () {
// Listen and respond to ads loaded and error events // Listen and respond to ads loaded and error events
this.loader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function (event) { this.loader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function (event) {
return _this3.onAdsManagerLoaded(event); return _this4.onAdsManagerLoaded(event);
}, false); }, false);
this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) { this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) {
return _this3.onAdError(error); return _this4.onAdError(error);
}, false); }, false);
// Request video ads // Request video ads
@@ -4535,7 +4545,7 @@ var Ads = function () {
this.loader.requestAds(request); this.loader.requestAds(request);
this.trigger('ADS_LOADER_LOADED'); this.trigger('loaded');
} catch (e) { } catch (e) {
this.onAdError(e); this.onAdError(e);
} }
@@ -4549,7 +4559,7 @@ var Ads = function () {
}, { }, {
key: 'pollCountdown', key: 'pollCountdown',
value: function pollCountdown() { value: function pollCountdown() {
var _this4 = this; var _this5 = this;
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -4560,9 +4570,9 @@ var Ads = function () {
} }
var update = function update() { var update = function update() {
var time = utils.formatTime(Math.max(_this4.manager.getRemainingTime(), 0)); var time = utils.formatTime(Math.max(_this5.manager.getRemainingTime(), 0));
var label = _this4.player.config.i18n.advertisement + ' - ' + time; var label = _this5.player.config.i18n.advertisement + ' - ' + time;
_this4.elements.container.setAttribute('data-badge-text', label); _this5.elements.container.setAttribute('data-badge-text', label);
}; };
this.countdownTimer = window.setInterval(update, 100); this.countdownTimer = window.setInterval(update, 100);
@@ -4576,7 +4586,7 @@ var Ads = function () {
}, { }, {
key: 'onAdsManagerLoaded', key: 'onAdsManagerLoaded',
value: function onAdsManagerLoaded(adsManagerLoadedEvent) { value: function onAdsManagerLoaded(adsManagerLoadedEvent) {
var _this5 = this; var _this6 = this;
// Get the ads manager // Get the ads manager
var settings = new google.ima.AdsRenderingSettings(); var settings = new google.ima.AdsRenderingSettings();
@@ -4594,13 +4604,13 @@ var Ads = function () {
// Add advertisement cue's within the time line if available // Add advertisement cue's within the time line if available
this.cuePoints.forEach(function (cuePoint) { this.cuePoints.forEach(function (cuePoint) {
if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < _this5.player.duration) { if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < _this6.player.duration) {
var seekElement = _this5.player.elements.progress; var seekElement = _this6.player.elements.progress;
if (seekElement) { if (seekElement) {
var cuePercentage = 100 / _this5.player.duration * cuePoint; var cuePercentage = 100 / _this6.player.duration * cuePoint;
var cue = utils.createElement('span', { var cue = utils.createElement('span', {
class: _this5.player.config.classNames.cues class: _this6.player.config.classNames.cues
}); });
cue.style.left = cuePercentage.toString() + '%'; cue.style.left = cuePercentage.toString() + '%';
@@ -4619,18 +4629,18 @@ var Ads = function () {
// Add listeners to the required events // Add listeners to the required events
// Advertisement error events // Advertisement error events
this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) { this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) {
return _this5.onAdError(error); return _this6.onAdError(error);
}); });
// Advertisement regular events // Advertisement regular events
Object.keys(google.ima.AdEvent.Type).forEach(function (type) { Object.keys(google.ima.AdEvent.Type).forEach(function (type) {
_this5.manager.addEventListener(google.ima.AdEvent.Type[type], function (event) { _this6.manager.addEventListener(google.ima.AdEvent.Type[type], function (event) {
return _this5.onAdEvent(event); return _this6.onAdEvent(event);
}); });
}); });
// Resolve our adsManager // Resolve our adsManager
this.trigger('ADS_MANAGER_LOADED'); this.trigger('loaded');
} }
/** /**
@@ -4643,7 +4653,7 @@ var Ads = function () {
}, { }, {
key: 'onAdEvent', key: 'onAdEvent',
value: function onAdEvent(event) { value: function onAdEvent(event) {
var _this6 = this; var _this7 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -4654,14 +4664,14 @@ var Ads = function () {
// Proxy event // Proxy event
var dispatchEvent = function dispatchEvent(type) { var dispatchEvent = function dispatchEvent(type) {
utils.dispatchEvent.call(_this6.player, _this6.player.media, 'ads' + type); utils.dispatchEvent.call(_this7.player, _this7.player.media, 'ads' + type);
}; };
switch (event.type) { switch (event.type) {
case google.ima.AdEvent.Type.LOADED: case google.ima.AdEvent.Type.LOADED:
// This is the first event sent for an ad - it is possible to determine whether the // This is the first event sent for an ad - it is possible to determine whether the
// ad is a video ad or an overlay // ad is a video ad or an overlay
this.trigger('LOADED'); this.trigger('loaded');
// Bubble event // Bubble event
dispatchEvent('loaded'); dispatchEvent('loaded');
@@ -4682,7 +4692,6 @@ var Ads = function () {
case google.ima.AdEvent.Type.ALL_ADS_COMPLETED: case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:
// All ads for the current videos are done. We can now request new advertisements // All ads for the current videos are done. We can now request new advertisements
// in case the video is re-played // in case the video is re-played
this.trigger('ALL_ADS_COMPLETED');
// Fire event // Fire event
dispatchEvent('allcomplete'); dispatchEvent('allcomplete');
@@ -4717,7 +4726,6 @@ var Ads = function () {
// This event indicates the ad has started - the video player can adjust the UI, // This event indicates the ad has started - the video player can adjust the UI,
// for example display a pause button and remaining time. Fired when content should // 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 // be paused. This usually happens right before an ad is about to cover the content
this.trigger('CONTENT_PAUSE_REQUESTED');
dispatchEvent('contentpause'); dispatchEvent('contentpause');
@@ -4730,7 +4738,6 @@ var Ads = function () {
// appropriate UI actions, such as removing the timer for remaining time detection. // appropriate UI actions, such as removing the timer for remaining time detection.
// Fired when content should be resumed. This usually happens when an ad finishes // Fired when content should be resumed. This usually happens when an ad finishes
// or collapses // or collapses
this.trigger('CONTENT_RESUME_REQUESTED');
dispatchEvent('contentresume'); dispatchEvent('contentresume');
@@ -4774,7 +4781,7 @@ var Ads = function () {
key: 'onAdError', key: 'onAdError',
value: function onAdError(event) { value: function onAdError(event) {
this.cancel(); this.cancel();
this.player.debug.log('Ads error', event); this.player.debug.warn('Ads error', event);
} }
/** /**
@@ -4786,7 +4793,7 @@ var Ads = function () {
}, { }, {
key: 'listeners', key: 'listeners',
value: function listeners() { value: function listeners() {
var _this7 = this; var _this8 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -4794,21 +4801,21 @@ var Ads = function () {
// Add listeners to the required events // Add listeners to the required events
this.player.on('ended', function () { this.player.on('ended', function () {
_this7.loader.contentComplete(); _this8.loader.contentComplete();
}); });
this.player.on('seeking', function () { this.player.on('seeking', function () {
time = _this7.player.currentTime; time = _this8.player.currentTime;
return time; return time;
}); });
this.player.on('seeked', function () { this.player.on('seeked', function () {
var seekedTime = _this7.player.currentTime; var seekedTime = _this8.player.currentTime;
_this7.cuePoints.forEach(function (cuePoint, index) { _this8.cuePoints.forEach(function (cuePoint, index) {
if (time < cuePoint && cuePoint < seekedTime) { if (time < cuePoint && cuePoint < seekedTime) {
_this7.manager.discardAdBreak(); _this8.manager.discardAdBreak();
_this7.cuePoints.splice(index, 1); _this8.cuePoints.splice(index, 1);
} }
}); });
}); });
@@ -4816,7 +4823,7 @@ var Ads = function () {
// Listen to the resizing of the window. And resize ad accordingly // Listen to the resizing of the window. And resize ad accordingly
// TODO: eventually implement ResizeObserver // TODO: eventually implement ResizeObserver
window.addEventListener('resize', function () { window.addEventListener('resize', function () {
_this7.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL); _this8.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL);
}); });
} }
@@ -4827,7 +4834,7 @@ var Ads = function () {
}, { }, {
key: 'play', key: 'play',
value: function play() { value: function play() {
var _this8 = this; var _this9 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -4839,29 +4846,29 @@ var Ads = function () {
// Play the requested advertisement whenever the adsManager is ready // Play the requested advertisement whenever the adsManager is ready
this.managerPromise.then(function () { this.managerPromise.then(function () {
// Initialize the container. Must be done via a user action on mobile devices // Initialize the container. Must be done via a user action on mobile devices
_this8.elements.displayContainer.initialize(); _this9.elements.displayContainer.initialize();
try { try {
if (!_this8.initialized) { if (!_this9.initialized) {
// Initialize the ads manager. Ad rules playlist will start at this time // Initialize the ads manager. Ad rules playlist will start at this time
_this8.manager.init(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL); _this9.manager.init(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL);
// Call play to start showing the ad. Single video and overlay ads will // Call play to start showing the ad. Single video and overlay ads will
// start at this time; the call will be ignored for ad rules // start at this time; the call will be ignored for ad rules
_this8.manager.start(); _this9.manager.start();
} }
_this8.initialized = true; _this9.initialized = true;
} catch (adError) { } catch (adError) {
// An error may be thrown if there was a problem with the // An error may be thrown if there was a problem with the
// VAST response // VAST response
_this8.onAdError(adError); _this9.onAdError(adError);
} }
}); });
} }
/** /**
* Resume our video. * Resume our video
*/ */
}, { }, {
@@ -4912,7 +4919,7 @@ var Ads = function () {
} }
// Tell our instance that we're done for now // Tell our instance that we're done for now
this.trigger('ERROR'); this.trigger('error');
// Re-create our adsManager // Re-create our adsManager
this.loadAds(); this.loadAds();
@@ -4925,23 +4932,23 @@ var Ads = function () {
}, { }, {
key: 'loadAds', key: 'loadAds',
value: function loadAds() { value: function loadAds() {
var _this9 = this; var _this10 = this;
// Tell our adsManager to go bye bye // Tell our adsManager to go bye bye
this.managerPromise.then(function () { this.managerPromise.then(function () {
// Destroy our adsManager // Destroy our adsManager
if (_this9.manager) { if (_this10.manager) {
_this9.manager.destroy(); _this10.manager.destroy();
} }
// Re-set our adsManager promises // Re-set our adsManager promises
_this9.managerPromise = new Promise(function (resolve) { _this10.managerPromise = new Promise(function (resolve) {
_this9.on('ADS_MANAGER_LOADED', resolve); _this10.on('loaded', resolve);
_this9.player.debug.log(_this9.manager); _this10.player.debug.log(_this10.manager);
}); });
// Now request some new advertisements // Now request some new advertisements
_this9.requestAds(); _this10.requestAds();
}); });
} }
@@ -4953,14 +4960,18 @@ var Ads = function () {
}, { }, {
key: 'trigger', key: 'trigger',
value: function trigger(event) { value: function trigger(event) {
var _this10 = this; var _this11 = this;
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var handlers = this.events[event]; var handlers = this.events[event];
if (utils.is.array(handlers)) { if (utils.is.array(handlers)) {
handlers.forEach(function (handler) { handlers.forEach(function (handler) {
if (utils.is.function(handler)) { if (utils.is.function(handler)) {
handler.call(_this10); handler.apply(_this11, args);
} }
}); });
} }
@@ -4997,13 +5008,13 @@ var Ads = function () {
}, { }, {
key: 'startSafetyTimer', key: 'startSafetyTimer',
value: function startSafetyTimer(time, from) { value: function startSafetyTimer(time, from) {
var _this11 = this; var _this12 = this;
this.player.debug.log('Safety timer invoked from: ' + from); this.player.debug.log('Safety timer invoked from: ' + from);
this.safetyTimer = setTimeout(function () { this.safetyTimer = setTimeout(function () {
_this11.cancel(); _this12.cancel();
_this11.clearSafetyTimer('startSafetyTimer()'); _this12.clearSafetyTimer('startSafetyTimer()');
}, time); }, time);
} }
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+77 -66
View File
@@ -9618,7 +9618,6 @@ var controls = {
// Plyr Event Listeners // Plyr Event Listeners
// ========================================================================== // ==========================================================================
// Sniff out the browser
var browser$1 = utils.getBrowser(); var browser$1 = utils.getBrowser();
var Listeners = function () { var Listeners = function () {
@@ -10319,22 +10318,34 @@ var Ads = function () {
// Setup a promise to resolve when the IMA manager is ready // Setup a promise to resolve when the IMA manager is ready
this.managerPromise = new Promise(function (resolve, reject) { this.managerPromise = new Promise(function (resolve, reject) {
// The ad is pre-loaded and ready // The ad is loaded and ready
_this.on('ADS_MANAGER_LOADED', resolve); _this.on('loaded', resolve);
// Ads failed // Ads failed
_this.on('ERROR', reject); _this.on('error', reject);
}); });
this.load();
}
/**
* Load the IMA SDK
*/
createClass(Ads, [{
key: 'load',
value: function load() {
var _this2 = this;
if (this.enabled) { if (this.enabled) {
// Check if the Google IMA3 SDK is loaded or load it ourselves // Check if the Google IMA3 SDK is loaded or load it ourselves
if (!utils.is.object(window.google)) { if (!utils.is.object(window.google)) {
utils.loadScript(player.config.urls.googleIMA.api).then(function () { utils.loadScript(this.player.config.urls.googleIMA.api).then(function () {
_this.ready(); _this2.ready();
}).catch(function () { }).catch(function () {
// Script failed to load or is blocked // Script failed to load or is blocked
_this.trigger('ERROR'); _this2.trigger('error', new Error('Google IMA SDK failed to load'));
_this.player.debug.error('Google IMA SDK failed to load');
}); });
} else { } else {
this.ready(); this.ready();
@@ -10343,14 +10354,13 @@ var Ads = function () {
} }
/** /**
* Get the ads instance ready. * Get the ads instance ready
*/ */
}, {
createClass(Ads, [{
key: 'ready', key: 'ready',
value: function ready() { value: function ready() {
var _this2 = this; var _this3 = this;
// Start ticking our safety timer. If the whole advertisement // Start ticking our safety timer. If the whole advertisement
// thing doesn't resolve within our set time; we bail // thing doesn't resolve within our set time; we bail
@@ -10358,7 +10368,7 @@ var Ads = function () {
// Clear the safety timer // Clear the safety timer
this.managerPromise.then(function () { this.managerPromise.then(function () {
_this2.clearSafetyTimer('onAdsManagerLoaded()'); _this3.clearSafetyTimer('onAdsManagerLoaded()');
}); });
// Set listeners on the Plyr instance // Set listeners on the Plyr instance
@@ -10410,7 +10420,7 @@ var Ads = function () {
}, { }, {
key: 'requestAds', key: 'requestAds',
value: function requestAds() { value: function requestAds() {
var _this3 = this; var _this4 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -10421,10 +10431,10 @@ var Ads = function () {
// Listen and respond to ads loaded and error events // Listen and respond to ads loaded and error events
this.loader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function (event) { this.loader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function (event) {
return _this3.onAdsManagerLoaded(event); return _this4.onAdsManagerLoaded(event);
}, false); }, false);
this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) { this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) {
return _this3.onAdError(error); return _this4.onAdError(error);
}, false); }, false);
// Request video ads // Request video ads
@@ -10443,7 +10453,7 @@ var Ads = function () {
this.loader.requestAds(request); this.loader.requestAds(request);
this.trigger('ADS_LOADER_LOADED'); this.trigger('loaded');
} catch (e) { } catch (e) {
this.onAdError(e); this.onAdError(e);
} }
@@ -10457,7 +10467,7 @@ var Ads = function () {
}, { }, {
key: 'pollCountdown', key: 'pollCountdown',
value: function pollCountdown() { value: function pollCountdown() {
var _this4 = this; var _this5 = this;
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -10468,9 +10478,9 @@ var Ads = function () {
} }
var update = function update() { var update = function update() {
var time = utils.formatTime(Math.max(_this4.manager.getRemainingTime(), 0)); var time = utils.formatTime(Math.max(_this5.manager.getRemainingTime(), 0));
var label = _this4.player.config.i18n.advertisement + ' - ' + time; var label = _this5.player.config.i18n.advertisement + ' - ' + time;
_this4.elements.container.setAttribute('data-badge-text', label); _this5.elements.container.setAttribute('data-badge-text', label);
}; };
this.countdownTimer = window.setInterval(update, 100); this.countdownTimer = window.setInterval(update, 100);
@@ -10484,7 +10494,7 @@ var Ads = function () {
}, { }, {
key: 'onAdsManagerLoaded', key: 'onAdsManagerLoaded',
value: function onAdsManagerLoaded(adsManagerLoadedEvent) { value: function onAdsManagerLoaded(adsManagerLoadedEvent) {
var _this5 = this; var _this6 = this;
// Get the ads manager // Get the ads manager
var settings = new google.ima.AdsRenderingSettings(); var settings = new google.ima.AdsRenderingSettings();
@@ -10502,13 +10512,13 @@ var Ads = function () {
// Add advertisement cue's within the time line if available // Add advertisement cue's within the time line if available
this.cuePoints.forEach(function (cuePoint) { this.cuePoints.forEach(function (cuePoint) {
if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < _this5.player.duration) { if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < _this6.player.duration) {
var seekElement = _this5.player.elements.progress; var seekElement = _this6.player.elements.progress;
if (seekElement) { if (seekElement) {
var cuePercentage = 100 / _this5.player.duration * cuePoint; var cuePercentage = 100 / _this6.player.duration * cuePoint;
var cue = utils.createElement('span', { var cue = utils.createElement('span', {
class: _this5.player.config.classNames.cues class: _this6.player.config.classNames.cues
}); });
cue.style.left = cuePercentage.toString() + '%'; cue.style.left = cuePercentage.toString() + '%';
@@ -10527,18 +10537,18 @@ var Ads = function () {
// Add listeners to the required events // Add listeners to the required events
// Advertisement error events // Advertisement error events
this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) { this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function (error) {
return _this5.onAdError(error); return _this6.onAdError(error);
}); });
// Advertisement regular events // Advertisement regular events
Object.keys(google.ima.AdEvent.Type).forEach(function (type) { Object.keys(google.ima.AdEvent.Type).forEach(function (type) {
_this5.manager.addEventListener(google.ima.AdEvent.Type[type], function (event) { _this6.manager.addEventListener(google.ima.AdEvent.Type[type], function (event) {
return _this5.onAdEvent(event); return _this6.onAdEvent(event);
}); });
}); });
// Resolve our adsManager // Resolve our adsManager
this.trigger('ADS_MANAGER_LOADED'); this.trigger('loaded');
} }
/** /**
@@ -10551,7 +10561,7 @@ var Ads = function () {
}, { }, {
key: 'onAdEvent', key: 'onAdEvent',
value: function onAdEvent(event) { value: function onAdEvent(event) {
var _this6 = this; var _this7 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -10562,14 +10572,14 @@ var Ads = function () {
// Proxy event // Proxy event
var dispatchEvent = function dispatchEvent(type) { var dispatchEvent = function dispatchEvent(type) {
utils.dispatchEvent.call(_this6.player, _this6.player.media, 'ads' + type); utils.dispatchEvent.call(_this7.player, _this7.player.media, 'ads' + type);
}; };
switch (event.type) { switch (event.type) {
case google.ima.AdEvent.Type.LOADED: case google.ima.AdEvent.Type.LOADED:
// This is the first event sent for an ad - it is possible to determine whether the // This is the first event sent for an ad - it is possible to determine whether the
// ad is a video ad or an overlay // ad is a video ad or an overlay
this.trigger('LOADED'); this.trigger('loaded');
// Bubble event // Bubble event
dispatchEvent('loaded'); dispatchEvent('loaded');
@@ -10590,7 +10600,6 @@ var Ads = function () {
case google.ima.AdEvent.Type.ALL_ADS_COMPLETED: case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:
// All ads for the current videos are done. We can now request new advertisements // All ads for the current videos are done. We can now request new advertisements
// in case the video is re-played // in case the video is re-played
this.trigger('ALL_ADS_COMPLETED');
// Fire event // Fire event
dispatchEvent('allcomplete'); dispatchEvent('allcomplete');
@@ -10625,7 +10634,6 @@ var Ads = function () {
// This event indicates the ad has started - the video player can adjust the UI, // This event indicates the ad has started - the video player can adjust the UI,
// for example display a pause button and remaining time. Fired when content should // 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 // be paused. This usually happens right before an ad is about to cover the content
this.trigger('CONTENT_PAUSE_REQUESTED');
dispatchEvent('contentpause'); dispatchEvent('contentpause');
@@ -10638,7 +10646,6 @@ var Ads = function () {
// appropriate UI actions, such as removing the timer for remaining time detection. // appropriate UI actions, such as removing the timer for remaining time detection.
// Fired when content should be resumed. This usually happens when an ad finishes // Fired when content should be resumed. This usually happens when an ad finishes
// or collapses // or collapses
this.trigger('CONTENT_RESUME_REQUESTED');
dispatchEvent('contentresume'); dispatchEvent('contentresume');
@@ -10682,7 +10689,7 @@ var Ads = function () {
key: 'onAdError', key: 'onAdError',
value: function onAdError(event) { value: function onAdError(event) {
this.cancel(); this.cancel();
this.player.debug.log('Ads error', event); this.player.debug.warn('Ads error', event);
} }
/** /**
@@ -10694,7 +10701,7 @@ var Ads = function () {
}, { }, {
key: 'listeners', key: 'listeners',
value: function listeners() { value: function listeners() {
var _this7 = this; var _this8 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -10702,21 +10709,21 @@ var Ads = function () {
// Add listeners to the required events // Add listeners to the required events
this.player.on('ended', function () { this.player.on('ended', function () {
_this7.loader.contentComplete(); _this8.loader.contentComplete();
}); });
this.player.on('seeking', function () { this.player.on('seeking', function () {
time = _this7.player.currentTime; time = _this8.player.currentTime;
return time; return time;
}); });
this.player.on('seeked', function () { this.player.on('seeked', function () {
var seekedTime = _this7.player.currentTime; var seekedTime = _this8.player.currentTime;
_this7.cuePoints.forEach(function (cuePoint, index) { _this8.cuePoints.forEach(function (cuePoint, index) {
if (time < cuePoint && cuePoint < seekedTime) { if (time < cuePoint && cuePoint < seekedTime) {
_this7.manager.discardAdBreak(); _this8.manager.discardAdBreak();
_this7.cuePoints.splice(index, 1); _this8.cuePoints.splice(index, 1);
} }
}); });
}); });
@@ -10724,7 +10731,7 @@ var Ads = function () {
// Listen to the resizing of the window. And resize ad accordingly // Listen to the resizing of the window. And resize ad accordingly
// TODO: eventually implement ResizeObserver // TODO: eventually implement ResizeObserver
window.addEventListener('resize', function () { window.addEventListener('resize', function () {
_this7.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL); _this8.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL);
}); });
} }
@@ -10735,7 +10742,7 @@ var Ads = function () {
}, { }, {
key: 'play', key: 'play',
value: function play() { value: function play() {
var _this8 = this; var _this9 = this;
var container = this.player.elements.container; var container = this.player.elements.container;
@@ -10747,29 +10754,29 @@ var Ads = function () {
// Play the requested advertisement whenever the adsManager is ready // Play the requested advertisement whenever the adsManager is ready
this.managerPromise.then(function () { this.managerPromise.then(function () {
// Initialize the container. Must be done via a user action on mobile devices // Initialize the container. Must be done via a user action on mobile devices
_this8.elements.displayContainer.initialize(); _this9.elements.displayContainer.initialize();
try { try {
if (!_this8.initialized) { if (!_this9.initialized) {
// Initialize the ads manager. Ad rules playlist will start at this time // Initialize the ads manager. Ad rules playlist will start at this time
_this8.manager.init(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL); _this9.manager.init(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL);
// Call play to start showing the ad. Single video and overlay ads will // Call play to start showing the ad. Single video and overlay ads will
// start at this time; the call will be ignored for ad rules // start at this time; the call will be ignored for ad rules
_this8.manager.start(); _this9.manager.start();
} }
_this8.initialized = true; _this9.initialized = true;
} catch (adError) { } catch (adError) {
// An error may be thrown if there was a problem with the // An error may be thrown if there was a problem with the
// VAST response // VAST response
_this8.onAdError(adError); _this9.onAdError(adError);
} }
}); });
} }
/** /**
* Resume our video. * Resume our video
*/ */
}, { }, {
@@ -10820,7 +10827,7 @@ var Ads = function () {
} }
// Tell our instance that we're done for now // Tell our instance that we're done for now
this.trigger('ERROR'); this.trigger('error');
// Re-create our adsManager // Re-create our adsManager
this.loadAds(); this.loadAds();
@@ -10833,23 +10840,23 @@ var Ads = function () {
}, { }, {
key: 'loadAds', key: 'loadAds',
value: function loadAds() { value: function loadAds() {
var _this9 = this; var _this10 = this;
// Tell our adsManager to go bye bye // Tell our adsManager to go bye bye
this.managerPromise.then(function () { this.managerPromise.then(function () {
// Destroy our adsManager // Destroy our adsManager
if (_this9.manager) { if (_this10.manager) {
_this9.manager.destroy(); _this10.manager.destroy();
} }
// Re-set our adsManager promises // Re-set our adsManager promises
_this9.managerPromise = new Promise(function (resolve) { _this10.managerPromise = new Promise(function (resolve) {
_this9.on('ADS_MANAGER_LOADED', resolve); _this10.on('loaded', resolve);
_this9.player.debug.log(_this9.manager); _this10.player.debug.log(_this10.manager);
}); });
// Now request some new advertisements // Now request some new advertisements
_this9.requestAds(); _this10.requestAds();
}); });
} }
@@ -10861,14 +10868,18 @@ var Ads = function () {
}, { }, {
key: 'trigger', key: 'trigger',
value: function trigger(event) { value: function trigger(event) {
var _this10 = this; var _this11 = this;
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var handlers = this.events[event]; var handlers = this.events[event];
if (utils.is.array(handlers)) { if (utils.is.array(handlers)) {
handlers.forEach(function (handler) { handlers.forEach(function (handler) {
if (utils.is.function(handler)) { if (utils.is.function(handler)) {
handler.call(_this10); handler.apply(_this11, args);
} }
}); });
} }
@@ -10905,13 +10916,13 @@ var Ads = function () {
}, { }, {
key: 'startSafetyTimer', key: 'startSafetyTimer',
value: function startSafetyTimer(time, from) { value: function startSafetyTimer(time, from) {
var _this11 = this; var _this12 = this;
this.player.debug.log('Safety timer invoked from: ' + from); this.player.debug.log('Safety timer invoked from: ' + from);
this.safetyTimer = setTimeout(function () { this.safetyTimer = setTimeout(function () {
_this11.cancel(); _this12.cancel();
_this11.clearSafetyTimer('startSafetyTimer()'); _this12.clearSafetyTimer('startSafetyTimer()');
}, time); }, time);
} }
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+20 -18
View File
@@ -33,26 +33,31 @@ class Ads {
// Setup a promise to resolve when the IMA manager is ready // Setup a promise to resolve when the IMA manager is ready
this.managerPromise = new Promise((resolve, reject) => { this.managerPromise = new Promise((resolve, reject) => {
// The ad is pre-loaded and ready // The ad is loaded and ready
this.on('ADS_MANAGER_LOADED', resolve); this.on('loaded', resolve);
// Ads failed // Ads failed
this.on('ERROR', reject); this.on('error', reject);
}); });
this.load();
}
/**
* Load the IMA SDK
*/
load() {
if (this.enabled) { if (this.enabled) {
// Check if the Google IMA3 SDK is loaded or load it ourselves // Check if the Google IMA3 SDK is loaded or load it ourselves
if (!utils.is.object(window.google)) { if (!utils.is.object(window.google)) {
utils utils
.loadScript(player.config.urls.googleIMA.api) .loadScript(this.player.config.urls.googleIMA.api)
.then(() => { .then(() => {
this.ready(); this.ready();
}) })
.catch(() => { .catch(() => {
// Script failed to load or is blocked // Script failed to load or is blocked
const message = 'Google IMA SDK failed to load'; this.trigger('error', new Error('Google IMA SDK failed to load'));
this.trigger('ERROR', new Error(message));
this.player.debug.error(message);
}); });
} else { } else {
this.ready(); this.ready();
@@ -61,7 +66,7 @@ class Ads {
} }
/** /**
* Get the ads instance ready. * Get the ads instance ready
*/ */
ready() { ready() {
// Start ticking our safety timer. If the whole advertisement // Start ticking our safety timer. If the whole advertisement
@@ -156,7 +161,7 @@ class Ads {
this.loader.requestAds(request); this.loader.requestAds(request);
this.trigger('ADS_LOADER_LOADED'); this.trigger('loaded');
} catch (e) { } catch (e) {
this.onAdError(e); this.onAdError(e);
} }
@@ -235,7 +240,7 @@ class Ads {
}); });
// Resolve our adsManager // Resolve our adsManager
this.trigger('ADS_MANAGER_LOADED'); this.trigger('loaded');
} }
/** /**
@@ -260,7 +265,7 @@ class Ads {
case google.ima.AdEvent.Type.LOADED: case google.ima.AdEvent.Type.LOADED:
// This is the first event sent for an ad - it is possible to determine whether the // This is the first event sent for an ad - it is possible to determine whether the
// ad is a video ad or an overlay // ad is a video ad or an overlay
this.trigger('LOADED'); this.trigger('loaded');
// Bubble event // Bubble event
dispatchEvent('loaded'); dispatchEvent('loaded');
@@ -281,7 +286,6 @@ class Ads {
case google.ima.AdEvent.Type.ALL_ADS_COMPLETED: case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:
// All ads for the current videos are done. We can now request new advertisements // All ads for the current videos are done. We can now request new advertisements
// in case the video is re-played // in case the video is re-played
this.trigger('ALL_ADS_COMPLETED');
// Fire event // Fire event
dispatchEvent('allcomplete'); dispatchEvent('allcomplete');
@@ -316,7 +320,6 @@ class Ads {
// This event indicates the ad has started - the video player can adjust the UI, // This event indicates the ad has started - the video player can adjust the UI,
// for example display a pause button and remaining time. Fired when content should // 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 // be paused. This usually happens right before an ad is about to cover the content
this.trigger('CONTENT_PAUSE_REQUESTED');
dispatchEvent('contentpause'); dispatchEvent('contentpause');
@@ -329,7 +332,6 @@ class Ads {
// appropriate UI actions, such as removing the timer for remaining time detection. // appropriate UI actions, such as removing the timer for remaining time detection.
// Fired when content should be resumed. This usually happens when an ad finishes // Fired when content should be resumed. This usually happens when an ad finishes
// or collapses // or collapses
this.trigger('CONTENT_RESUME_REQUESTED');
dispatchEvent('contentresume'); dispatchEvent('contentresume');
@@ -370,7 +372,7 @@ class Ads {
*/ */
onAdError(event) { onAdError(event) {
this.cancel(); this.cancel();
this.player.debug.log('Ads error', event); this.player.debug.warn('Ads error', event);
} }
/** /**
@@ -445,7 +447,7 @@ class Ads {
} }
/** /**
* Resume our video. * Resume our video
*/ */
resumeContent() { resumeContent() {
// Hide the advertisement container // Hide the advertisement container
@@ -487,7 +489,7 @@ class Ads {
} }
// Tell our instance that we're done for now // Tell our instance that we're done for now
this.trigger('ERROR'); this.trigger('error');
// Re-create our adsManager // Re-create our adsManager
this.loadAds(); this.loadAds();
@@ -506,7 +508,7 @@ class Ads {
// Re-set our adsManager promises // Re-set our adsManager promises
this.managerPromise = new Promise(resolve => { this.managerPromise = new Promise(resolve => {
this.on('ADS_MANAGER_LOADED', resolve); this.on('loaded', resolve);
this.player.debug.log(this.manager); this.player.debug.log(this.manager);
}); });