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-10-22 10:20:28 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-10-22 10:20:28 +0400
commit4c1bbb6b1d91757071f253ad0ece6186c4bc7333 (patch)
tree58b0ef1ab152776a56373188b216eb6f925975e0 /lib/server.js
parentf5e70ef4ef248149298c6498c48cb0dfad34cd9b (diff)
add torrent.createServer() method
Diffstat (limited to 'lib/server.js')
-rw-r--r--lib/server.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/server.js b/lib/server.js
index 3dd996c..0f59aa2 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -5,7 +5,7 @@ var pump = require('pump')
var rangeParser = require('range-parser')
var url = require('url')
-module.exports = function Server (client, port) {
+module.exports = function Server (torrent, opts) {
var server = http.createServer()
server.on('connection', function (socket) {
@@ -33,18 +33,20 @@ module.exports = function Server (client, port) {
var pathname = url.parse(req.url).pathname
if (pathname === '/favicon.ico') return res.end()
- if (pathname === '/') pathname = '/' + client.index
+ if (pathname === '/') {
+ return res.end('TODO: list files')
+ }
var index = Number(pathname.slice(1))
- if (Number.isNaN(index) || index >= client.torrent.files.length) {
+ if (Number.isNaN(index) || index >= torrent.files.length) {
res.statusCode = 404
return res.end()
}
- if (client.torrent) onTorrent(client.torrent)
- else client.once('torrent', onTorrent)
+ if (torrent.ready) onReady()
+ else torrent.once('ready', onReady)
- function onTorrent (torrent) {
+ function onReady () {
var file = torrent.files[index]
res.setHeader('Accept-Ranges', 'bytes')
@@ -68,7 +70,6 @@ module.exports = function Server (client, port) {
pump(file.createReadStream(range), res)
}
})
- server.listen(port)
return server
}