2014-07-22 05:58:13 +00:00
|
|
|
var portfinder = require('portfinder')
|
|
|
|
var Server = require('../').Server
|
|
|
|
|
|
|
|
exports.createServer = function (t, serverType, cb) {
|
|
|
|
var opts = serverType === 'http' ? { udp: false } : { http: false }
|
|
|
|
var server = new Server(opts)
|
|
|
|
|
|
|
|
server.on('error', function (err) {
|
|
|
|
t.error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
server.on('warning', function (err) {
|
|
|
|
t.error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
portfinder.getPort(function (err, port) {
|
|
|
|
if (err) return t.error(err)
|
|
|
|
|
2014-07-24 02:16:23 +00:00
|
|
|
var announceUrl = serverType === 'http'
|
2014-07-22 05:58:13 +00:00
|
|
|
? 'http://127.0.0.1:' + port + '/announce'
|
|
|
|
: 'udp://127.0.0.1:' + port
|
|
|
|
|
|
|
|
server.listen(port)
|
|
|
|
cb(server, announceUrl)
|
|
|
|
})
|
|
|
|
}
|