From 8b01cecae9349e333c9015ee8ac74dcec4216cae Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 17 Feb 2023 15:35:44 -0500 Subject: [PATCH] Give some better documentation for people who run it locally. --- admin/bando/demos/HLSVideo.svelte | 16 ++++++++++++-- admin/bando/demos/Video.svelte | 12 ++++++++-- admin/bando/demos/WTVideo.svelte | 20 +++++++++++++---- admin/bando/demos/WTVideo.svelte.md | 34 +++++++++++++++++++++++------ client/wt.js | 7 +++++- 5 files changed, 73 insertions(+), 16 deletions(-) diff --git a/admin/bando/demos/HLSVideo.svelte b/admin/bando/demos/HLSVideo.svelte index d003f2f..09f7e8b 100644 --- a/admin/bando/demos/HLSVideo.svelte +++ b/admin/bando/demos/HLSVideo.svelte @@ -1,10 +1,22 @@ + +

Instructions

+ +

To get this demo to work you should get the +WTVideo demo working. +This demo will have you create a sample image and sample video that +the HLSVideo uses as well. If you don't have access to +the mktorrent command mentioned in the +WTVideo demo then +just skip that part and as long as you have the samples in place +the HLSVideo demo will work.

diff --git a/admin/bando/demos/Video.svelte b/admin/bando/demos/Video.svelte index 6f8d777..c5a6892 100644 --- a/admin/bando/demos/Video.svelte +++ b/admin/bando/demos/Video.svelte @@ -1,7 +1,8 @@ @@ -14,3 +15,10 @@ + +

Instructions

+ +

Just like with the HLSVideo component, +you should get the WTVideo +demo working to get the sample files setup +correctly. After that this demo will work too.

diff --git a/admin/bando/demos/WTVideo.svelte b/admin/bando/demos/WTVideo.svelte index 49e3ab1..b4b22b0 100644 --- a/admin/bando/demos/WTVideo.svelte +++ b/admin/bando/demos/WTVideo.svelte @@ -1,12 +1,13 @@ @@ -21,3 +22,14 @@ + +

Instructions

+ +

Read the Docs panel for instructions + on how to get this demo to work on your local computer.

+ +

Bugs

+ +

The video downloads, but WebTorrent seems to lose track of the last +chunk. Not sure why but if you know then message me. +

diff --git a/admin/bando/demos/WTVideo.svelte.md b/admin/bando/demos/WTVideo.svelte.md index a84ef2e..49df1ed 100644 --- a/admin/bando/demos/WTVideo.svelte.md +++ b/admin/bando/demos/WTVideo.svelte.md @@ -2,23 +2,43 @@ 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: -``` -sh scripts/mktorrents.sh sample.mp4 +```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 [mktorrents](https://github.com/pobrn/mktorrent) to generate the torrent since it is faster. Be careful of the WebTorrent specific options I use in the ``services/mktorrents.sh`` that are needed for WebTorrent to understand the torrent: +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 15` -- Sets the piece length to 15. +* `-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 -=== +# Download Link -If you want to let people download the video then add the `download={ true }` property. This demo sets that option so you can see how it works. +If you want to let people download the video then add the `download={ true }` property. diff --git a/client/wt.js b/client/wt.js index 7916e54..4eb0e41 100644 --- a/client/wt.js +++ b/client/wt.js @@ -232,7 +232,12 @@ export const fetch_torrent_file = async (media) => { assert(media, "media can't be undefined"); assert(media.torrent_url, "media does not have torrent_url set"); - media.full_torrent_url = `${base_host}${media.torrent_url}`; + // kind of a hack to work with media models for now + if(media.torrent_url.startsWith("http")) { + media.full_torrent_url = `${media.torrent_url}`; + } else { + media.full_torrent_url = `${base_host}${media.torrent_url}`; + } let res = await fetch(media.full_torrent_url, { credentials: "same-origin" });