Koukou Roukou
Koukou Roukou

Reputation: 11

Torrent-stream require is not defined

Trying to stream a torrent file in the browser by using github.com/mafintosh/torrent-stream with no success. Using the following simple example taken from the manual of the project.

<html lang="en">
<head>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
    <script>
        var torrentStream = require('torrent-stream');

        var engine = torrentStream('MAGNET-LINK-HERE');

        engine.on('ready', function() {
            engine.files.forEach(function(file) {
                console.log('filename:', file.name);
                var stream = file.createReadStream();
                // stream is readable stream to containing the file content
            });
        });
    </script>

In the chrome console I get the following error.

Uncaught ReferenceError: require is not defined

This error comes from line 8. Anyone used this project?

Upvotes: 0

Views: 463

Answers (1)

KiraLT
KiraLT

Reputation: 2607

I don't think this library supports a browser, you need to use NodeJS instead. If you wish to stream torrents in a browser, you may like webtorrent. But from my experience, a lot of torrents does not work with it when using in the browser.

You may be interested in Torrent Stream Server. It is a server that downloads and streams video at the same time, so you can watch the video without fully downloading it. It's based on torrent-stream library which you are exploring and has build-in interface.

Upvotes: 0

Related Questions