react-native-tapdaq
Version:
Tapdaq bridge in React Native
212 lines (211 loc) • 8.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const tapdaqEventEmitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNTapdaq);
const version = '1.0.27';
class RNTapdaq {
constructor() {
this.initialize = (applicationId, clientKey, config) => {
return new Promise((resolve, reject) => {
let isInitialized = {};
if (config) {
isInitialized = this.nativeModule
.initializeWithConfig(applicationId, clientKey, config)
.then((status, error) => {
if (status) {
resolve(status);
}
else {
reject(false);
}
});
}
else {
isInitialized = this.nativeModule
.initialize(applicationId, clientKey)
.then((status, error) => {
if (status) {
resolve(status);
}
else {
reject(false);
}
});
}
});
};
this.isInitialized = () => {
return this.nativeModule.isInitialized();
};
this.openTestControls = () => {
this.nativeModule.openTestControls();
};
this.setConsentGiven = (value) => {
this.nativeModule.setConsentGiven(value);
};
this.setIsAgeRestrictedUser = (value) => {
this.nativeModule.setIsAgeRestrictedUser(value);
};
this.setUserSubjectToGDPR = (value) => {
this.nativeModule.setUserSubjectToGDPR(value);
};
this.setUserId = (id) => {
this.nativeModule.setUserId(id);
};
this.isInterstitialReady = (placementTag) => {
return this.nativeModule.isInterstitialReady(placementTag);
};
this.loadAndShowRandomAds = (placementTag) => {
let type = Math.floor(Math.random() * 9);
if (type === 0) {
return this.loadAndShowStaticInterstitial(placementTag);
}
else if (type === 1) {
return this.loadAndShowRewardedVideo(placementTag);
}
else if (type === 2) {
return this.loadAndShowBanner(placementTag);
}
else if (type === 3) {
return this.loadBannerForPlacementTagSize(placementTag, 'TDMBannerLarge', -1, 0, 0, 0);
}
else if (type === 4) {
return this.loadBannerForPlacementTagSize(placementTag, 'TDMBannerMedium', -1, 0, 0, 0);
}
else if (type === 5) {
return this.loadBannerForPlacementTagSize(placementTag, 'TDMBannerFull', -1, 0, 0, 0);
}
else if (type === 6) {
return this.loadBannerForPlacementTagSize(placementTag, 'TDMBannerLeaderboard', -1, 0, 0, 0);
}
else if (type === 7) {
return this.loadBannerForPlacementTagSize(placementTag, 'TDMBannerSmart', -1, 0, 0, 0);
}
else {
return this.loadBannerForPlacementTagSize(placementTag, 'TDMBannerStandard', -1, 0, 0, 0);
}
};
this.loadAndShowStaticInterstitial = (placementTag) => {
return new Promise((resolve, reject) => {
// @ts-ignore
this.loadInterstitial(placementTag).then((status, error) => {
if (status) {
// @ts-ignore
this.showInterstitial(placementTag).then((status, error) => {
if (status) {
resolve(status);
}
else {
reject(false);
}
});
}
else {
reject(false);
}
});
});
};
this.loadInterstitial = (placementTag) => {
return this.nativeModule.loadInterstitial(placementTag);
};
this.showInterstitial = (placementTag) => {
return this.nativeModule.showInterstitial(placementTag);
};
this.loadAndShowBanner = (placementTag) => {
return new Promise((resolve, reject) => {
// @ts-ignore
this.loadBannerForPlacementTag(placementTag).then((status, error) => {
if (status) {
resolve(status);
}
else {
reject(false);
}
});
});
};
this.loadBannerForPlacementTag = (placementTag) => {
return this.nativeModule.loadBannerForPlacementTag(placementTag);
};
this.hideBanner = () => {
return this.nativeModule.hideBanner();
};
this.loadBannerForPlacementTagSize = (placementTag, type, x, y, width, height) => {
let newtype = 0;
if (type == 'TDMBannerLarge') {
newtype = 1;
}
else if (type == 'TDMBannerMedium') {
newtype = 2;
}
else if (type == 'TDMBannerFull') {
newtype = 3;
}
else if (type == 'TDMBannerLeaderboard') {
newtype = 4;
}
else if (type == 'TDMBannerSmart') {
newtype = 5;
}
else if (type == 'TDMBannerCustom') {
newtype = 6;
}
return this.nativeModule.loadBannerForPlacementTagSize(placementTag, newtype, x, y, width, height);
};
this.isRewardedVideoReady = (placementTag) => {
return this.nativeModule.isRewardedVideoReady(placementTag);
};
this.loadAndShowRewardedVideo = (placementTag) => {
return new Promise((resolve, reject) => {
// @ts-ignore
this.loadRewardedVideo(placementTag).then((status, error) => {
if (status) {
// @ts-ignore
this.showRewardedVideo(placementTag).then((status, error) => {
if (status) {
resolve(status);
}
else {
reject(false);
}
});
}
else {
reject(false);
}
});
});
};
this.loadRewardedVideo = (placementTag) => {
return this.nativeModule.loadRewardedVideo(placementTag);
};
this.showRewardedVideo = (placementTag) => {
return this.nativeModule.showRewardedVideo(placementTag);
};
this.loadAndShowNative = (placementTag) => {
return this.nativeModule.loadAndShowNative(placementTag);
};
this.loadAndShowStaticVideo = (placementTag) => {
return this.nativeModule.loadAndShowStaticVideo(placementTag);
};
this.addListerner = (callback) => {
return tapdaqEventEmitter.addListener('tapdaq', callback);
};
this.addOnRewardListener = (callback) => {
return tapdaqEventEmitter.addListener('tapdaqReward', callback);
};
}
get nativeModule() {
return react_native_1.NativeModules.RNTapdaq;
}
js_version() {
return version;
}
ios_version() {
return this.nativeModule.versionIOS();
}
}
var MediatedNativeAd_1 = require("./components/MediatedNativeAd");
exports.MediatedNativeAd = MediatedNativeAd_1.default;
exports.default = new RNTapdaq();