Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-06-05 05:32:45 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-06-05 05:32:45 +0400
commitbb51259cf0fc818e66206f6136f8c3c41d3fa301 (patch)
tree1123c035f3965fa82e4fc7f88e27943d839f40bb /index.js
parentb20c8e96a3d258d549aa0c5c783ce623684d8e5f (diff)
make http server optional; emit 'listening'
Diffstat (limited to 'index.js')
-rw-r--r--index.js21
1 files changed, 10 insertions, 11 deletions
diff --git a/index.js b/index.js
index 3b61c1e..f129263 100644
--- a/index.js
+++ b/index.js
@@ -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