-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hce): add hce plugin wrapper (#2534)
feat(hce): add hce plugin wrapper
- Loading branch information
1 parent
03e6afb
commit 8460e68
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; | ||
|
||
/** | ||
* @name hce | ||
* @description | ||
* HCE Cordova Wrapper | ||
* | ||
* @usage | ||
* ```typescript | ||
* import { hce } from '@ionic-native/hce'; | ||
* | ||
* | ||
* constructor(private hce: hce) { } | ||
* | ||
* ... | ||
* | ||
* function onCommand(command){ | ||
* var commandAsBytes = new Uint8Array(command); | ||
* var commandAsString = hce.util.byteArrayToHexString(commandAsBytes); | ||
* | ||
* // do something with the command | ||
* | ||
* // send the response | ||
* hce.sendReponse(commandResponse); | ||
* } | ||
* this.hce.registerCommandCallback().then(onCommand); | ||
* | ||
* ``` | ||
*/ | ||
@Plugin({ | ||
pluginName: 'hce', | ||
plugin: 'cordova-plugin-hce', | ||
pluginRef: 'hce', | ||
repo: 'https://github.com/don/cordova-plugin-hce', | ||
install: '', | ||
installVariables: ['AID_FILTER'], | ||
platforms: ['Android'] | ||
}) | ||
@Injectable() | ||
export class HCE extends IonicNativePlugin { | ||
|
||
/** | ||
* Registers command receiver. | ||
* @param onCommand {HCECommandEvent} The event handler. | ||
* @param fail {Function} Error event handler. | ||
* | ||
*/ | ||
@Cordova() | ||
registerCommandCallback(onCommand: HCECommandEvent, fail?: Function): void { | ||
return; // We add return; here to avoid any IDE / Compiler errors | ||
} | ||
/** | ||
* Registers Deactivated receiver. | ||
* @param ok {HCEDeactivatedEvent} Success event handler. | ||
* @param fail {Function} Error event handler. | ||
* | ||
*/ | ||
@Cordova() | ||
registerDeactivatedCallback(ok: HCEDeactivatedEvent, fail?: Function): void { | ||
return; // We add return; here to avoid any IDE / Compiler errors | ||
} | ||
|
||
|
||
/** | ||
* Sends response APDU. | ||
* @param response {Uint8Array} Response | ||
* @param success {string} Success Callback. | ||
* @param success {string} Failure Callback. | ||
* | ||
*/ | ||
@Cordova() | ||
sendResponse(response: Uint8Array, success?: Function, failure?: Function): void { | ||
return; // We add return; here to avoid any IDE / Compiler errors | ||
} | ||
} | ||
|
||
export interface HCECommandEvent { (command: Uint8Array): void; } | ||
export interface HCEDeactivatedEvent { (command: number): void; } |