Skip to content

Commit

Permalink
refactor: Deprecated id setting, instead get the id from Vjs player. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ypavlotsky committed May 23, 2018
1 parent 30734c6 commit f08408a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/ad-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ const AdUi = function(controller) {
/**
* Used to prefix videojs ima controls.
*/
this.controlPrefix = this.controller.getSettings().id ?
this.controller.getSettings().id + '_' : '';
this.controlPrefix = this.controller.getPlayerId() + '_';

/**
* Boolean flag to show or hide the ad countdown timer.
Expand Down
12 changes: 7 additions & 5 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ Controller.IMA_DEFAULTS = {
Controller.prototype.initWithSettings = function(options) {
this.settings = this.extend({}, Controller.IMA_DEFAULTS, options || {});

if (!this.settings.id) {
window.console.error('Error: must provide id of video.js div');
return;
}

this.warnAboutDeprecatedSettings();

// Default showing countdown timer to true.
Expand Down Expand Up @@ -662,6 +657,13 @@ Controller.prototype.getAdsManager = function() {
return this.sdkImpl.getAdsManager();
};

/**
* Returns the instance of the player id.
* @return {string} The player id.
*/
Controller.prototype.getPlayerId = function() {
return this.playerWrapper.getPlayerId();
};

/**
* Changes the ad tag. You will need to call requestAds after this method
Expand Down
9 changes: 8 additions & 1 deletion src/player-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ PlayerWrapper.prototype.onReadyForPreroll = function() {
PlayerWrapper.prototype.onPlayerReady = function() {
this.h5Player =
document.getElementById(
this.controller.getSettings().id).getElementsByClassName(
this.getPlayerId()).getElementsByClassName(
'vjs-tech')[0];

// Detect inline options
Expand Down Expand Up @@ -407,6 +407,13 @@ PlayerWrapper.prototype.getPlayerOptions = function() {
return this.vjsPlayer.options_;
};

/**
* Returns the instance of the player id.
* @return {string} The player id.
*/
PlayerWrapper.prototype.getPlayerId = function() {
return this.vjsPlayer.id();
};

/**
* Toggle fullscreen state.
Expand Down

0 comments on commit f08408a

Please sign in to comment.