module PhaserAds { export module AdProvider { export class CordovaGameDistribution implements PhaserAds . AdProvider . IProvider { public adManager : AdManager ; public adsEnabled : boolean = false ; public hasRewarded : boolean = false ; constructor ( game , gameId , userId , debug = false ) { if ( cordova . plugins === undefined || ( cordova . plugins !== undefined && cordova . plugins . gdApi === undefined ) ) { console . log ( 'gdApi not available!' ) ; return ; } if ( debug ) { cordova . plugins . gdApi . enableTestAds ( ) ; } this . setAdListeners ( ) ; ( < CordovaPluginGdApi > cordova . plugins . gdApi ) . init ( [ gameId , userId ] , ( data ) => { console . log ( 'API init success!' , data ) ; } , ( error ) => { console . log ( 'API init error!' , error ) ; } ) ; } private setAdListeners ( ) { ( < CordovaPluginGdApi > cordova . plugins . gdApi ) . setAdListener ( ( data ) => { console . log ( 'banner reply, data.event' , data . event , data ) ; switch ( data . event ) { case 'BANNER_STARTED' : this . adManager . onContentPaused . dispatch ( ) ; break ; case 'API_IS_READY' : this . adsEnabled = true ; break ; case 'API_ALREADY_INITIALIZED' : break ; case 'BANNER_CLOSED' : case 'API_NOT_READY' : case 'BANNER_FAILED' : this . adManager . onContentResumed . dispatch ( ) ; break ; } } , ( error ) => { console . log ( 'Set listener error:' , error ) ; this . adsEnabled = false ; } ) ; } public setManager ( manager ) { this . adManager = manager ; } public showAd ( adType ? ) { if ( this . adsEnabled ) { console . log ( 'show banner called' ) ; ( < CordovaPluginGdApi > cordova . plugins . gdApi ) . showBanner ( ( data ) => { console . log ( 'Show banner worked' , data ) ; } , ( data ) => { console . log ( 'Could not show banner:' , data ) ; this . adManager . onContentResumed . dispatch ( ) ; } ) ; } else { console . log ( 'Ads not enabled, resuming' ) ; this . adManager . onContentResumed . dispatch ( ) ; } } public preloadAd ( ) { return ; } public destroyAd ( ) { return ; } public hideAd ( ) { return ; } } } }