Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Torrent Identifier: Using WebRTC clients/servers from localhost #422

Closed
VoR0220 opened this issue Sep 4, 2015 · 5 comments
Closed

Invalid Torrent Identifier: Using WebRTC clients/servers from localhost #422

VoR0220 opened this issue Sep 4, 2015 · 5 comments

Comments

@VoR0220
Copy link

@VoR0220 VoR0220 commented Sep 4, 2015

So I know that this has been something that has been addressed before but I was under the understanding that it had been fixed. We are currently utilizing Angular.js to try and inject torrent files into the DOM from our client. We keep trying to test this out but to no avail no matter what we try. Here is what we have:

function to download:

    startStream = function(addr) {
    var buffer = window.btoa(self.file);
    // buffer.write(self.infoHash, "utf-8");

    self.client.download(buffer, function(torrent) {
      // Got torrent metadata!
      var file = torrent.files[0] // Let's say the first file is an audio file...
      var audio = document.getElementById('audioElement') // Get audio element
      file.createReadStream().pipe(audio) // Stream the audio into the <audio> tag

      console.log('Client is downloading:', torrent.infoHash);

      torrent.addPeer(addr);

      torrent.files.forEach(function(file) {
        // Display the file by appending it to the DOM. Supports video, audio, images, and
        // more. Specify a container element (CSS selector or reference to DOM node).
        file.appendTo('body', function(err, elem) {
          if (err) throw err; //file failed to download or display in DOM
          console.log('New DOM node with the content', elem);
        });
      });
    });

function to seed:

seedStream = function(file) {

    self.client.seed(file, function onTorrent(torrent) {
      window.seeding = true;
      console.log('Client is seeding:', torrent.infoHash);
    });

    //server.close;
    self.client.destroy;
  }

actual logic for execution via angular:

.controller('StreamController', ['$scope', '$http', function StreamController($scope, $http) {

        $scope.renderTorrent = function(e) {
            var trackInput = document.querySelector('#track_file');

            var Seeder = new Stream(trackInput.files[0], '127.0.0.1:3000');

            Seeder.seedStream(trackInput.files[0]);

            var Leecher = new Stream('badacc9f73671c99ab0d65557b8fb2878cbfdbd5', '127.0.0.1:3000'); //provides info hash of the seeded song

            var checkSeed = setInterval(function() {
              if (window.seeding) {
                Leecher.startStream('127.0.0.1');
                return clearInterval(checkSeed);
              }
            }, 250);
        };

It continues to seed just fine, but when it comes to downloading it keeps giving the invalid torrent identifier. What are we doing wrong here? What can we do to get this up and running?

@VoR0220

This comment has been minimized.

Copy link
Author

@VoR0220 VoR0220 commented Sep 4, 2015

Since this, I have decided to split the seeding and leeching into 2 separate scopes, but the code remains the same. Still getting the same error.

@VoR0220

This comment has been minimized.

Copy link
Author

@VoR0220 VoR0220 commented Sep 5, 2015

further update: I have been trying to stream this from a client in instant.io...no such luck :/ Does it automatically seek out peers?

@VoR0220 VoR0220 changed the title Invalid Torrent Identifier Invalid Torrent Identifier: Using WebRTC clients/servers from localhost Sep 5, 2015
@VoR0220

This comment has been minimized.

Copy link
Author

@VoR0220 VoR0220 commented Sep 5, 2015

Update: No longer getting the error after playing around with the hex string itself and setting up a local seeding webtorrent, but still can't seem to get it to download....

@VoR0220

This comment has been minimized.

Copy link
Author

@VoR0220 VoR0220 commented Sep 7, 2015

@feross any comment at all on the nature of this error?

@VoR0220

This comment has been minimized.

Copy link
Author

@VoR0220 VoR0220 commented Sep 14, 2015

Finally got it working on a whim.

Stream library:

  Stream.prototype.startStream = function(addr) {

    self.client.add(self.file, function(torrent) {
      // Got torrent metadata!
      var file = torrent.files[0]; // Let's say the first file is an audio file...

      console.log('Client is downloading:', torrent.infoHash);

      torrent.addPeer(addr);
      torrent.files.forEach(function(file) {
        // Display the file by appending it to the DOM. Supports video, audio, images, and
        // more. Specify a container element (CSS selector or reference to DOM node).
        var playerTarget = document.querySelector('.track-details');

        file.appendTo(playerTarget, function(err, elem) {
          if (err) throw err; //file failed to download or display in DOM
          console.log('New DOM node with the content', elem);
        });
      });
    });
  }

Angular Controller

   var songHash = '';
        $scope.streamTorrent = function(e) {

            console.log(songHash);

            var Leecher = new Stream(songHash, '127.0.0.1:3001');

            var checkSeed = setInterval(function() {
              if (window.seeding) {
                console.info('G')
                Leecher.startStream('127.0.0.1:8000');
                return clearInterval(checkSeed);
              }  
            }, 250);
        };

        $scope.seedTorrent = function(e){
          var trackInput = document.querySelector('#track_file');

            var Seeder = new Stream(trackInput.files[0], '127.0.0.1:3000');

            Seeder.seedStream(trackInput.files[0], 'e3d87a69fb87cc1f24c065d1f09cb7015ad04d5e');
            var logHash = setInterval(function() {
                if (window.Hash) {
                  console.log(Seeder.returnInfoHash());
                  songHash = Seeder.returnInfoHash();
                  return clearInterval(logHash);
                }
            }, 250);

        };
@VoR0220 VoR0220 closed this Sep 14, 2015
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.