Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Redirect of content-url possible? #103

Closed
chauthai opened this issue Feb 9, 2016 · 3 comments
Closed

Redirect of content-url possible? #103

chauthai opened this issue Feb 9, 2016 · 3 comments

Comments

@chauthai
Copy link
Contributor

chauthai commented Feb 9, 2016

Is it possible to have a redirect behind a content-url? e.g. a user is from a specific country and gets only updates for his region.

@nikDemyankov
Copy link
Member

No, I don't think it will work with redirects. But you can try to control that from the JS side.

  1. Detect user's country.
  2. Set config-file from JS side by using chcp.configure() method.
  3. When options are set - perform update check.

Something like this:

var app = {

  // Application Constructor
  initialize: function() {
    this.bindEvents();
  },

  // Bind any events that are required.
  // Usually you should subscribe on 'deviceready' event to know, when you can start calling cordova modules
  bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
  },

  // deviceready Event Handler
  onDeviceReady: function() {
    // change plugin options
    app.configurePlugin();
  },

  getConfigUrlByCountry: function() {
    // somehow detect users country and return proper content-url
  },

  configurePlugin: function() {
    var url = app.getConfigUrlByCountry();
    var options = {
      'config-file': url
    };

    chcp.configure(options, configureCallback);
  },

  configureCallback: function(error) {
    if (error) {
      console.log('Error during the configuration process');
      console.log(error.description);
    } else {
      console.log('Plugin configured successfully');
      app.checkForUpdate();
    }
  },

  checkForUpdate: function() {
    chcp.fetchUpdate(this.fetchUpdateCallback);
  },

  fetchUpdateCallback: function(error, data) {
    if (error) {
      console.log('Failed to load the update with error code: ' + error.code);
      console.log(error.description);
      return;
    }
    console.log('Update is loaded, running the installation');

    chcp.installUpdate(this.installationCallback);
  },

  installationCallback: function(error) {
    if (error) {
      console.log('Failed to install the update with error code: ' + error.code);
      console.log(error.description);
    } else {
      console.log('Update installed!');
    }
  }
};

app.initialize();

@chauthai
Copy link
Contributor Author

chauthai commented Feb 9, 2016

Thanks for the fast answer and the code example.

@nordnet-deprecation-bot
Copy link
Contributor

👋 Hi! Thank you for your interest in this repo.

😢 We are not using nordnet/cordova-hot-code-push anymore, and we lack the manpower and the experience needed to maintain it. We are aware of the inconveniece that this may cause you. Feel free to use it as is, or create your own fork.

🔒 This will now be closed & locked.

ℹ️ Please see #371 for more information.

@nordnet nordnet locked and limited conversation to collaborators Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants