cordova-admob-tomitank 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +17 -0
  3. package/esm/admob.d.ts +3 -0
  4. package/esm/admob.js +22 -0
  5. package/esm/admob.js.map +1 -0
  6. package/esm/api.d.ts +61 -0
  7. package/esm/api.js +232 -0
  8. package/esm/api.js.map +1 -0
  9. package/esm/app-open.d.ts +17 -0
  10. package/esm/app-open.js +83 -0
  11. package/esm/app-open.js.map +1 -0
  12. package/esm/banner.d.ts +33 -0
  13. package/esm/banner.js +143 -0
  14. package/esm/banner.js.map +1 -0
  15. package/esm/generated.d.ts +77 -0
  16. package/esm/generated.js +104 -0
  17. package/esm/generated.js.map +1 -0
  18. package/esm/index.d.ts +31 -0
  19. package/esm/index.js +95 -0
  20. package/esm/index.js.map +1 -0
  21. package/esm/interstitial.d.ts +7 -0
  22. package/esm/interstitial.js +35 -0
  23. package/esm/interstitial.js.map +1 -0
  24. package/esm/native.d.ts +19 -0
  25. package/esm/native.js +134 -0
  26. package/esm/native.js.map +1 -0
  27. package/esm/rewarded-interstitial.d.ts +10 -0
  28. package/esm/rewarded-interstitial.js +35 -0
  29. package/esm/rewarded-interstitial.js.map +1 -0
  30. package/esm/rewarded.d.ts +14 -0
  31. package/esm/rewarded.js +35 -0
  32. package/esm/rewarded.js.map +1 -0
  33. package/esm/shared.d.ts +2 -0
  34. package/esm/shared.js +3 -0
  35. package/esm/shared.js.map +1 -0
  36. package/lib/admob.d.ts +3 -0
  37. package/lib/admob.js +50 -0
  38. package/lib/admob.js.map +1 -0
  39. package/lib/api.d.ts +61 -0
  40. package/lib/api.js +240 -0
  41. package/lib/api.js.map +1 -0
  42. package/lib/app-open.d.ts +17 -0
  43. package/lib/app-open.js +85 -0
  44. package/lib/app-open.js.map +1 -0
  45. package/lib/banner.d.ts +33 -0
  46. package/lib/banner.js +145 -0
  47. package/lib/banner.js.map +1 -0
  48. package/lib/generated.d.ts +77 -0
  49. package/lib/generated.js +110 -0
  50. package/lib/generated.js.map +1 -0
  51. package/lib/index.d.ts +31 -0
  52. package/lib/index.js +120 -0
  53. package/lib/index.js.map +1 -0
  54. package/lib/interstitial.d.ts +7 -0
  55. package/lib/interstitial.js +37 -0
  56. package/lib/interstitial.js.map +1 -0
  57. package/lib/native.d.ts +19 -0
  58. package/lib/native.js +136 -0
  59. package/lib/native.js.map +1 -0
  60. package/lib/rewarded-interstitial.d.ts +10 -0
  61. package/lib/rewarded-interstitial.js +37 -0
  62. package/lib/rewarded-interstitial.js.map +1 -0
  63. package/lib/rewarded.d.ts +14 -0
  64. package/lib/rewarded.js +37 -0
  65. package/lib/rewarded.js.map +1 -0
  66. package/lib/shared.d.ts +2 -0
  67. package/lib/shared.js +19 -0
  68. package/lib/shared.js.map +1 -0
  69. package/package.json +73 -0
  70. package/plugin.xml +333 -0
  71. package/scripts/iosNSAppTransportSecurity.js +29 -0
  72. package/scripts/iosNSAppTransportSecurity.ts +33 -0
  73. package/scripts/tsconfig.json +5 -0
  74. package/scripts/util.js +34 -0
  75. package/scripts/util.ts +44 -0
  76. package/src/android/cordova/AdMob.java +256 -0
  77. package/src/android/cordova/ExecuteContext.java +174 -0
  78. package/src/android/cordova/Generated.java +72 -0
  79. package/src/android/cordova/ads/AdBase.java +54 -0
  80. package/src/android/cordova/ads/AppOpen.java +98 -0
  81. package/src/android/cordova/ads/Banner.java +370 -0
  82. package/src/android/cordova/ads/Interstitial.java +101 -0
  83. package/src/android/cordova/ads/Native.java +162 -0
  84. package/src/android/cordova/ads/Rewarded.java +108 -0
  85. package/src/android/cordova/ads/RewardedInterstitial.java +108 -0
  86. package/src/android/core/Ad.java +73 -0
  87. package/src/android/core/Context.java +186 -0
  88. package/src/android/core/GenericAd.java +22 -0
  89. package/src/android/core/Helper.java +134 -0
  90. package/src/browser/AdMobProxy.js +33 -0
  91. package/src/ios/AMBAdBase.swift +72 -0
  92. package/src/ios/AMBAppOpenAd.swift +87 -0
  93. package/src/ios/AMBBanner.swift +294 -0
  94. package/src/ios/AMBContext.swift +166 -0
  95. package/src/ios/AMBCore.swift +232 -0
  96. package/src/ios/AMBGenerated.swift +45 -0
  97. package/src/ios/AMBInterstitial.swift +69 -0
  98. package/src/ios/AMBNativeAd.swift +128 -0
  99. package/src/ios/AMBPlugin.swift +198 -0
  100. package/src/ios/AMBRewarded.swift +72 -0
  101. package/src/ios/AMBRewardedInterstitial.swift +72 -0
  102. package/src/www/admob.ts +26 -0
  103. package/src/www/api.ts +156 -0
  104. package/src/www/app-open.ts +27 -0
  105. package/src/www/banner.ts +102 -0
  106. package/src/www/cordova.d.ts +9 -0
  107. package/src/www/generated.ts +125 -0
  108. package/src/www/index.ts +88 -0
  109. package/src/www/interstitial.ts +17 -0
  110. package/src/www/native.ts +54 -0
  111. package/src/www/rewarded-interstitial.ts +20 -0
  112. package/src/www/rewarded.ts +26 -0
  113. package/src/www/shared.ts +2 -0
  114. package/www/admob.js +675 -0
