• Stars
    star
    194
  • Rank 200,219 (Top 4 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PouchDB over WebRTC

PeerPouch

A plugin for PouchDB which allows a remote PouchDB instance to be used locally. It transfers data over WebRTC, for simple lower-latency remote access and even particularly peer-to-peer replication!

API

To set up a peer connection, you actually need to start with a centralized database — this hub is first used for signalling connection parameters, and then the connection can be used to exchange messages.

PouchDB(anyDB, function (e, hub) { /* now you can use the methods below */ })

This isn't actually a PeerPouch call, but to get the "hub" below you simply create a PouchDB instance for a database that all peers will share. This would usually be a CouchDB server accessed via HTTPS, but PeerPouch itself doesn't really care. (For example, in testing I sometimes use IndexedDB as a hub between two tabs in the same browser.)

This hub is used for signalling, i.e. for exchanging information about shares and peers. Every share creates a corresponding document in the database. Additionally, when opening a share the peers exchange a number of messages via this hub, received via its changes feed.

hub.getSharedDatabases([opts, ]cb)

Returns an array of shares available (not including ones you have shared) to cb. You may also provide a callback via opts.onChange which will receive new/_deleted shares as they are updated.

Each of these share documents will be locally modified to include a dbname field. This can be used to intialize using the PeerPouch WebRTC adapter, e.g. PouchDB(share.dbname, function (e, remote) { /* now the remote share is locally accessible! */ }.

hub.shareDatabase(db[, opts], cb)

Allows you to share a local database to remote peers. Opts can include .name (intended to be a human-readble string), .info (any arbitrary JSON-stringifiable object).

You may also provide an event handler via opts.onRemote which gets info and can evt.preventDefault() to refuse connection. [This API is still in progress and may change. Also note that security is a bit weak as there's no way to actually verify the remote's identity without having trusted design document on a trusted hub.]

CAUTION: because PouchDB was designed for single-user application, any remote which connects to will have whatever privilege access you do to the share.

hub.unshareDatabase(db, cb)

Removes the share information for the given database from the hub.

Example

After including PouchDB and PeerPouch on your page, start by opening the hub:

PouchDB("http://peerpouch-test.ipcalf.com", function (e, hub) {
    // now you can serve a database using…
    hub.shareDatabase(/* someOtherLocalPouch */);
    
    // or connect to someone else's shared database like…
    hub.getSharedDatabases(function (e,shares) {
        PouchDB(shares[0].dbname, function (e, remote) {
            remote.allDocs(function (e,result) { console.log("Peer's documents are:", result.rows); });
            // or set up two-way replication to a local DB!
            PouchDB.replicate(remote, local);
            PouchDB.replicate(local, remote);
        });
    });
});

Demo

Check out sendfile?

More Repositories

1

fermata

Succinct native REST client, for client-side web apps and node.js. Turns URLs into (optionally: magic!) JavaScript objects.
JavaScript
329
star
2

node-nrf

Pure-JavaScript nRF24L01 driver library
JavaScript
117
star
3

pi-spi

Simple RasPi SPI library (node.js)
C++
93
star
4

ipcalf

Gives back your public IP address in plain HTML, plain text, and JSON (w/CORS!)
HTML
72
star
5

fatfs

Standalone FAT16/FAT32 filesystem implementation in JavaScript
JavaScript
47
star
6

evel

[attempt at] safe eval of untrusted JavaScript source code in the browser.
JavaScript
33
star
7

struct-fu

Yet another node.js struct implementation (object↔︎buffer conversion)
JavaScript
27
star
8

ShutterStem

Open, decentralized photo repository based on CouchDB
JavaScript
27
star
9

sendfile

Share files directly with clients/friends/family using PeerPouch (WebRTC).
JavaScript
19
star
10

flatstache.js

Tiny library to expand flat Mustache.js templates (no sections/partials/etc.)
JavaScript
18
star
11

node-chargify

Simple wrapper around Chargify's REST API for node.js
JavaScript
17
star
12

pi-pins

Node.js module for controlling GPIO (with interrupts) for embedded Linux machines like Raspberry Pi and BeagleBone
JavaScript
14
star
13

LocLog

Location logging in CouchDB
JavaScript
13
star
14

node-rf24

Control nRF24L01+ wireless radio communications from a server with SPI/GPIO ports
C++
12
star
15

OpenLayers-Multitouch

Drop-in patch for better Multitouch and scrollwheel support in OpenLayers 2.10
JavaScript
12
star
16

sdcard

Tessel library for the SD card module.
JavaScript
11
star
17

greenhouse

Aquaponics monitoring and on-demand/remote-control fish feeder
Arduino
11
star
18

Metakaolin

Metakaolin is a commonly used starting material for laboratory synthesis of geopolymers.
JavaScript
10
star
19

microstates

REST for the wicking (i.e. garden beds. and the greenhouse, and the refrigerator and the stupid suburban lawn…)
10
star
20

wristmap

Maps on Pebble
JavaScript
9
star
21

gather-stream

Pipe a node.js stream into a buffer (with memory limit, error handling)
JavaScript
8
star
22

putdoc

Upload CouchDB design documents (from traditional couchapp format)
JavaScript
8
star
23

Glob

Barebones blog (CouchDB application)
JavaScript
6
star
24

js-cnc

JavaScript-based CNC controller (primarily intended to send send G-code to Grbl)
HTML
4
star
25

grbl-parallel

An Arduino shield for connecting Grbl to a YooCNC Mach3-style parallel port-based driver
Eagle
4
star
26

World-Wide-WebGL-map-demo

A demonstration of using WebGL to do web-based cartographic drawing on the GPU.
JavaScript
4
star
27

touch-test

Displays which touch and pointer events a mobile or desktop browser provides to HTML5 web apps
3
star
28

RQMS

Relaxed Queue Management System: simple low-latency Node.js job/message distribution manager using CouchDB for reliable persistence
JavaScript
3
star
29

tessel-cloudtester

JavaScript
3
star
30

jsblock

Chrome extension to block certain annoying/tracking scripts (Google Analytics, Tynt, Snap, Intellitxt…)
JavaScript
2
star
31

noscript-dropbox

An extremely rudimentary CouchDB form-based (no JavaScript) uploader, compatible with Netscape Navigator 4.05
JavaScript
2
star
32

twas

It was a dark and…
JavaScript
2
star
33

fermata-couchdb

CouchDB helpers for Fermata
JavaScript
1
star
34

TreeIO

Low-level library for manipulating append-only tree files
1
star
35

ddoc

Load functions from a local CouchApp into your node.js
JavaScript
1
star
36

rooflux

Logging/livestreaming of my solar PV inverter levels
JavaScript
1
star
37

GLRenderToTextureDemo

Objective-C
1
star
38

luseragent

How humans talk about their browsers.
JavaScript
1
star
39

halfstache.js

TODO
1
star
40

makerland-radio

Materials for Radio Workshop at Maker Land 2016
1
star
41

hanfordfriday

For all your Hanford Friday needs.
JavaScript
1
star
42

fishgoblub

Grabs images from an Eye-Fi and puts them into CouchDB.
JavaScript
1
star
43

PuSH-suite

PubSubHubbub v0.4 test suite
JavaScript
1
star
44

simplify-user-agent

User Agent helper library: simplify browser UA strings, match results using custom criteria
JavaScript
1
star
45

loading-docs

[wip]
JavaScript
1
star