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-14 11:13:51 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-10-14 11:13:51 +0400
commit0eb35e63b71e72857637e1bc86e213aed0ff4175 (patch)
tree9c9f8353159b62a08c9f6ec90ebc61148194ad33 /lib/server.js
parentb02c8ba10883d961897719d53583637215607c92 (diff)
Use --index to pick video file to stream (fix #150)
Diffstat (limited to 'lib/server.js')
-rw-r--r--lib/server.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/server.js b/lib/server.js
index a8c9973..03eef94 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 (webtorrent, port) {
+module.exports = function Server (client, port) {
var server = http.createServer()
server.on('connection', function (socket) {
@@ -31,21 +31,21 @@ module.exports = function Server (webtorrent, port) {
if (req.headers.origin)
res.setHeader('Access-Control-Allow-Origin', req.headers.origin)
- var u = url.parse(req.url)
- if (u.pathname === '/favicon.ico') return res.end()
- if (u.pathname === '/') u.pathname = '/' + webtorrent.index
- var i = Number(u.pathname.slice(1))
+ var pathname = url.parse(req.url).pathname
+ if (pathname === '/favicon.ico') return res.end()
+ if (pathname === '/') pathname = '/' + client.index
- if (isNaN(i) || i >= webtorrent.torrent.files.length) {
+ var index = Number(pathname.slice(1))
+ if (Number.isNaN(index) || index >= client.torrent.files.length) {
res.statusCode = 404
return res.end()
}
- if (webtorrent.torrent) onTorrent(webtorrent.torrent)
- else webtorrent.once('torrent', onTorrent)
+ if (client.torrent) onTorrent(client.torrent)
+ else client.once('torrent', onTorrent)
function onTorrent (torrent) {
- var file = torrent.files[i]
+ var file = torrent.files[index]
res.setHeader('Accept-Ranges', 'bytes')
res.setHeader('Content-Type', mime.lookup(file.name))