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

Error in the browser when trying to seed an array of strings #1483

Closed
vasco3 opened this issue Aug 26, 2018 · 2 comments
Closed

Error in the browser when trying to seed an array of strings #1483

vasco3 opened this issue Aug 26, 2018 · 2 comments

Comments

@vasco3
Copy link
Contributor

@vasco3 vasco3 commented Aug 26, 2018

What version of WebTorrent?
^0.102.1

What operating system and Node.js version?
n/A

What browser and version? (if using WebTorrent in the browser)
Chrome 68

What did you expect to happen?

Expected to be able to seed a stringified JSON blob.

    const { recipes } = this.props;
    const recipesSerialized = JSON.stringify(recipes);

    const client = new WebTorrent();

    client.seed([recipesSerialized], function seedTorrent({ magnetURI }) {
      console.log('Client is seeding ' + magnetURI);

      QRCode.toDataURL(magnetURI)
        .then(url => {
          this.setState({ exportDialogIsOpen: true, qrCodeDataUrl: url });
        })
        .catch(err => {
          // TODO show snackbar
          console.error(err);
        });
    });

What actually happened?

Received an error
Uncaught Error: filesystem paths do not work in the browser

@KayleePop

This comment has been minimized.

Copy link
Contributor

@KayleePop KayleePop commented Aug 26, 2018

Try this

    const { recipes } = this.props;
    const recipesSerialized = JSON.stringify(recipes);
    const recipesBuffer = Buffer.from(recipesSerialized);

    const client = new WebTorrent();

    client.seed(recipesBuffer, function seedTorrent({ magnetURI }) {
      console.log('Client is seeding ' + magnetURI);

      QRCode.toDataURL(magnetURI)
        .then(url => {
          this.setState({ exportDialogIsOpen: true, qrCodeDataUrl: url });
        })
        .catch(err => {
          // TODO show snackbar
          console.error(err);
        });
    });

see here for details on client.seed()

You're passing an array of strings, and it interprets strings as filesystem paths.

@vasco3

This comment has been minimized.

Copy link
Contributor Author

@vasco3 vasco3 commented Aug 26, 2018

works perfectly, thank you!

@vasco3 vasco3 closed this Aug 26, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Nov 24, 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
2 participants
You can’t perform that action at this time.