pouch-stream-multi-sync

0.3.0 • Public • Published

pouch-stream-multi-sync

By Build Status

Sync several PouchDBs through a stream.

Supports reconnection, negotiation and authentication.

Install

$ npm install pouch-stream-multi-sync --save

Server

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);

Client

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);
}

API

TODO

License

ISC

Readme

Keywords

none

Package Sidebar

Install

npm i pouch-stream-multi-sync

Weekly Downloads

0

Version

0.3.0

License

ISC

Last publish

Collaborators

  • pgte