@@ -0,0 +1,72 @@
1
+ import GoogleMobileAds
2
+
3
+ class AMBRewarded: AMBAdBase, GADFullScreenContentDelegate {
4
+ var mAd: GADRewardedAd?
5
+
6
+ deinit {
7
+ clear()
8
+ }
9
+
10
+ override func isLoaded() -> Bool {
11
+ return self.mAd != nil
12
+ }
13
+
14
+ override func load(_ ctx: AMBContext) {
15
+ clear()
16
+
17
+ GADRewardedAd.load(withAdUnitID: adUnitId, request: adRequest, completionHandler: { ad, error in
18
+ if error != nil {
19
+ self.emit(AMBEvents.adLoadFail, error!)
20
+ self.emit(AMBEvents.rewardedLoadFail, error!)
21
+
22
+ ctx.reject(error!)
23
+ return
24
+ }
25
+
26
+ self.mAd = ad
27
+ ad?.fullScreenContentDelegate = self
28
+ ad?.serverSideVerificationOptions = ctx.optGADServerSideVerificationOptions()
29
+
30
+ self.emit(AMBEvents.adLoad)
31
+ self.emit(AMBEvents.rewardedLoad)
32
+
33
+ ctx.resolve()
34
+ })
35
+ }
36
+
37
+ override func show(_ ctx: AMBContext) {
38
+ mAd?.present(fromRootViewController: plugin.viewController, userDidEarnRewardHandler: {
39
+ let reward = self.mAd!.adReward
40
+ self.emit(AMBEvents.adReward, reward)
41
+ self.emit(AMBEvents.rewardedReward, reward)
42
+ })
43
+ ctx.resolve()
44
+ }
45
+
46
+ func adDidRecordImpression(_ ad: GADFullScreenPresentingAd) {
47
+ self.emit(AMBEvents.adImpression)
48
+ self.emit(AMBEvents.rewardedImpression)
49
+ }
50
+
51
+ func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
52
+ clear()
53
+ self.emit(AMBEvents.adShowFail, error)
54
+ self.emit(AMBEvents.rewardedShowFail, error)
55
+ }
56
+
57
+ func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
58
+ self.emit(AMBEvents.adShow)
59
+ self.emit(AMBEvents.rewardedShow)
60
+ }
61
+
62
+ func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
63
+ clear()
64
+ self.emit(AMBEvents.adDismiss)
65
+ self.emit(AMBEvents.rewardedDismiss)
66
+ }
67
+
68
+ private func clear() {
69
+ mAd?.fullScreenContentDelegate = nil
70
+ mAd = nil
71
+ }
72
+ }
@@ -0,0 +1,72 @@
1
+ import GoogleMobileAds
2
+
3
+ class AMBRewardedInterstitial: AMBAdBase, GADFullScreenContentDelegate {
4
+ var mAd: GADRewardedInterstitialAd?
5
+
6
+ deinit {
7
+ clear()
8
+ }
9
+
10
+ override func isLoaded() -> Bool {
11
+ return self.mAd != nil
12
+ }
13
+
14
+ override func load(_ ctx: AMBContext) {
15
+ clear()
16
+
17
+ GADRewardedInterstitialAd.load(withAdUnitID: adUnitId, request: adRequest, completionHandler: { ad, error in
18
+ if error != nil {
19
+ self.emit(AMBEvents.adLoadFail, error!)
20
+ self.emit(AMBEvents.rewardedInterstitialLoadFail, error!)
21
+
22
+ ctx.reject(error!)
23
+ return
24
+ }
25
+
26
+ self.mAd = ad
27
+ ad?.fullScreenContentDelegate = self
28
+ ad?.serverSideVerificationOptions = ctx.optGADServerSideVerificationOptions()
29
+
30
+ self.emit(AMBEvents.adLoad)
31
+ self.emit(AMBEvents.rewardedInterstitialLoad)
32
+
33
+ ctx.resolve()
34
+ })
35
+ }
36
+
37
+ override func show(_ ctx: AMBContext) {
38
+ mAd?.present(fromRootViewController: plugin.viewController, userDidEarnRewardHandler: {
39
+ let reward = self.mAd!.adReward
40
+ self.emit(AMBEvents.adReward, reward)
41
+ self.emit(AMBEvents.rewardedInterstitialReward, reward)
42
+ })
43
+ ctx.resolve()
44
+ }
45
+
46
+ func adDidRecordImpression(_ ad: GADFullScreenPresentingAd) {
47
+ self.emit(AMBEvents.adImpression)
48
+ self.emit(AMBEvents.rewardedInterstitialImpression)
49
+ }
50
+
51
+ func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
52
+ clear()
53
+ self.emit(AMBEvents.adShowFail, error)
54
+ self.emit(AMBEvents.rewardedInterstitialShowFail, error)
55
+ }
56
+
57
+ func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
58
+ self.emit(AMBEvents.adShow)
59
+ self.emit(AMBEvents.rewardedInterstitialShow)
60
+ }
61
+
62
+ func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
63
+ clear()
64
+ self.emit(AMBEvents.adDismiss)
65
+ self.emit(AMBEvents.rewardedInterstitialDismiss)
66
+ }
67
+
68
+ private func clear() {
69
+ mAd?.fullScreenContentDelegate = nil
70
+ mAd = nil
71
+ }
72
+ }
@@ -0,0 +1,26 @@
1
+ import * as cordova from 'cordova'
2
+ import channel from 'cordova/channel'
3
+ import exec from 'cordova/exec'
4
+ import { AdMob } from '.'
5
+ import { MobileAd, NativeActions } from './shared'
6
+
7
+ const admob = new AdMob()
8
+
9
+ function onMessageFromNative(event: any) {
10
+ const { data } = event
11
+ if (data && data.adId) {
12
+ data.ad = MobileAd.getAdById(data.adId)
13
+ }
14
+ cordova.fireDocumentEvent(event.type, data)
15
+ }
16
+
17
+ const feature = 'onAdMobPlusReady'
18
+ channel.createSticky(feature)
19
+ channel.waitForInitialization(feature)
20
+
21
+ channel.onCordovaReady.subscribe(() => {
22
+ exec(onMessageFromNative, console.error, 'AdMob', NativeActions.ready, [])
23
+ channel.initializationComplete(feature)
24
+ })
25
+
26
+ export default admob
package/src/www/api.ts ADDED
@@ -0,0 +1,156 @@
1
+ import { execAsync, NativeActions } from './generated'
2
+
3
+ export { execAsync, AdSizeType, Events, NativeActions } from './generated'
4
+
5
+ /** @internal */
6
+ export type MobileAdOptions = {
7
+ id?: number
8
+ adUnitId: string
9
+ contentUrl?: string
10
+ keywords?: string[]
11
+ npa?: '1'
12
+ }
13
+
14
+ let started = false
15
+ let startPromise: Promise<{ version: string }> | null = null
16
+
17
+ /** @internal */
18
+ export async function start() {
19
+ startPromise = execAsync(NativeActions.start) as Promise<{ version: string }>
20
+ const result = await startPromise
21
+ started = true
22
+ return result
23
+ }
24
+
25
+ /** @internal */
26
+ export class MobileAd<T extends MobileAdOptions = MobileAdOptions> {
27
+ public static readonly type: string = ''
28
+
29
+ private static allAds: { [s: number]: MobileAd } = {}
30
+ private static idCounter = 0
31
+
32
+ public readonly id: number
33
+
34
+ protected readonly opts: T
35
+ private _created = false
36
+ private _init: Promise<any> | null = null
37
+
38
+ constructor(opts: T) {
39
+ this.opts = opts
40
+
41
+ this.id = opts.id ?? MobileAd.nextId()
42
+ MobileAd.allAds[this.id] = this
43
+ }
44
+
45
+ public static getAdById(id: number) {
46
+ return this.allAds[id]
47
+ }
48
+
49
+ private static nextId() {
50
+ const storage = window.localStorage
51
+ const key = 'admob-ad-id-counter'
52
+ const value = storage.getItem(key)
53
+ if (value !== null) {
54
+ MobileAd.idCounter = Number(value)
55
+ }
56
+ MobileAd.idCounter += 1
57
+ storage.setItem(key, `${MobileAd.idCounter}`)
58
+ return MobileAd.idCounter
59
+ }
60
+
61
+ public get adUnitId() {
62
+ return this.opts.adUnitId
63
+ }
64
+
65
+ public on(...args: Parameters<typeof document.addEventListener>): () => void {
66
+ const [eventName, cb, ...rest] = args
67
+ const type = `admob.ad.${eventName.toLowerCase()}`
68
+ const listener = (evt: any) => {
69
+ if (evt.ad === this) {
70
+ cb(evt)
71
+ }
72
+ }
73
+ document.addEventListener(type, listener, ...rest)
74
+
75
+ return () => {
76
+ document.removeEventListener(type, listener, ...rest)
77
+ }
78
+ }
79
+
80
+ protected async isLoaded() {
81
+ await this.init()
82
+ return execAsync(NativeActions.adIsLoaded, [
83
+ { id: this.id },
84
+ ]) as Promise<boolean>
85
+ }
86
+
87
+ protected async load() {
88
+ await this.init()
89
+ // TODO read `opts` in native code?
90
+ await execAsync(NativeActions.adLoad, [{ ...this.opts, id: this.id }])
91
+ }
92
+
93
+ protected async show(opts?: Record<string, any>) {
94
+ await this.init()
95
+ return execAsync(NativeActions.adShow, [{ ...opts, id: this.id }])
96
+ }
97
+
98
+ protected async hide() {
99
+ return execAsync(NativeActions.adHide, [{ id: this.id }])
100
+ }
101
+
102
+ protected async init() {
103
+ if (this._created) return
104
+
105
+ if (!started) {
106
+ if (startPromise === null) start()
107
+ await startPromise
108
+ }
109
+
110
+ if (this._init === null) {
111
+ const cls =
112
+ (this.constructor as unknown as { cls?: string }).cls ??
113
+ this.constructor.name
114
+
115
+ this._init = execAsync(NativeActions.adCreate, [
116
+ { ...this.opts, id: this.id, cls },
117
+ ])
118
+ }
119
+
120
+ await this._init
121
+ this._created = true
122
+ }
123
+ }
124
+
125
+ export enum MaxAdContentRating {
126
+ G = 'G',
127
+ MA = 'MA',
128
+ PG = 'PG',
129
+ T = 'T',
130
+ UNSPECIFIED = '',
131
+ }
132
+
133
+ export type RequestConfig = {
134
+ maxAdContentRating?: MaxAdContentRating
135
+ sameAppKey?: boolean,
136
+ tagForChildDirectedTreatment?: boolean | null
137
+ tagForUnderAgeOfConsent?: boolean | null
138
+ testDeviceIds?: string[]
139
+ }
140
+
141
+ export const enum Platforms {
142
+ android = 'android',
143
+ ios = 'ios',
144
+ }
145
+
146
+ export enum TrackingAuthorizationStatus {
147
+ notDetermined = 0,
148
+ restricted = 1,
149
+ denied = 2,
150
+ authorized = 3,
151
+ }
152
+
153
+ export type AdMobConfig = {
154
+ appMuted?: boolean
155
+ appVolume?: number
156
+ } & RequestConfig
@@ -0,0 +1,27 @@
1
+ import { MobileAd, MobileAdOptions } from './shared'
2
+
3
+ enum AppOpenAdOrientation {
4
+ Portrait = 1,
5
+ PortraitUpsideDown = 2,
6
+ LandscapeRight = 3,
7
+ LandscapeLeft = 4,
8
+ }
9
+
10
+ export default class AppOpenAd extends MobileAd<
11
+ MobileAdOptions & { orientation: AppOpenAdOrientation }
12
+ > {
13
+ static cls = 'AppOpenAd'
14
+ static readonly Orientation = AppOpenAdOrientation
15
+
16
+ public isLoaded() {
17
+ return super.isLoaded()
18
+ }
19
+
20
+ public load() {
21
+ return super.load()
22
+ }
23
+
24
+ async show() {
25
+ return super.show() as Promise<boolean>
26
+ }
27
+ }
@@ -0,0 +1,102 @@
1
+ import {
2
+ AdSizeType,
3
+ execAsync,
4
+ MobileAd,
5
+ MobileAdOptions,
6
+ NativeActions,
7
+ Platforms,
8
+ } from './shared'
9
+
10
+ type Position = 'top' | 'bottom'
11
+
12
+ const colorToRGBA = (function () {
13
+ const canvas = document.createElement('canvas')
14
+ canvas.width = canvas.height = 1
15
+ const ctx = canvas.getContext('2d')
16
+ if (!ctx) return () => undefined
17
+
18
+ return function (
19
+ col: string,
20
+ ): { r: number; g: number; b: number; a: number } | undefined {
21
+ ctx.clearRect(0, 0, 1, 1)
22
+ // In order to detect invalid values,
23
+ // we can't rely on col being in the same format as what fillStyle is computed as,
24
+ // but we can ask it to implicitly compute a normalized value twice and compare.
25
+ ctx.fillStyle = '#000'
26
+ ctx.fillStyle = col
27
+ const computed = ctx.fillStyle
28
+ ctx.fillStyle = '#fff'
29
+ ctx.fillStyle = col
30
+ if (computed !== ctx.fillStyle) {
31
+ return // invalid color
32
+ }
33
+ ctx.fillRect(0, 0, 1, 1)
34
+ const { data } = ctx.getImageData(0, 0, 1, 1)
35
+ return { r: data[0], g: data[1], b: data[2], a: data[3] }
36
+ }
37
+ })()
38
+
39
+ type BannerSize =
40
+ | AdSizeType
41
+ | { width: number; height: number }
42
+ | {
43
+ adaptive: 'anchored'
44
+ orientation?: 'portrait' | 'landscape'
45
+ width?: number
46
+ }
47
+ | {
48
+ adaptive: 'inline'
49
+ maxHeight: number
50
+ width?: number
51
+ }
52
+
53
+ export interface BannerAdOptions extends MobileAdOptions {
54
+ position?: Position
55
+ size?: BannerSize
56
+ offset?: number
57
+ }
58
+
59
+ export default class BannerAd extends MobileAd<BannerAdOptions> {
60
+ static cls = 'BannerAd'
61
+
62
+ private _loaded = false
63
+
64
+ constructor(opts: BannerAdOptions) {
65
+ super({
66
+ position: 'bottom',
67
+ size: AdSizeType.SMART_BANNER,
68
+ ...opts,
69
+ })
70
+ }
71
+
72
+ public static config(opts: {
73
+ backgroundColor?: string
74
+ marginTop?: number
75
+ marginBottom?: number
76
+ }) {
77
+ if (cordova.platformId === Platforms.ios) {
78
+ const { backgroundColor: bgColor } = opts
79
+ return execAsync(NativeActions.bannerConfig, [
80
+ { ...opts, backgroundColor: bgColor ? colorToRGBA(bgColor) : bgColor },
81
+ ])
82
+ }
83
+ return false
84
+ }
85
+
86
+ public async load() {
87
+ await super.load()
88
+ this._loaded = true
89
+ }
90
+
91
+ public async show() {
92
+ if (!this._loaded) {
93
+ await this.load()
94
+ }
95
+
96
+ return super.show()
97
+ }
98
+
99
+ public async hide() {
100
+ return super.hide()
101
+ }
102
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="cordova-plus/types" />
2
+
3
+ declare module 'cordova/channel'
4
+
5
+ declare module 'cordova/exec'
6
+
7
+ interface Cordova {
8
+ fireDocumentEvent(eventName: string, data: any)
9
+ }
@@ -0,0 +1,125 @@
1
+ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ export enum NativeActions {
3
+ adCreate = 'adCreate',
4
+ adHide = 'adHide',
5
+ adIsLoaded = 'adIsLoaded',
6
+ adLoad = 'adLoad',
7
+ adShow = 'adShow',
8
+ bannerConfig = 'bannerConfig',
9
+ bannerHide = 'bannerHide',
10
+ bannerLoad = 'bannerLoad',
11
+ bannerShow = 'bannerShow',
12
+ configRequest = 'configRequest',
13
+ configure = 'configure',
14
+ interstitialIsLoaded = 'interstitialIsLoaded',
15
+ interstitialLoad = 'interstitialLoad',
16
+ interstitialShow = 'interstitialShow',
17
+ ready = 'ready',
18
+ requestTrackingAuthorization = 'requestTrackingAuthorization',
19
+ rewardedInterstitialIsLoaded = 'rewardedInterstitialIsLoaded',
20
+ rewardedInterstitialLoad = 'rewardedInterstitialLoad',
21
+ rewardedInterstitialShow = 'rewardedInterstitialShow',
22
+ rewardedIsLoaded = 'rewardedIsLoaded',
23
+ rewardedLoad = 'rewardedLoad',
24
+ rewardedShow = 'rewardedShow',
25
+ setAppMuted = 'setAppMuted',
26
+ setAppVolume = 'setAppVolume',
27
+ start = 'start',
28
+ }
29
+
30
+ export enum Events {
31
+ adClick = 'admob.ad.click',
32
+ adDismiss = 'admob.ad.dismiss',
33
+ adImpression = 'admob.ad.impression',
34
+ adLoad = 'admob.ad.load',
35
+ adLoadFail = 'admob.ad.loadfail',
36
+ adReward = 'admob.ad.reward',
37
+ adShow = 'admob.ad.show',
38
+ adShowFail = 'admob.ad.showfail',
39
+ bannerClick = 'admob.banner.click',
40
+ bannerClose = 'admob.banner.close',
41
+ bannerImpression = 'admob.banner.impression',
42
+ bannerLoad = 'admob.banner.load',
43
+ bannerLoadFail = 'admob.banner.loadfail',
44
+ bannerOpen = 'admob.banner.open',
45
+ bannerSize = 'admob.banner.size',
46
+ bannerSizeChange = 'admob.banner.sizechange',
47
+ interstitialDismiss = 'admob.interstitial.dismiss',
48
+ interstitialImpression = 'admob.interstitial.impression',
49
+ interstitialLoad = 'admob.interstitial.load',
50
+ interstitialLoadFail = 'admob.interstitial.loadfail',
51
+ interstitialShow = 'admob.interstitial.show',
52
+ interstitialShowFail = 'admob.interstitial.showfail',
53
+ ready = 'admob.ready',
54
+ rewardedDismiss = 'admob.rewarded.dismiss',
55
+ rewardedImpression = 'admob.rewarded.impression',
56
+ rewardedInterstitialDismiss = 'admob.rewardedi.dismiss',
57
+ rewardedInterstitialImpression = 'admob.rewardedi.impression',
58
+ rewardedInterstitialLoad = 'admob.rewardedi.load',
59
+ rewardedInterstitialLoadFail = 'admob.rewardedi.loadfail',
60
+ rewardedInterstitialReward = 'admob.rewardedi.reward',
61
+ rewardedInterstitialShow = 'admob.rewardedi.show',
62
+ rewardedInterstitialShowFail = 'admob.rewardedi.showfail',
63
+ rewardedLoad = 'admob.rewarded.load',
64
+ rewardedLoadFail = 'admob.rewarded.loadfail',
65
+ rewardedReward = 'admob.rewarded.reward',
66
+ rewardedShow = 'admob.rewarded.show',
67
+ rewardedShowFail = 'admob.rewarded.showfail',
68
+ }
69
+
70
+ export enum AdSizeType {
71
+ BANNER,
72
+ LARGE_BANNER,
73
+ MEDIUM_RECTANGLE,
74
+ FULL_BANNER,
75
+ LEADERBOARD,
76
+ SMART_BANNER,
77
+ }
78
+
79
+ export const execAsync = (action: NativeActions, args?: any[]) => {
80
+ return new Promise((resolve, reject) => {
81
+ cordova.exec(resolve, reject, 'AdMob', action, args)
82
+ })
83
+ }
84
+
85
+ export function waitEvent(
86
+ successEvent: string,
87
+ failEvent = '',
88
+ ): Promise<CustomEvent> {
89
+ return new Promise((resolve, reject) => {
90
+ document.addEventListener(
91
+ successEvent as any,
92
+ (event: CustomEvent) => {
93
+ resolve(event)
94
+ },
95
+ false,
96
+ )
97
+
98
+ if (failEvent) {
99
+ document.addEventListener(
100
+ failEvent as any,
101
+ (failedEvent: CustomEvent) => {
102
+ reject(failedEvent)
103
+ },
104
+ false,
105
+ )
106
+ }
107
+ })
108
+ }
109
+
110
+ export const initPlugin = () => {
111
+ document.addEventListener(
112
+ 'deviceready',
113
+ () => {
114
+ cordova.exec(
115
+ (event) => {
116
+ cordova.fireDocumentEvent(event.type, event.data)
117
+ },
118
+ console.error,
119
+ 'AdMob',
120
+ NativeActions.ready,
121
+ )
122
+ },
123
+ false,
124
+ )
125
+ }
@@ -0,0 +1,88 @@
1
+ import AppOpenAd from './app-open'
2
+ import BannerAd, { BannerAdOptions } from './banner'
3
+ import InterstitialAd from './interstitial'
4
+ import NativeAd, { NativeAdOptions } from './native'
5
+ import RewardedAd, {
6
+ RewardedAdOptions,
7
+ ServerSideVerificationOptions,
8
+ } from './rewarded'
9
+ import RewardedInterstitialAd, {
10
+ RewardedInterstitialAdOptions,
11
+ } from './rewarded-interstitial'
12
+ import {
13
+ AdMobConfig,
14
+ Events,
15
+ execAsync,
16
+ NativeActions,
17
+ Platforms,
18
+ RequestConfig,
19
+ start,
20
+ TrackingAuthorizationStatus,
21
+ } from './shared'
22
+
23
+ export * from './api'
24
+ export {
25
+ AppOpenAd,
26
+ BannerAd,
27
+ BannerAdOptions,
28
+ InterstitialAd,
29
+ NativeAd,
30
+ NativeAdOptions,
31
+ RewardedAd,
32
+ RewardedAdOptions,
33
+ RewardedInterstitialAd,
34
+ RewardedInterstitialAdOptions,
35
+ ServerSideVerificationOptions,
36
+ }
37
+
38
+ export class AdMob {
39
+ public readonly AppOpenAd = AppOpenAd
40
+ public readonly BannerAd = BannerAd
41
+ public readonly InterstitialAd = InterstitialAd
42
+ public readonly NativeAd = NativeAd
43
+ public readonly RewardedAd = RewardedAd
44
+ public readonly RewardedInterstitialAd = RewardedInterstitialAd
45
+
46
+ public readonly Events = Events
47
+ public readonly TrackingAuthorizationStatus = TrackingAuthorizationStatus
48
+
49
+ configure(config: AdMobConfig) {
50
+ return execAsync(NativeActions.configure, [config])
51
+ }
52
+
53
+ public configRequest(requestConfig: RequestConfig) {
54
+ return execAsync(NativeActions.configRequest, [requestConfig])
55
+ }
56
+
57
+ public setAppMuted(value: boolean) {
58
+ return execAsync(NativeActions.setAppMuted, [value])
59
+ }
60
+
61
+ public setAppVolume(value: number) {
62
+ return execAsync(NativeActions.setAppVolume, [value])
63
+ }
64
+
65
+ public start() {
66
+ return start()
67
+ }
68
+
69
+ public async requestTrackingAuthorization(): Promise<
70
+ TrackingAuthorizationStatus | false
71
+ > {
72
+ if (cordova.platformId === Platforms.ios) {
73
+ const n = await execAsync(NativeActions.requestTrackingAuthorization)
74
+ if (n !== false) {
75
+ return TrackingAuthorizationStatus[
76
+ TrackingAuthorizationStatus[n as number]
77
+ ]
78
+ }
79
+ }
80
+ return false
81
+ }
82
+ }
83
+
84
+ declare global {
85
+ const admob: AdMob
86
+ }
87
+
88
+ export default AdMob
@@ -0,0 +1,17 @@
1
+ import { MobileAd, MobileAdOptions } from './shared'
2
+
3
+ export default class InterstitialAd extends MobileAd<MobileAdOptions> {
4
+ static cls = 'InterstitialAd'
5
+
6
+ public isLoaded() {
7
+ return super.isLoaded()
8
+ }
9
+
10
+ public load() {
11
+ return super.load()
12
+ }
13
+
14
+ public show() {
15
+ return super.show()
16
+ }
17
+ }