Sync several PouchDBs through a stream.
Supports reconnection, negotiation and authentication.
$ npm install pouch-stream-multi-sync --save
var PouchSync = require('pouch-stream-multi-sync');
var server = PouchSync.createServer(onRequest);
function onRequest(credentials, dbName, cb) {
if (credentials.token == 'some token') {
cb(null, new PouchDB(dbName));
} else {
cb(new Error('not allowed'));
}
};
// pipe server into and from duplex stream
stream.pipe(server).pipe(stream);
Example of client using a websocket:
var websocket = require('websocket-stream');
var PouchSync = require('pouch-stream-multi-sync');
var db = new PouchDB('todos');
var client = PouchSync.createClient(getStream);
var sync = client.sync(db, {
remoteName: 'todos-server',
credentials: { token: 'some token'}
});
client.connect('ws://somehost:someport');
function getStream(address) {
return websocket(address);
}
TODO
ISC