OverviewFilesCommitsIssuesDocsReleasesPeers

holepunchto-kb / skills / hyperswarm / api-extract.json

66 lines · json ref:
{
  "repo": "hyperswarm",
  "timestamp": "2026-01-16T23:00:28.916Z",
  "entryPoint": "index.js",
  "exports": {
    "packageJson": {}
  },
  "api": {
    "file": "index.js",
    "exports": [
      {
        "type": "default",
        "name": "class"
      }
    ],
    "classes": [
      {
        "name": "Hyperswarm"
      }
    ],
    "functions": [
      {
        "name": "onclose"
      },
      {
        "name": "noop"
      },
      {
        "name": "allowAll"
      },
      {
        "name": "shouldForceRelaying"
      },
      {
        "name": "shouldBan"
      },
      {
        "name": "toRelayFunction"
      }
    ]
  },
  "readme": {
    "content": "# hyperswarm\n\n### [See the full API docs at docs.pears.com](https://docs.pears.com/building-blocks/hyperswarm)\n\nA high-level API for finding and connecting to peers who are interested in a \"topic.\"\n\n## Installation\n\n```\nnpm install hyperswarm\n```\n\n## Usage\n\n```js\nconst Hyperswarm = require('hyperswarm')\n\nconst swarm1 = new Hyperswarm()\nconst swarm2 = new Hyperswarm()\n\nswarm1.on('connection', (conn, info) => {\n  // swarm1 will receive server connections\n  conn.write('this is a server connection')\n  conn.end()\n})\n\nswarm2.on('connection', (conn, info) => {\n  conn.on('data', (data) => console.log('client got message:', data.toString()))\n})\n\nconst topic = Buffer.alloc(32).fill('hello world') // A topic must be 32 bytes\nconst discovery = swarm1.join(topic, { server: true, client: false })\nawait discovery.flushed() // Waits for the topic to be fully announced on the DHT\n\nswarm2.join(topic, { server: false, client: true })\nawait swarm2.flush() // Waits for the swarm to connect to pending peers",
    "sections": [
      "intro",
      "installation",
      "usage",
      "hyperswarm api",
      "peerdiscovery api",
      "peerinfo api",
      "license"
    ],
    "hasApi": true,
    "hasExamples": true,
    "exampleCount": 2,
    "examples": [
      "npm install hyperswarm",
      "const Hyperswarm = require('hyperswarm')\n\nconst swarm1 = new Hyperswarm()\nconst swarm2 = new Hyperswarm()\n\nswarm1.on('connection', (conn, info) => {\n  // swarm1 will receive server connections\n  conn.write('this is a server connection')\n  conn.end()\n})\n\nswarm2.on('connection', (conn, info) => {\n  conn.on('data', (data) => console.log('client got message:', data.toString()))\n})\n\nconst topic = Buffer.alloc(32).fill('hello world') // A topic must be 32 bytes\nconst discovery = swarm1.join(topic, { server: true, client: false })\nawait discovery.flushed() // Waits for the topic to be fully announced on the DHT\n\nswarm2.join(topic, { server: false, client: true })\nawait swarm2.flush() // Waits for the swarm to connect to pending peers.\n\n// After this point, both client and server should have connections"
    ]
  },
  "patterns": [
    "peer-discovery",
    "dht-discovery",
    "streaming"
  ]
}