Skip to content

Commit

Permalink
Use new webrtc for bittorrent, improve magnet parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauve Signweaver committed Sep 25, 2024
1 parent 5100ebb commit 9e03185
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 283 deletions.
2 changes: 1 addition & 1 deletion app/protocols/bt-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default async function createHandler (options, session) {
// This enables webtorrent-hybrid functionality
// https://github.com/webtorrent/webtorrent-hybrid/blob/v4.1.3/lib/global.js
const { default: createTorrent } = await import('create-torrent')
const { default: wrtc } = await import('wrtc')
const { default: wrtc } = await import('@roamhq/wrtc')
globalThis.WEBTORRENT_ANNOUNCE = createTorrent.announceList
.map(arr => arr[0])
.filter(url => url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0)
Expand Down
18 changes: 10 additions & 8 deletions app/protocols/magnet-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ export default async function createHandler () {

if (xs) {
const match = PUBLIC_KEY_MATCH.exec(xs)
if (!match) {
return sendError('Magnet has no bittorrent infohash')
if (match) {
const publicKey = match[1]
const final = `bittorrent://${publicKey}`
sendFinal(final)
return
}
const publicKey = match[1]
const final = `bittorrent://${publicKey}`
sendFinal(final)
} else if (xt) {
}
if (xt) {
const match = INFO_HASH_MATCH.exec(xt)
if (!match) {
return sendError('Magnet has no bittorrent infohash')
}
const infohash = match[1]
const final = `bittorrent://${infohash}/`
sendFinal(final)
} else {
return sendError('Magnet link has no `xt` or `xs` parameter')
return
}

return sendError('Magnet link has no `xt` or `xs` parameter')
} catch (e) {
sendError(e.stack)
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"standard": "^17.0.0"
},
"dependencies": {
"@roamhq/wrtc": "^0.8.0",
"abort-controller": "^3.0.0",
"bt-fetch": "^3.1.1",
"create-desktop-shortcuts": "^1.7.0",
Expand All @@ -212,7 +213,6 @@
"scoped-fs": "^1.4.1",
"semver": "^7.5.2",
"ssb-fetch": "^1.5.2",
"whatwg-mimetype": "https://github.com/jsdom/whatwg-mimetype#v2.3.0",
"wrtc": "^0.4.7"
"whatwg-mimetype": "https://github.com/jsdom/whatwg-mimetype#v2.3.0"
}
}
}
Loading

0 comments on commit 9e03185

Please sign in to comment.