The [WebTorrent](https://webtorrent.io) project provides a way for websites to
share the bandwidth load with the users viewing content. It works on almost any
content, but the first thing I I implemented is for Video.

# Getting Media

This demo is found in `admin/bando/demos/WTVideos.svelte` and it is coded to expect a sample image, video and torrent file at:

* `/images/sample_video.mp4`
* `/images/sample_image.jpg`
* `/images/sample_video.mp4.torrent`

If you want it to work locally, grab a video and an image and place them there, then use `mktorrent` as described next.

# Making the .torrent

This will most likely *only* work if you have your server on `127.0.0.1` since the torrent file is configured for that.  Also, the default `npm run dev` will run the simple tracker implementation found in `services/tracker.js`.  If you want to generate the torrents again then run:

```shell
mktorrent -v -w http://127.0.0.1:5001/images/sample_video.mp4 \
  -a ws://127.0.0.1:9001/ \
  -o static/images/sample_video.mp4.torrent \
  -p -l 18 static/images/sample_video.mp4
cp -r static/images public/images
```

It uses the [mktorrent](https://github.com/pobrn/mktorrent) to generate the torrent since it is faster.  Be careful of the WebTorrent specific options I use in the `mktorrent` that are needed for WebTorrent to understand the torrent:

* `-p` -- Sets the private flag.  This isn't needed for WebTorrent but is
  needed if you want to add extra protections to people accessing your content
  only after they log in.
* `-l 18` -- Sets the piece length to 18, which is what WebTorrent seems to need.
* `-w 127.0.0.1` -- Sets an initial web URL to use as a source.  You
  should remove this if you want them to only go through the tracker and other
  users.
* `-a ws://127.0.0.1:9001/` -- Tells WebTorrent where the tracker is located.

# Bugs

1. It looks like WebTorrent has a problem getting the last chunk in some situations and I'm quite sure why.  If you have an idea let me know.

# Download Link

If you want to let people download the video then add the `download={ true }` property.
