aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/miscs/webtorrent.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/miscs/webtorrent.ts')
-rw-r--r--shared/extra-utils/miscs/webtorrent.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/shared/extra-utils/miscs/webtorrent.ts b/shared/extra-utils/miscs/webtorrent.ts
index 8fe2ad821..b610fdda8 100644
--- a/shared/extra-utils/miscs/webtorrent.ts
+++ b/shared/extra-utils/miscs/webtorrent.ts
@@ -7,13 +7,28 @@ import { PeerTubeServer } from '../server'
7 7
8let webtorrent: WebTorrent.Instance 8let webtorrent: WebTorrent.Instance
9 9
10function webtorrentAdd (torrent: string, refreshWebTorrent = false) { 10function webtorrentAdd (torrentId: string, refreshWebTorrent = false) {
11 const WebTorrent = require('webtorrent') 11 const WebTorrent = require('webtorrent')
12 12
13 if (!webtorrent) webtorrent = new WebTorrent() 13 if (!webtorrent) webtorrent = new WebTorrent()
14 if (refreshWebTorrent === true) webtorrent = new WebTorrent() 14 if (refreshWebTorrent === true) webtorrent = new WebTorrent()
15 15
16 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) 16 webtorrent.on('error', err => console.error('Error in webtorrent', err))
17
18 return new Promise<WebTorrent.Torrent>(res => {
19 const torrent = webtorrent.add(torrentId, res)
20
21 torrent.on('error', err => console.error('Error in webtorrent torrent', err))
22 torrent.on('warning', warn => {
23 const msg = typeof warn === 'string'
24 ? warn
25 : warn.message
26
27 if (msg.includes('Unsupported')) return
28
29 console.error('Warning in webtorrent torrent', warn)
30 })
31 })
17} 32}
18 33
19async function parseTorrentVideo (server: PeerTubeServer, file: VideoFile) { 34async function parseTorrentVideo (server: PeerTubeServer, file: VideoFile) {