1.0.2 • Published 6 years ago

native-messaging-swarm v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Native messaging swarm

A swarm library that would allow to replicate a dat stream thorugh tcp/udp from the browser. It uses WebExtension's native messaging protocol.

Installation

npm install native-messaging-swarm

Usage

const runtime = require('browser.runtime') // or window.runtime
const hyperdrive = require('hyperdrive')
const swarm = require('native-messaging-swarm')

const archive = hyperdrive('./test')
const port = runtime.connectNative(`${__dirname}/native.js`)

archive.ready(() => {
  // shares the archive through tcp/udp from the native app
  swarm(archive, port)
})

Example

Thanks to browser.runtime, on nodejs it'll spawn a new process that mimics the native messaging app. In the future the native app can be packaged (https://github.com/zeit/pkg) and would work through a native messaging manifest (see WebExtensions).

Test this already by launching node example.js. It'll start an archive with a dat.json and share it through hyperdiscovery with the native app. To clone using hyperdiscovery use node clone.js [key].