diff --git a/src/client-side/controller.js b/src/client-side/controller.js index 9004c74d..67d73727 100644 --- a/src/client-side/controller.js +++ b/src/client-side/controller.js @@ -70,8 +70,8 @@ const Controller = function(player, options) { timeout: this.settings.timeout, prerollTimeout: this.settings.prerollTimeout, }; - const adsPluginSettings = this.extend( - {}, contribAdsDefaults, options.contribAdsSettings || {}); + const adsPluginSettings = + Object.assign({}, contribAdsDefaults, options.contribAdsSettings || {}); this.playerWrapper = new PlayerWrapper(player, adsPluginSettings, this); this.adUi = new AdUi(this); @@ -97,7 +97,7 @@ Controller.IMA_DEFAULTS = { * @param {Object} options Options to be used in initialization. */ Controller.prototype.initWithSettings = function(options) { - this.settings = this.extend({}, Controller.IMA_DEFAULTS, options || {}); + this.settings = Object.assign({}, Controller.IMA_DEFAULTS, options || {}); this.warnAboutDeprecatedSettings(); @@ -779,29 +779,4 @@ Controller.prototype.triggerPlayerEvent = function(name, data) { this.playerWrapper.triggerPlayerEvent(name, data); }; - -/** - * Extends an object to include the contents of objects at parameters 2 onward. - * - * @param {Object} obj The object onto which the subsequent objects' parameters - * will be extended. This object will be modified. - * @param {...Object} var_args The objects whose properties are to be extended - * onto obj. - * @return {Object} The extended object. - */ -Controller.prototype.extend = function(obj, ...args) { - let arg; - let index; - let key; - for (index = 0; index < args.length; index++) { - arg = args[index]; - for (key in arg) { - if (arg.hasOwnProperty(key)) { - obj[key] = arg[key]; - } - } - } - return obj; -}; - export default Controller; diff --git a/src/client-side/sdk-impl.js b/src/client-side/sdk-impl.js index b2e61f0e..a66fbca6 100644 --- a/src/client-side/sdk-impl.js +++ b/src/client-side/sdk-impl.js @@ -663,7 +663,6 @@ SdkImpl.prototype.onPlayerResize = function(width, height) { if (this.adsManager) { this.adsManagerDimensions.width = width; this.adsManagerDimensions.height = height; - /* global google */ /* eslint no-undef: 'error' */ this.adsManager.resize(width, height, google.ima.ViewMode.NORMAL); } diff --git a/src/dai/dai-controller.js b/src/dai/dai-controller.js index 17ffcb38..fa1e8628 100644 --- a/src/dai/dai-controller.js +++ b/src/dai/dai-controller.js @@ -257,7 +257,8 @@ DaiController.prototype.addEventListener = function(event, callback) { /** * Returns the instance of the StreamManager. - * @return {google.ima.StreamManager!} The StreamManager being used by the plugin. + * @return {google.ima.StreamManager!} The StreamManager being used by the + * plugin. */ DaiController.prototype.getStreamManager = function() { return this.sdkImpl.getStreamManager(); @@ -272,7 +273,8 @@ DaiController.prototype.getPlayerId = function() { }; /** - * @return {boolean} true if we expect that the stream will autoplay. false otherwise. + * @return {boolean} true if we expect that the stream will autoplay. false + * otherwise. */ DaiController.prototype.streamWillAutoplay = function() { if (this.settings.streamWillAutoplay !== undefined) { diff --git a/src/dai/sdk-impl.js b/src/dai/sdk-impl.js index f492329d..db44599a 100644 --- a/src/dai/sdk-impl.js +++ b/src/dai/sdk-impl.js @@ -20,7 +20,8 @@ /** * Implementation of the IMA DAI SDK for the plugin. * - * @param {DaiController!} daiController Reference to the parent DAI controller. + * @param {DaiController!} daiController Reference to the parent DAI + * controller. * * @constructor * @struct @@ -132,7 +133,6 @@ SdkImpl.prototype.initImaDai = function() { */ SdkImpl.prototype.onAddTrack = function(event) { const track = event.track; - console.log('TRACK', track); if (track.kind === 'metadata') { track.mode = 'hidden'; track.oncuechange = (e) => { @@ -207,13 +207,11 @@ SdkImpl.prototype.onStreamPause = function() { this.loadUrl(event.getStreamData().url); break; case google.ima.dai.api.StreamEvent.Type.ERROR: - const errorMessage = event.getStreamData().errorMessage; - window.console.warn('Error loading stream, attempting to play backup stream. ' - + errorMessage); + window.console.warn('Error loading stream, attempting to play backup ' + + 'stream. ' + event.getStreamData().errorMessage); this.daiController.onErrorLoadingAds(event); - const fallbackUrl = this.daiController.getSettings().fallbackStreamUrl; - if (fallbackUrl) { - this.loadurl(fallbackUrl); + if (this.daiController.getSettings().fallbackStreamUrl) { + this.loadurl(this.daiController.getSettings().fallbackStreamUrl); } break; case google.ima.dai.api.StreamEvent.Type.AD_BREAK_STARTED: @@ -225,8 +223,8 @@ SdkImpl.prototype.onStreamPause = function() { this.isAdBreak = false; this.adUiDiv.style.display = 'none'; this.daiController.onAdBreakEnd(); - const currentTime = this.vjsPlayer.currentTime(); - if (this.snapForwardTime && this.snapForwardTime > currentTime) { + if (this.snapForwardTime && this.snapForwardTime > + this.vjsPlayer.currentTime()) { this.vjsPlayer.currentTime(this.snapForwardTime); this.snapForwardTime = 0; } @@ -250,7 +248,8 @@ SdkImpl.prototype.loadUrl = function(streamUrl) { const bookmarkTime = this.daiController.getSettings().bookmarkTime; if (bookmarkTime) { - const startTime = this.streamManager.streamTimeForContentTime(bookmarkTime); + const startTime = + this.streamManager.streamTimeForContentTime(bookmarkTime); // Seeking on load triggers the onSeekEnd event, so treat this seek as // if it's snapback. Without this, resuming at a bookmark kicks you // back to the ad before the bookmark. @@ -285,7 +284,8 @@ SdkImpl.prototype.requestStream = function() { streamRequest.authKey = this.daiController.getSettings().authKey; } if (this.daiController.getSettings().adTagParameters) { - streamRequest.adTagParameters = this.daiController.getSettings().adTagParameters; + streamRequest.adTagParameters = + this.daiController.getSettings().adTagParameters; } if (this.daiController.getSettings().streamActivityMonitorId) { streamRequest.streamActivityMonitorId = @@ -336,7 +336,8 @@ SdkImpl.prototype.onPlayerDisposed = function() { /** * Returns the instance of the StreamManager. - * @return {google.ima.StreamManager!} The StreamManager being used by the plugin. + * @return {google.ima.StreamManager!} The StreamManager being used by the + * plugin. */ SdkImpl.prototype.getStreamManager = function() { return this.StreamManager; diff --git a/src/ima-plugin.js b/src/ima-plugin.js index 2ef92ce2..a415b38f 100644 --- a/src/ima-plugin.js +++ b/src/ima-plugin.js @@ -234,11 +234,9 @@ const ImaDaiPlugin = function(player, options) { }.bind(this); /** - * Adds an EventListener to the StreamManager. For a list of available events, - * see - * https://developers.google.com/interactive-media-ads/docs/sdks/html5/dai/reference/js/StreamEvent - * @param {google.ima.StreamEvent.Type} event The StreamEvent.Type for which to - * listen. + * Adds an EventListener to the StreamManager. + * @param {google.ima.StreamEvent.Type} event The StreamEvent.Type for which + * to listen. * @param {callback} callback The method to call when the event is fired. */ this.addEventListener = function(event, callback) { @@ -247,19 +245,33 @@ const ImaDaiPlugin = function(player, options) { /** * Returns the instance of the StreamManager. - * @return {google.ima.StreamManager} The StreamManager being used by the plugin. + * @return {google.ima.StreamManager} The StreamManager being used by the + * plugin. */ this.getStreamManager = function() { return this.controller.getStreamManager(); }.bind(this); -} +}; +/** + * Initializes the plugin for client-side ads. + * @param {Object} options Plugin option set on initiation. + */ const init = function(options) { /* eslint no-invalid-this: 'off' */ this.ima = new ImaPlugin(this, options); }; +/** + * LiveStream class used for DAI live streams. + */ class LiveStream { + /** + * LiveStream class constructor used for DAI live streams. + * @param {string} streamFormat stream format, plugin currently supports only + * 'hls' streams. + * @param {string} assetKey live stream's asset key. + */ constructor(streamFormat, assetKey) { streamFormat = streamFormat.toLowerCase(); if (streamFormat !== 'hls' && streamFormat !== 'dash') { @@ -278,7 +290,17 @@ class LiveStream { } } +/** + * VodStream class used for DAI VOD streams. + */ class VodStream { + /** + * VodStream class constructor used for DAI VOD streams. + * @param {string} streamFormat stream format, plugin currently supports only + * 'hls' streams. + * @param {string} cmsId VOD stream's CMS ID. + * @param {string} videoId VOD stream's video ID. + */ constructor(streamFormat, cmsId, videoId) { streamFormat = streamFormat.toLowerCase(); if (streamFormat !== 'hls' && streamFormat !== 'dash') { @@ -291,7 +313,7 @@ class VodStream { } else if (typeof cmsId !== 'string') { window.console.error('cmsId error: value must be string.'); return; - } else if(typeof videoId !== 'string') { + } else if (typeof videoId !== 'string') { window.console.error('videoId error: value must be string.'); return; } @@ -302,6 +324,12 @@ class VodStream { } } +/** + * Initializes the plugin for DAI ads. + * @param {Object} stream Accepts either an instance of the LiveStream or + * VodStream classes. + * @param {Object} options Plugin option set on initiation. + */ const initDai = function(stream, options) { if (stream instanceof LiveStream) { options.streamType = 'live'; @@ -311,7 +339,9 @@ const initDai = function(stream, options) { options.cmsId = stream.cmsId; options.videoId = stream.videoId; } else { - window.console.error('initDai() first parameter must be an instance of LiveStream or VodStream.'); + window.console.error( + 'initDai() first parameter must be an instance of LiveStream or ' + + 'VodStream.'); return; } @@ -327,5 +357,5 @@ registerPlugin('imaDai', initDai); export default ImaPlugin; export { VodStream, - LiveStream -} + LiveStream, +};