Skip to content

mathieudutour/cordova-plugin-hotpushes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#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 cordova-plugin-hotpushes

Supported Platforms

  • Android
  • iOS
  • WP8

Examples

API

new HotPush(options)

Parameter Description
options.src String URL to hot push endpoint
options.versionFileName 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 HotPush.HOTPUSH_TYPE.REPLACE is the default behaviour that completely removes existing content then copies new content from a zip file.
The type HotPush.HOTPUSH_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 === Hotpush.HOTPUSH_TYPE.REPLACE) URL of the zip containing the files to hot push.
options.documentsPath Object (Optional) Path to the Documents folder (useful for WKWebView)
options.checkType String (Optional) Set to Hotpush.HOTPUSH_CHECK_TYPE.VERSION if you want to use the version number in your version.json instead of timestamp
options.debug Boolean (Optional) Print debug information in the console

Returns

  • Instance of HotPush.

Example

var hotpushes = new HotPush({
  src: 'http://myserver/hot/',
  versionFileName: 'version.json',
  type: HotPush.HOTPUSH_TYPE.REPLACE,
  archiveURL: 'http://myserver/hot/assets.zip'
});

hotpushes.loadWaitingLocalFiles()

Load the local files at position -1 (see version.json). Return a promise.

Parameter Description
no parameters

Example

hotpushes.loadWaitingLocalFiles()
  .then((result) => console.log('waiting'))
  .catch((err) => console.log(err));

hotpushes.loadLocalFiles()

Load the local files at position >= 0. Return a promise.

Parameter Description
no parameters

Example

hotpushes.loadLocalFiles()
  .then((result) => console.log('all good'))
  .catch((err) => console.log(err));

hotpushes.check()

Check if there is a new version available on the server. Return a promise which resolve with either HotPush.UPDATE.FOUND or HotPush.UPDATE.NOT_FOUND.

Parameter Description
no parameters

Example

hotpushes.check()
  .then((result) => {
    if (result === HotPush.UPDATE.FOUND) {
      // do something. Maybe hotpushes.update() or show a popup ?
    }
  })
  .catch((err) => console.log(err));

hotpushes.update()

Download the files on the server. Return a promise.

Parameter Description
no parameters

Example

hotpushes.update()
  .then(() => {
    location.reload();
  })
  .catch((err) => console.log(err));

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) {
    // data.progress
    // data.status
});

hotpushes.cancel()

Cancels the content sync operation.

hotpushes.lastCheck

Timestamp of the last check

hotpushes.lastUpdate

Timestamp of the last update

HotPush.PROGRESS_STATE

An enumeration that describes the current progress state.

Integer Description
0 STOPPED
1 DOWNLOADING
2 EXTRACTING
3 COMPLETE

HotPush.HOTPUSH_TYPE

An enumeration that describes the type of hotpush to perform.

String Description
merge MERGE
replace REPLACE

HotPush.HOTPUSH_CHECK_TYPE

An enumeration that describes the field to look at in the version.json file.

String Description
version VERSION
timestamp TIMESTAMP

HotPush.UPDATE

String Description
NOT_FOUND NOT_FOUND
FOUND FOUND

About

Simple hot code push for ios and android on Cordova

Resources

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •