2018-04-06 18:31:25 +10:00
# DwebTransports
2018-04-08 14:53:19 +10:00
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)
2018-04-27 11:52:16 +10:00
to support the decentralized web.
2018-04-08 14:53:19 +10:00
2018-04-19 17:50:02 +10:00
### Goals
2018-04-08 14:53:19 +10:00
* 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
2018-07-27 13:35:10 -07:00
`"@internetarchive/dweb-transports.git": "latest",`
2018-04-08 14:53:19 +10:00
to your package.json file in the dependencies section.
2018-07-27 13:35:10 -07:00
* `npm install @internetarchive/dweb-transports` will install the dependencies including IPFS & WebTorrent
2018-04-08 14:53:19 +10:00
2018-07-27 13:35:10 -07:00
`const DwebTransports = require("@internetarchive/dweb-transports")` will add all Transports to a Javascript file.
2018-05-30 20:11:33 -07:00
* TODO-API writeup how to require only some of the transports.
2018-04-08 14:53:19 +10:00
* Then see usage API below
### Installation and usage in the Browser
* 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>`
Then code like this should work.
```
2018-04-09 12:12:20 +10:00
async function main(url) {
2018-04-08 14:53:19 +10:00
try {
2018-04-09 12:12:20 +10:00
// and if not found will use the defaulttransports specified here.
await DwebTransports.p_connect({
statuselement: document.getElementById("statuselement"), // Where to build status indicator
defaulttransports: ["HTTP","IPFS"], // Default transports if not specified
transports: searchparams.getAll("transport") // Allow override default from URL parameters
2018-08-13 17:55:04 +10:00
});
2018-04-09 12:12:20 +10:00
// Any code you want to run after connected to transports goes here.
2018-04-08 14:53:19 +10:00
} catch(err) {
2018-04-09 12:12:20 +10:00
console.log("App Error:", err);
2018-04-08 14:53:19 +10:00
alert(err.message);
}
}
var searchparams = new URL(window.location.href).searchParams;
2018-04-09 12:12:20 +10:00
```
See [example_block.html ](./example_block.html ) for an example of connecting, storing and retrieving.
2018-04-19 17:50:02 +10:00
See [API.md ](./API.md ) for the detailed API.
2018-04-27 11:52:16 +10:00
2018-09-15 20:20:44 +10:00
See [Dweb document index ](./DOCUMENTINDEX.md ) for a list of the repos that make up the Internet Archive's Dweb project, and an index of other documents.