2017-05-26 16:55:22 +00:00
|
|
|
import { NativeModules, NativeEventEmitter } from 'react-native';
|
2017-05-27 14:24:51 +00:00
|
|
|
import { nativeSDKMissing } from './../../utils';
|
|
|
|
|
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 16:55:22 +00:00
|
|
|
import { Base } from './../base';
|
2017-05-26 14:18:57 +00:00
|
|
|
|
|
|
|
const FirebaseAdMob = NativeModules.RNFirebaseAdMob;
|
2017-05-31 14:22:15 +00:00
|
|
|
const FirebaseAdMobEvt = FirebaseAdMob && new NativeEventEmitter(FirebaseAdMob);
|
2017-05-26 14:18:57 +00:00
|
|
|
|
|
|
|
export default class Admob extends Base {
|
|
|
|
|
2017-05-26 16:55:22 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
2017-05-31 14:22:15 +00:00
|
|
|
if (!FirebaseAdMob) {
|
2017-05-27 14:24:51 +00:00
|
|
|
return nativeSDKMissing('admob');
|
|
|
|
}
|
|
|
|
|
2017-06-01 09:22:15 +00:00
|
|
|
this._initialized = false;
|
2017-05-26 16:55:22 +00:00
|
|
|
FirebaseAdMobEvt.addListener('interstitial_event', this._onInterstitialEvent.bind(this));
|
2017-05-27 16:03:09 +00:00
|
|
|
FirebaseAdMobEvt.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!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._initialized = true;
|
|
|
|
return FirebaseAdMob.initialize(appId);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|