Skip to content

Commit

Permalink
Fixes lint errors.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 453251753
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Jun 6, 2022
1 parent 7829eb7 commit 596c76f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
31 changes: 3 additions & 28 deletions src/client-side/controller.js
Expand Up @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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;
1 change: 0 additions & 1 deletion src/client-side/sdk-impl.js
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/dai/dai-controller.js
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
27 changes: 14 additions & 13 deletions src/dai/sdk-impl.js
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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:
Expand All @@ -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;
}
Expand All @@ -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.
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down
52 changes: 41 additions & 11 deletions src/ima-plugin.js
Expand Up @@ -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) {
Expand All @@ -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') {
Expand All @@ -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') {
Expand All @@ -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;
}
Expand All @@ -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';
Expand All @@ -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;
}

Expand All @@ -327,5 +357,5 @@ registerPlugin('imaDai', initDai);
export default ImaPlugin;
export {
VodStream,
LiveStream
}
LiveStream,
};

0 comments on commit 596c76f

Please sign in to comment.