[admob] temp fix for duplicate subscriptions
This commit is contained in:
parent
ce0934d44c
commit
22e511209a
|
@ -5,6 +5,8 @@ import { nativeToJSError } from '../../utils';
|
|||
|
||||
const FirebaseAdMob = NativeModules.RNFirebaseAdMob;
|
||||
|
||||
let subscriptions = [];
|
||||
|
||||
export default class Interstitial {
|
||||
|
||||
constructor(admob: Object, adUnit: string) {
|
||||
|
@ -13,10 +15,16 @@ export default class Interstitial {
|
|||
FirebaseAdMob.clearInterstitial(adUnit);
|
||||
}
|
||||
|
||||
for (let i = 0, len = subscriptions.length; i < len; i++) {
|
||||
subscriptions[i].remove();
|
||||
}
|
||||
subscriptions = [];
|
||||
|
||||
this.admob = admob;
|
||||
this.adUnit = adUnit;
|
||||
this.loaded = false;
|
||||
this.admob.on(`interstitial_${adUnit}`, this._onInterstitialEvent.bind(this));
|
||||
this.admob.removeAllListeners(`interstitial_${adUnit}`);
|
||||
this.admob.on(`interstitial_${adUnit}`, this._onInterstitialEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +32,7 @@ export default class Interstitial {
|
|||
* @param event
|
||||
* @private
|
||||
*/
|
||||
_onInterstitialEvent(event) {
|
||||
_onInterstitialEvent = (event) => {
|
||||
const eventType = `interstitial:${this.adUnit}:${event.type}`;
|
||||
|
||||
let emitData = Object.assign({}, event);
|
||||
|
@ -42,7 +50,7 @@ export default class Interstitial {
|
|||
|
||||
this.admob.emit(eventType, emitData);
|
||||
this.admob.emit(`interstitial:${this.adUnit}:*`, emitData);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Load an ad with an instance of AdRequest
|
||||
|
@ -89,6 +97,8 @@ export default class Interstitial {
|
|||
return null;
|
||||
}
|
||||
|
||||
return this.admob.on(`interstitial:${this.adUnit}:${eventType}`, listenerCb);
|
||||
const sub = this.admob.on(`interstitial:${this.adUnit}:${eventType}`, listenerCb);
|
||||
subscriptions.push(sub);
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,21 @@ import { nativeToJSError } from '../../utils';
|
|||
|
||||
const FirebaseAdMob = NativeModules.RNFirebaseAdMob;
|
||||
|
||||
let subscriptions = [];
|
||||
|
||||
export default class RewardedVideo {
|
||||
|
||||
constructor(admob: Object, adunit: string) {
|
||||
constructor(admob: Object, adUnit: string) {
|
||||
for (let i = 0, len = subscriptions.length; i < len; i++) {
|
||||
subscriptions[i].remove();
|
||||
}
|
||||
subscriptions = [];
|
||||
|
||||
this.admob = admob;
|
||||
this.adUnit = adunit;
|
||||
this.adUnit = adUnit;
|
||||
this.loaded = false;
|
||||
this.admob.on(`rewarded_video_${adunit}`, this._onRewardedVideoEvent.bind(this));
|
||||
this.admob.removeAllListeners(`rewarded_video_${adUnit}`);
|
||||
this.admob.on(`rewarded_video_${adUnit}`, this._onRewardedVideoEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +27,7 @@ export default class RewardedVideo {
|
|||
* @param event
|
||||
* @private
|
||||
*/
|
||||
_onRewardedVideoEvent(event) {
|
||||
_onRewardedVideoEvent = (event) => {
|
||||
const eventType = `rewarded_video:${this.adUnit}:${event.type}`;
|
||||
|
||||
let emitData = Object.assign({}, event);
|
||||
|
@ -37,7 +45,7 @@ export default class RewardedVideo {
|
|||
|
||||
this.admob.emit(eventType, emitData);
|
||||
this.admob.emit(`rewarded_video:${this.adUnit}:*`, emitData);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Load an ad with an instance of AdRequest
|
||||
|
@ -89,6 +97,8 @@ export default class RewardedVideo {
|
|||
return null;
|
||||
}
|
||||
|
||||
return this.admob.on(`rewarded_video:${this.adUnit}:${eventType}`, listenerCb);
|
||||
const sub = this.admob.on(`rewarded_video:${this.adUnit}:${eventType}`, listenerCb);
|
||||
subscriptions.push(sub);
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue