diff --git a/src/videos.js b/src/videos.js index 605ce098f..48ec19d4d 100644 --- a/src/videos.js +++ b/src/videos.js @@ -103,6 +103,7 @@ VideosDB.findById(id, function (err, video) { if (err || !video) { + if (!err) err = new Error('Cannot find this video.') logger.error('Cannot find this video.', { error: err }) return callback(err) } diff --git a/src/webTorrentNode.js b/src/webTorrentNode.js index 03bff7803..ebe8d5d81 100644 --- a/src/webTorrentNode.js +++ b/src/webTorrentNode.js @@ -8,16 +8,8 @@ var logger = require('./logger') - var host - var port - - try { - host = config.get('webserver.host') - port = config.get('webserver.port') - } catch (e) { - host = 'client' - port = 1 - } + var host = config.get('webserver.host') + var port = config.get('webserver.port') var nodeKey = 'webtorrentnode' + port var processKey = 'webtorrent' + port @@ -33,7 +25,21 @@ // Useful to kill it webtorrentnode.app = null - webtorrentnode.create = function (callback) { + webtorrentnode.create = function (options, callback) { + if (typeof options === 'function') { + callback = options + options = {} + } + + // Override options + if (options.host) host = options.host + if (options.port) { + port = options.port + nodeKey = 'webtorrentnode' + port + processKey = 'webtorrent' + port + ipc.config.id = nodeKey + } + ipc.serve(function () { if (!webtorrentnode.silent) logger.info('IPC server ready.') diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js index fff179006..81d4b06b6 100644 --- a/test/api/multiplePods.js +++ b/test/api/multiplePods.js @@ -61,7 +61,7 @@ .end(function (err, res) { if (err) throw err - webtorrent.create(function () { + webtorrent.create({ host: 'client', port: '1' }, function () { done() }) }) @@ -214,7 +214,7 @@ describe('Should seed the uploaded video', function () { it('Should add the file 1 by asking pod 3', function (done) { // Yes, this could be long - this.timeout(60000) + this.timeout(200000) getVideosList(urls[2], function (err, res) { if (err) throw err @@ -232,15 +232,13 @@ it('Should add the file 2 by asking pod 1', function (done) { // Yes, this could be long - this.timeout(60000) + this.timeout(200000) getVideosList(urls[0], function (err, res) { if (err) throw err var video = res.body[1] - video_id = video._id - webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist expect(torrent.files.length).to.equal(1) @@ -253,12 +251,13 @@ it('Should add the file 3 by asking pod 2', function (done) { // Yes, this could be long - this.timeout(60000) + this.timeout(200000) getVideosList(urls[1], function (err, res) { if (err) throw err var video = res.body[2] + video_id = res.body[1]._id webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist diff --git a/test/api/singlePod.js b/test/api/singlePod.js index 59a617970..149c10b9e 100644 --- a/test/api/singlePod.js +++ b/test/api/singlePod.js @@ -23,7 +23,7 @@ app = app1 url = url1 - webtorrent.create(function () { + webtorrent.create({ host: 'client', port: '1' }, function () { done() }) })