I use PouchDB to store data offline and synchronize with a remote CouchDB database when the application goes online. It works well if the application starts on the network: PouchDB fires an event pausewhen the connection is interrupted and continues when the connection returns. Here is a sample code:
localDB.replicate.to(remoteDB, {
live: true,
retry: true
}).on('paused', function (info) {
}).on('change', function (change) {
}).on('active', function (info) {
}).on('error', function (err) {
console.log(err);
})
But when the application is launched offline, an error ( Failed to load resource: net::ERR_ADDRESS_UNREACHABLE)
access to the remote database is not possible, and PouchDB fires an event error( "Database encountered an unknown error", status 500). Even if the connection returns, replication will not work.
:
, (, pause , )?
UPDATE:
nlawson ! , :
function retryReplication() {
var remoteDB = new PouchDB('http://129.199.80.62:5984/remotedb');
localDB.replicate.to(remoteDB, {
live: true,
}).on('paused', function (info) {
}).on('change', function (change) {
}).on('active', function (info) {
}).on('error', function (err) {
setTimeout(retryReplication, 5000);
});
};