The ThaliReplicationManager
class handles database replication between devices, using PouchDB and the Thali Cordova bridge ThaliEmitter
class. This class is meant solely for the purpose of demonstrating Thali Story 0 and will be dramatically enhanced in the future.
This is the basic usage to start the replication manager.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('started', function () {
console.log('Thali replication manager started');
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
ThaliReplicationManager
constructor
start
stop
starting
started
stopping
stopped
startError
stopError
Creates a new instance of the ThaliReplicationManager
class with a PouchDB instance.
db
:PouchDB
- a PouchDB instance used for synchronization across devices.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
This method starts the Thali Replication Manager with the given device name, port number used for synchronization and database name to synchronize. Once called this method emits the starting
event. Once started, the started
event is fired. If there is an error in starting the Thali Replication Manager, the startError
event will fire.
deviceName
:String
- the device name to start broadcasting.port
:Number
- the port number used for synchronization.dbName
:String
- the name of the database.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('started', function () {
console.log('Thali replication manager started');
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
This method stops the Thali Replication Manager. Once called, this will fire the stopping
event. Once stopped, the stopped
event will fire. If an error occurs stopping the Thali Replication Manager, the stopError
event will fire.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('started', function () {
manager.stop();
});
manager.on('stopped', function () {
console.log('Thali replication manager stopped');
})
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
This event is called once start
has been called and before it has fully started with the started
event or an error was raised with the startError
event.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('starting', function () {
console.log('Thali replication manager is starting');
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
This event is called once start
has been called and has successfully started.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('started', function () {
console.log('Thali replication manager has started');
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
This event is called once start
has been called and has not started successfully.
error
: An error which occurred during starting the Thali Replication Manager.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('startError', function (err) {
console.log('Thali replication failed to start: %s', err);
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
This event is called once stop
has been called and before it has fully stopped with the stopped
event or an error was raised with the stopError
event.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('started', function () {
manager.stop();
});
manager.on('stopping', function () {
console.log('Thali replication manager is stopping');
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
This event is called once stop
has been called and has successfully stopped.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('started', function () {
manager.stop();
});
manager.on('stopped', function () {
console.log('Thali replication manager has stopped');
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);
This event is called once stop
has been called and has not stopped successfully.
error
: An error which occurred during starting the Thali Replication Manager.
var ThaliReplicationManager = require('thali');
var PouchDB = require('pouchdb');
var db = new PouchDB('dbname');
var manager = new ThaliReplicationManager(db);
manager.on('started', function () {
manager.stop();
});
manager.on('stopError', function (err) {
console.log('Thali replication manager failed to stop: %s', err);
});
manager.start('deviceName', 5000 /* port */, 'thali' /* db name */);