2014-07-22 05:58:13 +00:00
|
|
|
var Server = require('../').Server
|
|
|
|
|
2016-03-01 01:39:03 +00:00
|
|
|
exports.createServer = function (t, opts, cb) {
|
|
|
|
if (typeof opts === 'string') opts = { serverType: opts }
|
|
|
|
|
|
|
|
opts.http = (opts.serverType === 'http')
|
|
|
|
opts.udp = (opts.serverType === 'udp')
|
|
|
|
opts.ws = (opts.serverType === 'ws')
|
|
|
|
|
|
|
|
var server = new Server(opts)
|
2014-07-22 05:58:13 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
server.on('error', function (err) { t.error(err) })
|
|
|
|
server.on('warning', function (err) { t.error(err) })
|
2014-07-22 05:58:13 +00:00
|
|
|
|
2015-01-29 22:59:08 +00:00
|
|
|
server.listen(0, function () {
|
2016-03-01 01:39:03 +00:00
|
|
|
var port = server[opts.serverType].address().port
|
2016-02-29 22:48:23 +00:00
|
|
|
var announceUrl
|
2016-03-01 01:39:03 +00:00
|
|
|
if (opts.serverType === 'http') {
|
2016-02-29 22:48:23 +00:00
|
|
|
announceUrl = 'http://127.0.0.1:' + port + '/announce'
|
2016-03-01 01:39:03 +00:00
|
|
|
} else if (opts.serverType === 'udp') {
|
2016-02-29 22:48:23 +00:00
|
|
|
announceUrl = 'udp://127.0.0.1:' + port
|
2016-03-01 01:39:03 +00:00
|
|
|
} else if (opts.serverType === 'ws') {
|
2016-02-29 22:48:23 +00:00
|
|
|
announceUrl = 'ws://127.0.0.1:' + port
|
|
|
|
}
|
2014-07-22 05:58:13 +00:00
|
|
|
|
|
|
|
cb(server, announceUrl)
|
|
|
|
})
|
|
|
|
}
|
2016-03-01 01:11:02 +00:00
|
|
|
|
|
|
|
exports.mockWebsocketTracker = function (client) {
|
|
|
|
client._trackers[0]._generateOffers = function (numwant, cb) {
|
|
|
|
var offers = []
|
|
|
|
for (var i = 0; i < numwant; i++) {
|
|
|
|
offers.push({ fake_offer: 'fake_offer_' + i })
|
|
|
|
}
|
|
|
|
process.nextTick(function () {
|
|
|
|
cb(offers)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|