Skip to content

Commit

Permalink
fix: ads preset fails when using player (#414)
Browse files Browse the repository at this point in the history
following #410 Ads preset is referencing player directly so need to use context.
  • Loading branch information
OrenMe committed Sep 25, 2019
1 parent f749921 commit 31f2b1c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/ui-presets/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ const PRESET_NAME = 'Ads';
* Ads ui interface component
*
* @param {*} props component props
* @param {*} context component context
* @returns {?HTMLElement} player ui tree
*/
function AdsUI(props: any): ?React$Element<any> {
if (useDefaultAdsUi(props)) {
function AdsUI(props: any, context: any): ?React$Element<any> {
if (useDefaultAdsUi(props, context)) {
return (
<div className={style.adGuiWrapper}>
<Loading />
<div className={style.playerGui} id="player-gui">
<UnmuteIndication hasTopBar />
<TopBar disabled={true}>
<div className={style.leftControls}>{isBumper(props) ? undefined : <AdNotice />}</div>
<div className={style.leftControls}>{isBumper(props, context) ? undefined : <AdNotice />}</div>
</TopBar>
</div>
</div>
Expand All @@ -44,7 +45,7 @@ function AdsUI(props: any): ?React$Element<any> {
<div className={style.playerGui} id="player-gui">
<UnmuteIndication hasTopBar />
<TopBar disabled={true}>
<div className={style.leftControls}>{isBumper(props) ? undefined : <AdNotice />}</div>
<div className={style.leftControls}>{isBumper(props, context) ? undefined : <AdNotice />}</div>
<div className={style.rightControls}>{adsUiCustomization.learnMoreButton ? <AdLearnMore /> : undefined}</div>
</TopBar>
{adsUiCustomization.skipButton ? <AdSkip /> : undefined}
Expand Down Expand Up @@ -91,13 +92,14 @@ function getAdsUiCustomization(): Object {
/**
* Whether the default ads ui should be shown or not.
* @param {any} props - component props
* @param {any} context - context
* @returns {boolean} - Whether the default ads ui should be shown or not.
*/
function useDefaultAdsUi(props: any): boolean {
function useDefaultAdsUi(props: any, context: any): boolean {
const isMobile = props.state.shell.isMobile;
let useStyledLinearAds = false;
try {
const adsRenderingSettings = props.player.config.plugins.ima.adsRenderingSettings;
const adsRenderingSettings = context.player.config.plugins.ima.adsRenderingSettings;
useStyledLinearAds = adsRenderingSettings && adsRenderingSettings.useStyledLinearAds;
} catch (e) {
// Do nothing
Expand All @@ -108,10 +110,11 @@ function useDefaultAdsUi(props: any): boolean {
/**
* Whether the current ad is a bumper.
* @param {any} props - component props
* @param {any} context - component context
* @returns {boolean} - Whether is bumper.
*/
function isBumper(props: any): boolean {
const ad = props.player.ads.getAd();
function isBumper(props: any, context: any): boolean {
const ad = context.player.ads.getAd();
return ad && ad.bumper;
}

Expand Down

0 comments on commit 31f2b1c

Please sign in to comment.