Introduction
A Cordova plug-in is a bit of add-on code that provides a JavaScript interface to native components. It allows your app to use native device capabilities beyond what is available to pure web apps. See the existing Cordova plugins.
To use the Risk Management SDK in an Ionic project, we will first need to create a Cordova plug-in, which wraps the SDK.
Creating the file structure
To create a Cordova plug-in, create the following file structure in any location in your file system:
plugin.xml- main configuration file for the plug-inpackage.json- Node.js project description and dependenciessrc- source code directory for the native Android and iOS platformswww- javascript API directory
Creating the plug-in summary
Edit package.json file with the plug-in summary.
{
"version": "0.0.1",
"name": "gahplugin",
"cordova_name": "GahPlugin",
"description": "GAH plugin",
"license": "Copyright (c) THALES DEVELOPMENT",
"author": {
"name": "Author",
"email": "author@email.com"
},
"keywords": [
"GAH",
"plugin"
]
}
Creating the JavaScript API
The JavaScript API available for the developer integrating the plug-in is available in www/GahPlugin.js.
Create this file and add all the APIs which we will need in our application to this file.
var exec = require('cordova/exec');
var PLUGIN_NAME = 'GahPlugin';
function GahPlugin() {
}
/**
* Initializes GAH SDK.
*
* @param gahUrl GAH signal collector backend URL.
* @param tmxOrgId Thread matrix organization id.
* @param tmxFpServerUrl Thread matrix server URL.
* @param callback Success callback.
* @param errorCallback Error callback.
*/
GahPlugin.prototype.initialize = function (gahUrl, tmxOrgId, tmxFpServerUrl, callback, errorCallback) {
exec(callback, errorCallback, PLUGIN_NAME, 'initialize', [gahUrl, tmxOrgId, tmxFpServerUrl]);
};
/**
* Retrieves the visit id.
*
* @param callback Success callback.
* @param errorCallback Error callback.
*/
GahPlugin.prototype.getVisiId = function (callback, errorCallback) {
exec(callback, errorCallback, PLUGIN_NAME, 'visitId', []);
};
/**
* Starts prefetch of data, caches signals. Call on applicaiton start, after GAH has been initialized
*/
GahPlugin.prototype.startPrefetch = function (callback, errorCallback) {
exec(callback, errorCallback, PLUGIN_NAME, 'startPrefetch', []);
};
/**
* Stops prefetch of data. Call before application end, or when GAH will not be further used.
*/
GahPlugin.prototype.stopPrefetch = function (callback, errorCallback) {
exec(callback, errorCallback, PLUGIN_NAME, 'stopPrefetch', []);
};
/**
* Clears the transaction resources. Call after each transaction (login, transfer funds etc.).
*/
GahPlugin.prototype.clearTransaction = function (callback, errorCallback) {
exec(callback, errorCallback, PLUGIN_NAME, 'clearTransaction', []);
};
/**
* Checks if signal collection is completed. Needs to be called before {@code getVisiId},
* to check if all signals are collected
*/
GahPlugin.prototype.isSignalCollectionCompleted = function (callback, errorCallback) {
exec(callback, errorCallback, PLUGIN_NAME, 'isSignalCollectionCompleted', []);
};
/**
* Sets the transaction as critical(high value trasfer etc.).
*/
GahPlugin.prototype.setTransactionAsCritical = function (callback, errorCallback) {
exec(callback, errorCallback, PLUGIN_NAME, 'setTransactionAsCritical', []);
};
var gahPlugin = new GahPlugin();
module.exports = gahPlugin;