2017-06-30 16:23:32 +00:00
|
|
|
import ModuleBase from './../../utils/ModuleBase';
|
2017-05-27 14:24:51 +00:00
|
|
|
|
2017-05-26 14:18:57 +00:00
|
|
|
import Interstitial from './Interstitial';
|
2017-05-27 16:03:09 +00:00
|
|
|
import RewardedVideo from './RewardedVideo';
|
2017-05-26 14:18:57 +00:00
|
|
|
import AdRequest from './AdRequest';
|
2017-05-31 15:33:08 +00:00
|
|
|
import VideoOptions from './VideoOptions';
|
2017-05-26 14:18:57 +00:00
|
|
|
import Banner from './Banner';
|
2017-05-31 15:33:08 +00:00
|
|
|
import NativeExpress from './NativeExpress';
|
2017-05-26 14:18:57 +00:00
|
|
|
|
|
|
|
|
2017-06-30 16:23:32 +00:00
|
|
|
export default class Admob extends ModuleBase {
|
|
|
|
constructor(firebaseApp: Object, options: Object = {}) {
|
|
|
|
super(firebaseApp, options, 'AdMob', true);
|
2017-05-27 14:24:51 +00:00
|
|
|
|
2017-06-01 09:22:15 +00:00
|
|
|
this._initialized = false;
|
2017-06-27 14:14:02 +00:00
|
|
|
this._appId = null;
|
2017-06-30 16:23:32 +00:00
|
|
|
|
|
|
|
this._eventEmitter.addListener('interstitial_event', this._onInterstitialEvent.bind(this));
|
|
|
|
this._eventEmitter.addListener('rewarded_video_event', this._onRewardedVideoEvent.bind(this));
|
2017-05-26 16:55:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_onInterstitialEvent(event) {
|
2017-05-27 16:03:09 +00:00
|
|
|
const { adUnit } = event;
|
|
|
|
const jsEventType = `interstitial_${adUnit}`;
|
|
|
|
|
|
|
|
if (!this.hasListeners(jsEventType)) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit(jsEventType, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onRewardedVideoEvent(event) {
|
|
|
|
const { adUnit } = event;
|
|
|
|
const jsEventType = `rewarded_video_${adUnit}`;
|
2017-05-26 16:55:22 +00:00
|
|
|
|
|
|
|
if (!this.hasListeners(jsEventType)) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit(jsEventType, event);
|
|
|
|
}
|
|
|
|
|
2017-06-01 09:22:15 +00:00
|
|
|
initialize(appId: string) {
|
|
|
|
if (this._initialized) {
|
|
|
|
this.log.warn('AdMob has already been initialized!');
|
2017-06-30 16:23:32 +00:00
|
|
|
} else {
|
|
|
|
this._initialized = true;
|
|
|
|
this._appId = appId;
|
|
|
|
this._native.initialize(appId);
|
2017-06-01 09:22:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-27 14:14:02 +00:00
|
|
|
openDebugMenu() {
|
|
|
|
if (!this._initialized) {
|
|
|
|
this.log.warn('AdMob needs to be initialized before opening the dev menu!');
|
2017-06-30 16:23:32 +00:00
|
|
|
} else {
|
|
|
|
this.log.info('Opening debug menu');
|
|
|
|
this._native.openDebugMenu(this._appId);
|
2017-06-27 14:14:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 14:18:57 +00:00
|
|
|
interstitial(adUnit: string) {
|
2017-05-26 16:55:22 +00:00
|
|
|
return new Interstitial(this, adUnit);
|
2017-05-26 14:18:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 16:03:09 +00:00
|
|
|
rewarded(adUnit: string) {
|
|
|
|
return new RewardedVideo(this, adUnit);
|
|
|
|
}
|
|
|
|
|
2017-05-26 16:55:22 +00:00
|
|
|
static get statics() {
|
|
|
|
return statics;
|
|
|
|
}
|
2017-05-26 14:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const statics = {
|
|
|
|
Banner,
|
2017-05-31 15:33:08 +00:00
|
|
|
NativeExpress,
|
2017-05-26 14:18:57 +00:00
|
|
|
AdRequest,
|
2017-05-31 15:33:08 +00:00
|
|
|
VideoOptions,
|
2017-05-26 16:55:22 +00:00
|
|
|
EventTypes: {
|
|
|
|
onAdLoaded: 'onAdLoaded',
|
|
|
|
onAdOpened: 'onAdOpened',
|
|
|
|
onAdLeftApplication: 'onAdLeftApplication',
|
|
|
|
onAdClosed: 'onAdClosed',
|
|
|
|
onAdFailedToLoad: 'onAdFailedToLoad',
|
|
|
|
},
|
2017-05-27 16:27:22 +00:00
|
|
|
RewardedVideoEventTypes: {
|
|
|
|
onRewarded: 'onRewarded',
|
|
|
|
onRewardedVideoStarted: 'onRewardedVideoStarted',
|
|
|
|
},
|
2017-05-31 15:33:08 +00:00
|
|
|
NativeExpressEventTypes: {
|
|
|
|
onVideoEnd: 'onVideoEnd',
|
2017-06-20 11:19:26 +00:00
|
|
|
onVideoMute: 'onVideoMute',
|
|
|
|
onVideoPause: 'onVideoPause',
|
|
|
|
onVideoPlay: 'onVideoPlay',
|
|
|
|
onVideoStart: 'onVideoStart',
|
2017-05-31 15:33:08 +00:00
|
|
|
},
|
2017-05-26 14:18:57 +00:00
|
|
|
};
|