npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pouchdb-longpoll-ws-proxy

v1.0.0

Published

You can't replicate to more than 6 database with PouchDB because many browsers has 6 maximum paralel connection. PouchDB uses long poll HTTP connection to watch changes, thus hitting the maximum paralel connection.

Downloads

1

Readme

You can't replicate to more than 6 database with PouchDB because many browsers has 6 maximum paralel connection. PouchDB uses long poll HTTP connection to watch changes, thus hitting the maximum paralel connection.

This helper provides a custom fetch method to watch changes via WebSocket so it won't hit maximum connection limitation. It uses standard fetch if the operation is not a long poll operation.

Just read the source code. It's short.

Why not use socket-pouch?

Because it doesn't work in my case. I can't create index and other things also doesn't work. I don't know why. Just try it by yourself. Is it working? If yes then use it. If not then maybe this helper is a good news for you.

socket-pouch is also a whole new adapter while my helper is not an adapter. It's just a fetcher so it more likely to work since I don't introduce any custom adapter.

How to

Example code is available in folder example.

Server

Yes, you need to run a server. This is the proxy to provide the WebSocket interface.

const createServer = require('pouchdb-longpoll-ws-proxy/createServer');

const wsServer = createServer({
  host: '0.0.0.0',
  port: 8080,
});

wsServer.on('listening', () => console.log('listening'));

// wsServer.close();

You can also use HTTPS to run WSS.

const https = require('https');
const createServer = require('pouchdb-longpoll-ws-proxy/createServer');

const httpsServer = https.createServer({
  key: fs.readFileSync(process.env.PATH_KEY, { encoding: 'utf8' }),
  cert: fs.readFileSync(process.env.PATH_CERT, { encoding: 'utf8' }),
});

httpsServer.listen(8080);

const wsServer = createServer({
  host: '0.0.0.0',
  server: httpsServer,
});

Client

import createFetchWs from 'pouchdb-longpoll-ws-proxy/createFetchWs';
const fetchWs = createFetchWs('ws://localhost:8080'); // this is all of it

// do what you usually do
const dbRemote = new PouchDB({
  name: `http://localhost:5984/nameDbRemote`,
  fetch: fetchWs,
});
const dbLocal = new PouchDB({
  name: 'nameDbLocal',
});
const replicator = dbLocal.replicate.from(dbRemote, {
  live: true,
  retry: true,
});
replicator.on('change', onChange);

API

createServer(options)

Create a new server instance. Read this and this. Returns server object.

createFetchWs(urlWs)

Create a fetcher to be used by PouchDB. urlWs is the URL to the server.