How to use hyperswarm - 2 common examples

To help you get started, we’ve selected a few hyperswarm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inkandswitch / pushpin / src / background / index.tsx View on Github external
import { RepoBackend, DocUrl } from 'hypermerge'

import { ToBackendRepoMsg } from 'hypermerge/dist/RepoMsg'
import { Socket } from 'net'
// import Client from 'discovery-cloud'
import ipc from '../ipc'
import { HYPERMERGE_PATH, FILE_SERVER_PATH } from '../renderer/constants'
import Root from './components/Root'
import { ToSystemMsg } from '../renderer/System'

window._debug = {}

const back = new RepoBackend({ path: HYPERMERGE_PATH })

// const cloud = new Client({ url: 'wss://pushpin-relay.herokuapp.com' })
const swarm = Hyperswarm({
  queue: {
    multiplex: true,
  },
})

back.addSwarm(swarm)
// back.addSwarm(cloud)

back.startFileServer(FILE_SERVER_PATH)
window._debug.repo = back
window._debug.swarm = swarm

ipc.config.id = 'background'

ipc.serve(() => {
  ipc.server.on('repo.msg', (msg: ToBackendRepoMsg) => {
github automerge / hypermerge / tools / Cat.ts View on Github external
import { Repo, DocUrl } from '../src'
import Hyperswarm from 'hyperswarm'

const url = process.argv[2] as DocUrl

if (url === undefined) {
  console.log('Usage: cat ')
  process.exit()
}

const repo = new Repo({ memory: true })

repo.setSwarm(Hyperswarm())

console.log('Watching document:', url)

repo.watch(url, (doc) => {
  console.log(doc)
})

hyperswarm

A distributed networking stack for connecting peers

MIT
Latest version published 1 month ago

Package Health Score

79 / 100
Full package analysis

Popular hyperswarm functions

Similar packages