diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-06-05 05:32:45 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-06-05 05:32:45 +0400 |
commit | bb51259cf0fc818e66206f6136f8c3c41d3fa301 (patch) | |
tree | 1123c035f3965fa82e4fc7f88e27943d839f40bb /index.js | |
parent | b20c8e96a3d258d549aa0c5c783ce623684d8e5f (diff) |
make http server optional; emit 'listening'
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -20,21 +20,26 @@ inherits(WebTorrent, Client) function WebTorrent (opts) { var self = this opts = opts || {} - if (opts.blocklist) opts.blocklist = parseBlocklist(opts.blocklist) + if (opts.blocklist) opts.blocklist = parseBlocklist(opts.blocklist) // TODO: this usage is weird Client.call(self, opts) if (opts.list) { return } - self._startServer() + if (opts.port !== false) { + // start http server + self.server = http.createServer() + self.server.on('request', self._onRequest.bind(self)) + self.server.listen(opts.port) + self.server.once('listening', function () { + self.emit('listening') + }) + } self.on('torrent', function (torrent) { self._onTorrent(torrent) }) - - // TODO: add event that signals that all files that are "interesting" to the user have - // completed and handle it by stopping fetching additional data from the network } WebTorrent.prototype.add = function (torrentId, opts, cb) { @@ -114,12 +119,6 @@ WebTorrent.prototype._onTorrent = function (torrent) { self.torrent = torrent } -WebTorrent.prototype._startServer = function () { - var self = this - self.server = http.createServer() - self.server.on('request', self._onRequest.bind(self)) -} - WebTorrent.prototype._onRequest = function (req, res) { var self = this |