|
| 1 | + |
| 2 | +import { Injectable } from '@angular/core'; |
| 3 | +import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; |
| 4 | + |
| 5 | +/** |
| 6 | + * @name hce |
| 7 | + * @description |
| 8 | + * HCE Cordova Wrapper |
| 9 | + * |
| 10 | + * @usage |
| 11 | + * ```typescript |
| 12 | + * import { hce } from '@ionic-native/hce'; |
| 13 | + * |
| 14 | + * |
| 15 | + * constructor(private hce: hce) { } |
| 16 | + * |
| 17 | + * ... |
| 18 | + * |
| 19 | + * function onCommand(command){ |
| 20 | + * var commandAsBytes = new Uint8Array(command); |
| 21 | + * var commandAsString = hce.util.byteArrayToHexString(commandAsBytes); |
| 22 | + * |
| 23 | + * // do something with the command |
| 24 | + * |
| 25 | + * // send the response |
| 26 | + * hce.sendReponse(commandResponse); |
| 27 | + * } |
| 28 | + * this.hce.registerCommandCallback().then(onCommand); |
| 29 | + * |
| 30 | + * ``` |
| 31 | + */ |
| 32 | +@Plugin({ |
| 33 | + pluginName: 'hce', |
| 34 | + plugin: 'cordova-plugin-hce', |
| 35 | + pluginRef: 'hce', |
| 36 | + repo: 'https://github.com/don/cordova-plugin-hce', |
| 37 | + install: '', |
| 38 | + installVariables: ['AID_FILTER'], |
| 39 | + platforms: ['Android'] |
| 40 | +}) |
| 41 | +@Injectable() |
| 42 | +export class HCE extends IonicNativePlugin { |
| 43 | + |
| 44 | + /** |
| 45 | + * Registers command receiver. |
| 46 | + * @param onCommand {HCECommandEvent} The event handler. |
| 47 | + * @param fail {Function} Error event handler. |
| 48 | + * |
| 49 | + */ |
| 50 | + @Cordova() |
| 51 | + registerCommandCallback(onCommand: HCECommandEvent, fail?: Function): void { |
| 52 | + return; // We add return; here to avoid any IDE / Compiler errors |
| 53 | + } |
| 54 | + /** |
| 55 | + * Registers Deactivated receiver. |
| 56 | + * @param ok {HCEDeactivatedEvent} Success event handler. |
| 57 | + * @param fail {Function} Error event handler. |
| 58 | + * |
| 59 | + */ |
| 60 | + @Cordova() |
| 61 | + registerDeactivatedCallback(ok: HCEDeactivatedEvent, fail?: Function): void { |
| 62 | + return; // We add return; here to avoid any IDE / Compiler errors |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + /** |
| 67 | + * Sends response APDU. |
| 68 | + * @param response {Uint8Array} Response |
| 69 | + * @param success {string} Success Callback. |
| 70 | + * @param success {string} Failure Callback. |
| 71 | + * |
| 72 | + */ |
| 73 | + @Cordova() |
| 74 | + sendResponse(response: Uint8Array, success?: Function, failure?: Function): void { |
| 75 | + return; // We add return; here to avoid any IDE / Compiler errors |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +export interface HCECommandEvent { (command: Uint8Array): void; } |
| 80 | +export interface HCEDeactivatedEvent { (command: number): void; } |
0 commit comments