Skip to content

Commit

Permalink
BREAKING CHANGE: Update WebTorrent to v2 and drop NodeJS < 16 (#303)
Browse files Browse the repository at this point in the history
* BREAKING CHANGE: Update WebTorrent to v2 and drop support for NodeJS < 16

* feat: update create-torrent to 6.0.17

* feat: improve logging by including peer type (TCP,UTP,WEBRTC,WEBSEED)

* fix: update ci to drop NodeJS 14

* fix: update docs to reflect changes, adds webrtc connectivity but requires native deps.
  • Loading branch information
SilentBot1 committed Jun 2, 2024
1 parent 35939c9 commit 3e34c7f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
os:
- ubuntu-latest
node:
- '14'
- '16'
- '18'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@
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).

### Features

- **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)
Expand Down
43 changes: 36 additions & 7 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand All @@ -43,7 +43,7 @@
"xtend": "4.0.2"
},
"engines": {
"node": ">=12.20.0"
"node": ">=16"
},
"exports": {
"./bin/cmd.js": "./bin/cmd.js"
Expand Down

0 comments on commit 3e34c7f

Please sign in to comment.