diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e54602e..23e8129 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,8 @@ jobs: os: - ubuntu-latest node: - - '14' - '16' + - '18' steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/README.md b/README.md index ed86d2b..40e5698 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,7 @@ i.e. *THIS PACKAGE*, is for using WebTorrent from the **command line**. `webtorrent-cli` is a simple torrent client for use in node.js, as a command line app. It -uses TCP and UDP to talk to other torrent clients. - -**NOTE**: To connect to "web peers" (browsers) in addition to normal BitTorrent peers, use -[`webtorrent-hybrid`](https://www.npmjs.com/package/webtorrent-hybrid) which includes WebRTC -support for node. +uses TCP, UDP and WebRTC to talk to other torrent clients. To use WebTorrent in the browser, see [`webtorrent`](https://www.npmjs.com/package/webtorrent). @@ -33,7 +29,6 @@ To use WebTorrent in the browser, see [`webtorrent`](https://www.npmjs.com/packa - **Use [WebTorrent](https://webtorrent.io) from the command line!** - **Insanely fast** -- **Pure Javascript** (no native dependencies) - Streaming - Stream to **AirPlay**, **Chromecast**, **VLC player**, **IINA**, and many other devices/players - Fetches pieces from the network on-demand so seeking is supported (even before torrent is finished) diff --git a/bin/cmd.js b/bin/cmd.js index b508b8b..e1020a4 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -353,7 +353,8 @@ async function runDownload (torrentId) { }) // Start http server - server = torrent.createServer() + const instance = client.createServer({}, 'node') + server = instance.server server.listen(argv.port) .on('error', err => { @@ -439,11 +440,11 @@ async function runDownload (torrentId) { if (typeof argv.select !== 'number') { index = 0 } - torrent.files.forEach((file, i) => allHrefs.push(JSON.stringify(`${href}/${i}/${encodeURIComponent(file.name)}`))) + torrent.files.forEach((file, i) => allHrefs.push(new URL(href + file.streamURL).toString())) // set the first file to the selected index allHrefs = allHrefs.slice(index, allHrefs.length).concat(allHrefs.slice(0, index)) } else { - href += `/${index}/${encodeURIComponent(torrent.files[index].name)}` + href = new URL(href + torrent.files[index].streamURL).toString() } if (playerName) { @@ -736,13 +737,41 @@ function drawTorrent (torrent) { : `${Math.floor(100 * bits / piececount)}%` } - let str = chalk`%s {magenta %s} %s {cyan %s} {red %s}` + let str = chalk`%s %s {magenta %s} %s {cyan %s} {red %s}` + let type = '' + + switch (wire.type) { + case 'webSeed': + type = 'WEBSEED' + break + case 'webrtc': + type = 'WEBRTC' + break + case 'tcpIncoming': + type = 'TCPIN' + break + case 'tcpOutgoing': + type = 'TCPOUT' + break + case 'utpIncoming': + type = 'UTPIN' + break + case 'utpOutgoing': + type = 'UTPOUT' + break + default: + type = 'UNKNOWN' + break + } + + const addr = (wire.remoteAddress + ? `${wire.remoteAddress}:${wire.remotePort}` + : 'Unknown') const args = [ progress.padEnd(3), - (wire.remoteAddress - ? `${wire.remoteAddress}:${wire.remotePort}` - : 'Unknown').padEnd(25), + type.padEnd(7), + addr.padEnd(32), prettierBytes(wire.downloaded).padEnd(10), (prettierBytes(wire.downloadSpeed()) + '/s').padEnd(12), (prettierBytes(wire.uploadSpeed()) + '/s').padEnd(12) diff --git a/package.json b/package.json index 638ef7a..ec03b5f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "dependencies": { "chalk": "^4.1.1", "common-tags": "^1.8.0", - "create-torrent": "^5.0.0", + "create-torrent": "^6.0.17", "dlnacasts": "^0.1.0", "ecstatic": "^4.1.4", "inquirer": "^8.2.2", @@ -29,7 +29,7 @@ "parse-torrent": "^9.1.3", "prettier-bytes": "^1.0.4", "vlc-command": "^1.2.0", - "webtorrent": "^1.3.2", + "webtorrent": "^2.3.0", "winreg": "^1.2.4", "yargs": "^17.0.1" }, @@ -43,7 +43,7 @@ "xtend": "4.0.2" }, "engines": { - "node": ">=12.20.0" + "node": ">=16" }, "exports": { "./bin/cmd.js": "./bin/cmd.js"