#cordova-plugin-hotpushes
Download and cache remotely hosted content.
This plugin is a work in progress and it is not production ready. PR welcome.
Installation
cordova plugin add https://github.com/mathieudutour/cordova-plugin-hotpushes
Supported Platforms
Examples
API
HotPush.sync(options)
Parameter | Description |
---|
options.src | String URL to hot push endpoint |
options.versionJSONPFileName | String Name of the jsonp file containing the version information. |
options.versionJSONFileName | String Name of the json file containing the version information |
options.type | String (Optional) Defines the hot push strategy applied to the content. The type replace is the default behaviour that completely removes existing content then copies new content from a zip file. The type merge will download and replace only content which has changed. |
options.headers | Object (Optional) Set of headers to use when requesting the remote content from options.src . |
options.archiveURL | String (Mandatory if options.type === 'replace' ) URL of the zip containing the files to hot push. |
options.documentsPath | Object (Optional) Path to the Documents folder (useful for WKWebView) |
Returns
Example
var hotpushes = HotPush.sync({
src: 'http://myserver/hot/',
versionJSONPFileName: 'version.jsonp',
versionJSONFileName: 'version.json',
type: 'replace',
archiveURL: 'http://myserver/hot/assets.zip'
});
HotPush.check()
Load the local files and check if there is a new version available on the server.
Parameter | Description |
---|
no parameters | |
HotPush.update()
Download the files on the server.
Parameter | Description |
---|
no parameters | |
hotpushes.on(event, callback)
Parameter | Description |
---|
event | String Name of the event to listen to. See below for all the event names. |
callback | Function is called when the event is triggered. |
hotpushes.on('updateFound', callback)
The event updateFound
will be triggered when a new update is found on the server.
Callback Parameter | Description |
---|
no parameters | |
Example
hotpushes.on('updateFound', function() {
hotpushes.update();
});
hotpushes.on('noUpdateFound', callback)
The event noUpdateFound
will be triggered when no new update is found on the server.
Callback Parameter | Description |
---|
no parameters | |
Example
hotpushes.on('noUpdateFound', function() {
alert('All good!');
});
hotpushes.on('progress', callback)
The event progress
will be triggered on each update as the native platform downloads and caches the content.
Callback Parameter | Description |
---|
data.progress | Integer Progress percentage between 0 - 100 . The progress includes all actions required to cache the remote content locally. This is different on each platform, but often includes requesting, downloading, and extracting the cached content along with any system cleanup tasks. |
data.status | Integer Enumeration of PROGRESS_STATE to describe the current progress state. |
Example
hotpushes.on('progress', function(data) {
});
hotpushes.on('updateComplete', callback)
The event updateComplete
will be triggered when the content has been successfully cached onto the device.
Callback Parameter | Description |
---|
no parameters | |
Example
hotpushes.on('updateComplete', function() {
location.reload();
});
hotpushes.on('error', callback)
The event error
will trigger when an internal error occurs and the cache is aborted.
Callback Parameter | Description |
---|
e | Error Standard JavaScript error object that describes the error. |
Example
hotpushes.on('error', function(e) {
});
hotpushes.on('cancel', callback)
The event cancel
will trigger when hotpushes.cancel
is called.
Callback Parameter | Description |
---|
no parameters | |
Example
hotpushes.on('cancel', function() {
});
hotpushes.cancel()
Cancels the content sync operation and triggers the cancel callback.
HotPush.PROGRESS_STATE
An enumeration that describes the current progress state.
Integer | Description |
---|
0 | STOPPED |
1 | DOWNLOADING |
2 | EXTRACTING |
3 | COMPLETE |