2

I am trying to create a Node.js server that loads multiple torrent magnets and then serves a static directory to that .mp4 (endpoint), similar to what the demo is doing for a single torrent.

const WebTorrent = require('webtorrent')
var client = new WebTorrent()
var torrentId = '#'
const util = require('util')
client.add(torrentId, function (torrent) {
  // Create HTTP server for this torrent
  var server = torrent.createServer()
  // console.log(util.inspect(torrent.createServer(), {showHidden: true, depth: null})) // To see what's going on
  // Visit http://localhost:<port>/ to see a list of files
  // Access individual files at http://localhost:<port>/<index> where index is the index
  // in the torrent.files array
  server.listen(8000) // s  tart the server listening to a port
})

My end goal was to eventually have a database of magnet URL's, then have my server create a direct endpoint to each .mp4 file. This demo is working for the most basic re-creatable example for a single magnet, but I would like to load up multiple and serve the endpoints like:

client.add(magnet.forEach(), function(torrent) {
  // Create server after multiple torrents loaded
})

I guess I really need to know how torrent.createServer() is able to make the static directory, or is there a way to load up multiple magnets?

Here is what it is creating for a single magnet url.

enter image description here

I know torrent.createServer() is making a simple HTTP server, I just do not understand also how it is indexing and serving the .mp4's directly without downloading them prior to the server.

ABC
  • 2,068
  • 1
  • 10
  • 21

0 Answers0