This is a Fork , i removed many things from the original script, feel free to visit the original script at pldubouilh-live-torrent for more options.
Simple proof-of-concept for a live streaming solution based on webtorrent. Video player courtesy of hls.js.
Yes please ! Live demo with sintel at live.computer
# 1- Make some chunks in this folder /feed ( readme.md has instructions about how )
live-torrent -v -u https://live.computer/manifest.m3u8
# 2- run the script
npm run live
# 3- Open browser at http://127.0.0.1:8008
How to implement on a website ?
Just host the script, serviceworker and videoplayer on your site and you're good to go. Also, there are some limitations to the use of SW ; the site hosting the videoplayer needs to be served from HTTPS, and serviceworker should be located at the root of the domain (e.g. https://live.computer/sw.js
). Also feel free to open an issue if something's acting weird :)
Do I need CORS ?
Yes ! But it's easy to enable. It's enabled by default using the "create from a folder" option.
TLDR(ish); A server script parses the video manifest and generates torrent magnet links from the video chunks. The magnets are pushed on the manifest.
Now on the browser side, the videoplayer downloads the manifest, the serviceworker hijacks the request, extracts the magnet links, and tries to download the chunks via webtorrent.
Basically 3 different pieces are needed :
- a server script to make a HLS manifest with magnet links in it
- serviceworker to proxy the manifest/chunks requests
- client script, that's the bit utilizing webtorrent (no webrtc in SW !)
- Optimise p2p - shave off more time for webtorrent to download the chunks