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

browserify issue #529

Closed
jkhall opened this issue Dec 15, 2015 · 8 comments
Closed

browserify issue #529

jkhall opened this issue Dec 15, 2015 · 8 comments

Comments

@jkhall
Copy link

@jkhall jkhall commented Dec 15, 2015

when I browserify the basic example from the webtorrent.io I get the error: net.createServer is not a function. It seems to make sense, not being able to make a server on the client, but I thought I'd bring it up since it seems that we are supposed to be able to browserify the npm webtorrent module. Just using the CDN for now.

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Dec 15, 2015

That's something, at least for now, clients cannot do. Would be cool to create an http server from your browser window, but not yet :(

Just like the direct file system access, it's still not available. And who knows if it will ever be.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Dec 17, 2015

@chiggachiggayeah Just to make sure, you got this error when calling torrent.createServer(), right? If you got it while calling some other function, then it might be a bug. Please leave a comment if that's the case.

@jkhall

This comment has been minimized.

Copy link
Author

@jkhall jkhall commented Dec 18, 2015

Hey sorry for just getting back. The error happens when I try to browserify webtorrent, which, from the repo, I thought was supposed to be possible. Maybe it's not anymore, or I just misunderstood. Anyhow, I get an error in the web console complaining that net.createServer isn't a function in this bit of code:

function TCPPool (port, hostname) {
  var self = this

  self.port = port
  self.listening = false
  self.swarms = {} // infoHash (hex) -> Swarm

  debug('new TCPPool (port: %s, hostname: %s)', port, hostname)

  // Save incoming conns so they can be destroyed if server is closed before the conn is
  // passed off to a Swarm.
  self.pendingConns = []

  self.server = net.createServer()
  self.server.on('connection', function (conn) { self._onConnection(conn) })
  self.server.on('error', function (err) { self._onError(err) })
  self.server.on('listening', function () { self._onListening() })
  self.server.listen(self.port, hostname)
}

the code that I've browserified is here:

var WebTorrent = require('webtorrent');

var client = new WebTorrent();

var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d'

client.add(torrentId, function (torrent) {
  // Torrents can contain many files. Let's use the first.
  var file = torrent.files[0]

  // Display the file by adding it to the DOM. Supports video, audio, image, etc. files
  file.appendTo('body')
})
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Dec 28, 2015

Yes, browserifying webtorrent should be possible, and works for me. It sounds like your browserify is misbehaving because it's packaging tcp-pool.js with the TCPPool class. This file is supposed to be skipped by bundlers. See this line: https://github.com/feross/bittorrent-swarm/blob/master/package.json#L14

Are you sure you're not using webpack or something like that? What version of browserify and webtorrent are you using?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Dec 28, 2015

Now that I think about it, I recall there was a browserify issue with resolving the browser field correctly in older versions of browserify.

Please make sure you're running the latest version.

npm install browserify@latest --save-dev

If you have browserify installed globally, beware that that might get used if your PATH is not set correctly in your scripts, so update that too, like this:

npm install browserify -g
@jkhall

This comment has been minimized.

Copy link
Author

@jkhall jkhall commented Dec 28, 2015

Yep. It seems to be working after an uninstall and then installing the latest browserify version. Sorry about that. Should've tried that myself instead of bothering you guys. Thanks though.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Dec 28, 2015

Cool, thanks for letting us know that you got it working!

@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 5, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 5, 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
3 participants
You can’t perform that action at this time.