mirror of
https://github.com/fluencelabs/dweb-transports
synced 2025-03-15 18:30:49 +00:00
2.1 KiB
2.1 KiB
DwebTransports
General transport library for Decentralized Web handles multiple underlying transports.
Background
This library is part of a general project at the Internet Archive (archive.org) to support the decentralized web.
###Goals
- to allow a single API that can be used for most basic interactions with decentralized transports.
- to support multiple URLs, on different transports, so that the (current) underlying unreliability is hidden.
Node Installation
- Clone this repo.
- Until this is in npm, add the line
"dweb-transports": "git+https://git@github.com/mitra42/dweb-transports.git",
to your package.json file in the dependencies section. - (TODO Note location above will change to an internetarchive repo)
npm install dweb-transports
will install the dependencies including IPFS & WebTorrent
const DwebTransports = require(dweb-transport)
will add all Transports to a Javascript file.
- TODO writeup how to require only some of the transports.
- Then see usage API below
Installation and usage in the Browser
- TODO installation of dev dependencies
- Install npm & node
- Clone this repo and cd to it.
npm bundle
will create dist/dweb_transports_bundle.js- Add
<SCRIPT type="text/javascript" src="dweb_transports_bundle.js"></SCRIPT>
to your<HEAD>
- TODO need to split out necessary from htmlutils so p_connect exposed
Then code like this should work.
async function main() {
try {
// Connect to a set of transports, that the user can override
// p_connect will look for "?transport=HTTP" etc to override defaults
await p_connect({defaulttransport: ["HTTP", "IPFS"]});
// Code you want to happen after connection goes here
// Fetch some data from a service, specifiying two places to get it
foo = await DwebTransports.p_fetch(["http://bar.com/foo.json", "ipfs:/ipfs/Q1abc"], verbose);
} catch(err) {
alert(err.message);
}
}
var searchparams = new URL(window.location.href).searchParams;
// Allow specifying ?verbose=true in URL to get debugging
var verbose = searchparams.get("verbose") || false;