'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

This commit is contained in:
Feross Aboukhadijeh 2019-07-04 21:41:39 -07:00
parent 2c3058294b
commit c37aac7277

View File

@ -5,7 +5,7 @@ const once = require('once')
const parallel = require('run-parallel')
const Peer = require('simple-peer')
const uniq = require('uniq')
const url = require('url')
const URL = require('url').URL
const common = require('./lib/common')
const HTTPTracker = require('./lib/client/http-tracker') // empty object in browser
@ -85,7 +85,14 @@ class Client extends EventEmitter {
this._trackers = announce
.map(announceUrl => {
const parsedUrl = url.parse(announceUrl)
let parsedUrl
try {
parsedUrl = new URL(announceUrl)
} catch (err) {
nextTickWarn(new Error(`Invalid tracker URL: ${announceUrl}`))
return null
}
const port = parsedUrl.port
if (port < 0 || port > 65535) {
nextTickWarn(new Error(`Invalid tracker port: ${announceUrl}`))