module PhaserAds { export module AdProvider { export enum HeyzapAdTypes { Interstitial , Video , Rewarded , Banner } export class CordovaHeyzap implements IProvider { public adManager : AdManager ; public adsEnabled : boolean = false ; public hasRewarded : boolean = false ; constructor ( game , publisherId ) { if ( game . device . cordova || game . device . crosswalk ) { this . adsEnabled = true ; } else { return ; } HeyzapAds . start ( publisherId ) . then ( ( ) => { } , ( error ) => { this . adsEnabled = false ; } ) ; } public setManager ( manager ) { this . adManager = manager ; } public showAd ( adType , bannerAdPositions ? ) { if ( ! this . adsEnabled ) { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( ) ; } switch ( adType ) { case HeyzapAdTypes . Interstitial : HeyzapAds . InterstitialAd . addEventListener ( HeyzapAds . InterstitialAd . Events . HIDE , ( ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( HeyzapAds . InterstitialAd . Events . HIDE ) ; } ) ; HeyzapAds . InterstitialAd . addEventListener ( HeyzapAds . InterstitialAd . Events . SHOW_FAILED , ( ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( HeyzapAds . InterstitialAd . Events . SHOW_FAILED ) ; } ) ; HeyzapAds . InterstitialAd . addEventListener ( HeyzapAds . InterstitialAd . Events . CLICKED , ( ) => { this . adManager . onAdClicked . dispatch ( HeyzapAds . InterstitialAd . Events . CLICKED ) ; } ) ; HeyzapAds . InterstitialAd . show ( ) . then ( ( ) => { this . adManager . onContentPaused . dispatch ( ) ; } , ( error ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( ) ; } ) ; break ; case HeyzapAdTypes . Video : HeyzapAds . VideoAd . addEventListener ( HeyzapAds . VideoAd . Events . HIDE , ( ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( HeyzapAds . VideoAd . Events . HIDE ) ; } ) ; HeyzapAds . VideoAd . addEventListener ( HeyzapAds . VideoAd . Events . SHOW_FAILED , ( ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( HeyzapAds . VideoAd . Events . SHOW_FAILED ) ; } ) ; HeyzapAds . VideoAd . addEventListener ( HeyzapAds . VideoAd . Events . CLICKED , ( ) => { this . adManager . onAdClicked . dispatch ( HeyzapAds . VideoAd . Events . CLICKED ) ; } ) ; HeyzapAds . VideoAd . show ( ) . then ( ( ) => { this . adManager . onContentPaused . dispatch ( ) ; } , ( error ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( ) ; } ) ; break ; case HeyzapAdTypes . Rewarded : HeyzapAds . IncentivizedAd . addEventListener ( HeyzapAds . IncentivizedAd . Events . HIDE , ( ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( HeyzapAds . IncentivizedAd . Events . HIDE ) ; } ) ; HeyzapAds . IncentivizedAd . addEventListener ( HeyzapAds . IncentivizedAd . Events . SHOW_FAILED , ( ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( HeyzapAds . IncentivizedAd . Events . SHOW_FAILED ) ; } ) ; HeyzapAds . IncentivizedAd . addEventListener ( HeyzapAds . IncentivizedAd . Events . CLICKED , ( ) => { this . adManager . onAdClicked . dispatch ( HeyzapAds . IncentivizedAd . Events . CLICKED ) ; } ) ; HeyzapAds . IncentivizedAd . show ( ) . then ( ( ) => { this . adManager . onContentPaused . dispatch ( ) ; } , ( error ) => { this . adManager . unMuteAfterAd ( ) ; this . adManager . onContentResumed . dispatch ( ) ; } ) ; break ; case HeyzapAdTypes . Banner : HeyzapAds . BannerAd . show ( bannerAdPositions ) . then ( ( ) => { } , ( error ) => { } ) ; break ; } } public preloadAd ( adType ) { if ( ! this . adsEnabled ) { return ; } if ( adType === HeyzapAdTypes . Rewarded ) { HeyzapAds . IncentivizedAd . fetch ( ) . then ( ( ) => { } , ( error ) => { } ) ; } return ; } public destroyAd ( adType ) { if ( ! this . adsEnabled ) { return ; } if ( adType === HeyzapAdTypes . Banner ) { HeyzapAds . BannerAd . destroy ( ) . then ( ( ) => { } , ( error ) => { } ) ; } return ; } public hideAd ( adType ) { if ( ! this . adsEnabled ) { return ; } if ( adType === HeyzapAdTypes . Banner ) { HeyzapAds . BannerAd . hide ( ) . then ( ( ) => { } , ( error ) => { } ) ; } return ; } } } }