Clone this repo:
$ git clone https://gist.github.com/23ad8d6e3a1509335253ff074fcd3cb6.git helia-b2b-sharing
$ cd helia-b2b-sharing/
Generate npm-browser.js
npm package bundle:
var __create = Object.create; | |
var __defProp = Object.defineProperty; | |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | |
var __getOwnPropNames = Object.getOwnPropertyNames; | |
var __getProtoOf = Object.getPrototypeOf; | |
var __hasOwnProp = Object.prototype.hasOwnProperty; | |
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | |
get: (a, b) => (typeof require !== "undefined" ? require : a)[b] | |
}) : x)(function(x) { | |
if (typeof require !== "undefined") |
export * from "@libp2p/bootstrap"; |
<!doctype html> | |
<html> | |
<head> | |
<link rel="icon" href="data:image/x-icon," /> | |
<script type="module" src="./multi-nodes-cdn.js"></script> | |
</head> | |
<body> | |
Open JavaScript console to check running logs | |
</body> | |
</html> |
// npm i helia @helia/unixfs | |
import * as helia from "helia"; | |
import {unixfs} from "@helia/unixfs"; // unixfs support for large bytes | |
import {CID} from "multiformats/cid"; // helia.pins not support string CID | |
const node1 = await helia.createHelia(); // tcp network, stored on memory (not use files) | |
const node2 = await helia.createHelia(); | |
const node1fs = unixfs(node1); | |
const node2fs = unixfs(node2); |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Epicycles of a single-stroke by DFT</title> | |
<script type="module" src="./main.js"></script> | |
</head> | |
<body style="display: flex; flex-direction: column; align-items: center; justify-content: center;"> | |
<h1>Draw a line</h1> | |
<canvas id="canvas" style="border: solid; width: 75svmin; height: 75svmin; "></canvas> |
// wrapping libp2p stream (mplex/stream) | |
// - stream.source: AsyncIterable<Uint8Array> | |
// - stream.sink: (Iterable<Uint8Array> | AsyncIterable<Uint8Array>) => Promise<undefined> | |
// - stream.close, stream.closeRead, stream.closeWrite, stream.abort, stream.reset | |
const newQueue = () => { | |
const [gets, polls] = [[], []]; | |
const next = () => new Promise( | |
get => polls.length > 0 ? polls.shift()(get) : gets.push(get)); | |
const poll = () => new Promise( | |
poll => gets.length > 0 ? poll(gets.shift()) : polls.push(poll)); |
await caches.delete("tmp"); | |
const cache = await caches.open("tmp"); | |
const req1 = new Request("http://example.com/"); | |
const req2 = new Request("http://example.com/", {method: "head"}); | |
const req3 = new Request("http://example.com/", {method: "post"}); | |
const res1 = new Response("hello en-US", {headers: {"Content-Type": "text/plain;charset=utf-8"}}); | |
const res2 = new Response("", {headers: {}}); | |
await cache.put(req1, res1); // cache "http://example.com/ with res1 |