Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Sync various PouchDBs over a stream

Notifications You must be signed in to change notification settings

yldio/pouch-stream-multi-sync

Repository files navigation

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