• Stars
    star
    198
  • Rank 196,898 (Top 4 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A client side library for fetching and rendering a static website via torrent over WebRTC

peerweb.js

A client side library for retrieving and rendering a static website over torrent.

Usage

window.peerweb.init(function(e) {
  if(e) throw e
  window.peerweb.debug = true
  window.peerweb.render([torrent_hash])
})

PeerWeb will download the directory from the torrent passed into render, and will replace the contents of document.body with the file index.html from the torrent. All subsequent GET http requests will be resolved against the torrent file.

The torrent should be structured something like:

./
├── imgs
│   ├── foo.png
│   └── bar.png
├── css
│   └── index.css
└── index.html

The main takeaway from the above diagram is that peerweb requires your torrent to have an index.html and that you can have nested subdirectories.

For an example, download ws and run it in the ./example directory in this repo.

Dependencies

All dependencies can be found in this repo under the ./example directory.

Unfortunately, peerweb only works in Chromium 49 or later (google-chrome-beta at the time of this writing). Chrome <40 has a bug preventing ServiceWorkers from loading blob files and all versions of Firefox that support ServiceWorkers has a bug preventing WebSockets from working when ServiceWorkers are being used for the page.

Installation

Download the above dependencies. Place router.js in the base of your project directory (along-side index.html). Then add the following to the <head> of your index.html file:

<script src="./path/to/async-1.5.2.js"></script>
<script src="./path/to/localforage-1.2.6.min.js"></script>
<script src="./path/to/webtorrent-0.72.1.min.js"></script>
<script src="./path/to/peerweb.js"></script>

Note: it is critical that router.js be served directly from ./router.js and not a subdirectory of your project. This allows the ServiceWorker to intercept all http requests for the webpage

How it works

peerweb uses the webtorrent project to download a static website. It then stores paths to the blobs for each file in the torrent in the browser's storage using localforage. It registers a ServiceWorker to intercept http requests from the page and attempts to resolve them against blobs found in the browser's storage. It then searches for index.html in the torrent and drops it into the current document.body triggering the website to render and the http requests to be intercepted by the ServiceWorker.

More Repositories

1

template

A simple framework for webapps
TypeScript
481
star
2

awesome-p2p

An awesome list for those interested in building decentralized applications
147
star
3

peerweb

Welcome to the Decentralized Web
JavaScript
118
star
4

getos

A Node.js module that returns the OS/Distribution name of the environment you are working on
JavaScript
78
star
5

dante

Build tests against Docker images by harnessing the power of layers
Go
44
star
6

dockeri.co

Badges for Docker
TypeScript
39
star
7

Taboo

CSS
36
star
8

presentation

JavaScript
27
star
9

wikiscroll

HTML
24
star
10

libfuse-template

A jumping off point for implementing a fuse file system
C
10
star
11

docker-webhook

JavaScript
8
star
12

isDev

A simple tool for determining if your node server is running in dev mode or not
JavaScript
7
star
13

docker-TrinityCore

Trinity Core files in a docker container
Shell
6
star
14

irc-sh

pure bash irc client
Shell
5
star
15

aws-mock-lambda-api-gateway

JavaScript
5
star
16

blob-to-stream

Convert a blob to a stream!
JavaScript
4
star
17

dagGen

A simple library for generating random directed acyclic graphs represented by adjacency matrices
Java
4
star
18

this-vc-does-not-exist

HTML
3
star
19

takeoff

JavaScript
3
star
20

awesome-prompt-engineering

3
star
21

knowledge

Documenting everything! Inspired by https://github.com/yoshuawuyts/knowledge/
3
star
22

kickass_nord

Generate OpenVPN configurations for Nord with fallbacks and bypasses
DIGITAL Command Language
3
star
23

build-container-sync

JavaScript
3
star
24

login-microservices

A collection of micro-services that solves login. Can be used for rapid application development.
JavaScript
3
star
25

theArtOfComputerProgramming

"The Art of Computer Programming" by Donald Knuth
Java
3
star
26

concurrent-request

JavaScript
3
star
27

nodedocs

Generate documentation from your cwd served up on localhost:8080
JavaScript
2
star
28

frea-primary-mirror

2
star
29

home_automation

Shell
2
star
30

marvin

An AI for handling async callbacks in JavaScript
JavaScript
2
star
31

rpi_setup

Download the latest raspbian lite image and get it ready for SSH
Shell
2
star
32

blockly-drones

JavaScript
2
star
33

buffered-reader

Buffer responses from asynchronous functions to increase the performance of Node.js applications
JavaScript
2
star
34

turn-it-up

Rust
2
star
35

peerweb-testing

Just testing the travis-ci configuration
JavaScript
2
star
36

ttlmap

{⏰} Map with TTL for values
JavaScript
1
star
37

todd

Sleeps on my couch and is helpful sometimes
JavaScript
1
star
38

awesome-projects

Projects I think are awesome
1
star
39

mpi-pi

A distributed monte-carlo algorithm for approximating pi using mpi.
C
1
star
40

npm-datamining

Scary datasets harvested from npm
JavaScript
1
star
41

peerweb-old

JavaScript
1
star
42

mded

Markdown Editor
JavaScript
1
star
43

siuPersonalWebsite

My Personal Homepage for SIUC
1
star
44

laptop

Lua
1
star
45

docker-iojs-test-server

1
star
46

frea-cli

JavaScript
1
star
47

stlaursWebsite

The Repository for STLAURS
PHP
1
star
48

retrohacker.github.io

HTML
1
star
49

goLex

A simple lexical analyzer written in Go
Go
1
star
50

varstring

A simple node library for replacing variables with strings in a string. Great for generating configuration files.
JavaScript
1
star
51

npm-change-resolve

JavaScript
1
star
52

docker-node-scratch

Node.js Docker Images....... From scratch!
Shell
1
star
53

json-types

TypeScript
1
star
54

objectify

JavaScript
1
star
55

owningTheStack

gimmicks for owningTheStack presentation
Shell
1
star
56

anki-terraform

Issue repository for my Terraform Anki deck
1
star
57

nodebuild

JavaScript
1
star
58

fuzzee-benchmarks

Run benchmarking tests to test the performance of fuzzee against jfuzzylogic
JavaScript
1
star
59

docker-integration

Jenkins test server for docker images
Shell
1
star
60

dotfiles_old

Contains a setup script for my dev environment and dotfiles for vim, xresources, and zsh configurations.
Python
1
star
61

node-template

An opinionated template to get a Node.js project up and running
JavaScript
1
star
62

documentation

storj documentation and tutorial
1
star
63

distributed_web

JavaScript
1
star
64

Minix

The incredibly lightweight RESTful routing package
JavaScript
1
star
65

new_website

JavaScript
1
star
66

CloudCompute2

C++
1
star
67

add-listener-first

A node module that ensures your EventEmitter listener will be run first
JavaScript
1
star
68

arduino-tests

Experimenting with writing tests for arduino code
C++
1
star
69

orgdeps

List the npm dependencies of a GitHub organization's public projects in a Unix friendly way
JavaScript
1
star
70

docker-npg

Docker script for building a node container with postgresql baked inside.
Shell
1
star
71

website-2015

Legacy website for blankenship.io
HTML
1
star
72

ofcourse

The backend REST server for ofCourse
JavaScript
1
star
73

old-dotfiles

C
1
star
74

npm-graphql

A graphql API for the npm registry
JavaScript
1
star
75

wedding

Wedding Website!
HTML
1
star
76

parse-docker-image-name

Aptly named module: given the name of a docker image, parse it into its components
JavaScript
1
star
77

kak-waka

KakouneScript
1
star
78

mpi-histogram

Generates a histogram of numbers using MPI.
C
1
star