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
# Install
npm i -g live-torrent
# Start with example live-feed
live-torrent -u http://wms.shared.streamshow.it/carinatv/carinatv/ -p playlist.m3u8
# Open browser at http://127.0.0.1:8008
I have a regular feed already
live-torrent can convert your feed into a webtorrent enabled feed. Just install the CLI tool and start converting your feed.
I want to create a feed !
Have a look in the server/
directory !
How to implement on a website ?
Just host the script/sw yourself. Also, there are some limitations to the use of SW ; it needs to be served from HTTPS, and it 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 :)
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. If it fails, it falls back to the manifest url (and then seed), otherwise, well p2p - yay !
Basically 3 different pieces are needed :
- a server script that takes in a HLS feed and adds the magnet links to it
- serviceworker to proxy the manifest/chunks requests
- client script, that's the bit utilizing webtorrent (no webrtc in SW !)
- Implement CLI tool that could live on top of existing feeds
- Optimise p2p - shave off more time for webtorrent to download the chunks