|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; |
| 3 | +import { Observable } from 'rxjs/Observable'; |
| 4 | +import { fromEvent } from 'rxjs/observable/fromEvent'; |
| 5 | + |
| 6 | +export type AdUnitIDOption = string | { |
| 7 | + android: string; |
| 8 | + ios: string; |
| 9 | +}; |
| 10 | + |
| 11 | +/** |
| 12 | + * @name AdMob Free |
| 13 | + * @description |
| 14 | + * AdMob Plus is the successor of cordova-plugin-admob-free, which provides a cleaner API and build with modern tools. |
| 15 | + */ |
| 16 | +@Plugin({ |
| 17 | + plugin: 'cordova-admob-plus', |
| 18 | + pluginName: 'AdMob', |
| 19 | + pluginRef: 'admob.banner', |
| 20 | +}) |
| 21 | +export class Banner { |
| 22 | + @Cordova({ otherPromise: true }) |
| 23 | + hide(): Promise<any> { |
| 24 | + return Promise.resolve(); |
| 25 | + } |
| 26 | + |
| 27 | + @Cordova({ otherPromise: true }) |
| 28 | + show(opts: { id?: AdUnitIDOption }): Promise<any> { |
| 29 | + return Promise.resolve(); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +@Plugin({ |
| 34 | + plugin: 'cordova-admob-plus', |
| 35 | + pluginName: 'AdMob', |
| 36 | + pluginRef: 'admob.interstitial', |
| 37 | +}) |
| 38 | +export class Interstitial { |
| 39 | + @Cordova({ otherPromise: true }) |
| 40 | + load(opts: { id?: AdUnitIDOption }): Promise<any> { |
| 41 | + return Promise.resolve(); |
| 42 | + } |
| 43 | + |
| 44 | + @Cordova({ otherPromise: true }) |
| 45 | + show(): Promise<any> { |
| 46 | + return Promise.resolve(); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +@Plugin({ |
| 51 | + plugin: 'cordova-admob-plus', |
| 52 | + pluginName: 'AdMob', |
| 53 | + pluginRef: 'admob.rewardVideo', |
| 54 | +}) |
| 55 | +export class RewardVideo { |
| 56 | + @Cordova({ otherPromise: true }) |
| 57 | + load(opts: { id?: AdUnitIDOption }): Promise<any> { |
| 58 | + return Promise.resolve(); |
| 59 | + } |
| 60 | + |
| 61 | + @Cordova({ otherPromise: true }) |
| 62 | + show(): Promise<any> { |
| 63 | + return Promise.resolve(); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +@Plugin({ |
| 68 | + platforms: ['Android', 'iOS'], |
| 69 | + plugin: 'cordova-admob-plus', |
| 70 | + pluginName: 'AdMob', |
| 71 | + pluginRef: 'admob', |
| 72 | + repo: 'https://github.com/admob-plus/admob-plus', |
| 73 | +}) |
| 74 | +@Injectable() |
| 75 | +export class AdMob extends IonicNativePlugin { |
| 76 | + banner = new Banner(); |
| 77 | + interstitial = new Interstitial(); |
| 78 | + rewardVideo = new RewardVideo(); |
| 79 | + |
| 80 | + @Cordova({ otherPromise: true }) |
| 81 | + setAppMuted(value: boolean): Promise<any> { |
| 82 | + return Promise.resolve(); |
| 83 | + } |
| 84 | + |
| 85 | + @Cordova({ otherPromise: true }) |
| 86 | + setAppVolume(value: number): Promise<any> { |
| 87 | + return Promise.resolve(); |
| 88 | + } |
| 89 | + |
| 90 | + on(event: string): Observable<any> { |
| 91 | + return fromEvent(document, event); |
| 92 | + } |
| 93 | +} |
0 commit comments