]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add debug messages to webtorrent tests
authorChocobozzz <me@florianbigard.com>
Thu, 2 Sep 2021 07:53:27 +0000 (09:53 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 2 Sep 2021 07:55:48 +0000 (09:55 +0200)
shared/extra-utils/miscs/webtorrent.ts

index 8fe2ad82160785ca2571820de860a971b053f3cc..b610fdda8a3bb80e8ef667c5401c86314d6ac4b9 100644 (file)
@@ -7,13 +7,28 @@ import { PeerTubeServer } from '../server'
 
 let webtorrent: WebTorrent.Instance
 
-function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
+function webtorrentAdd (torrentId: string, refreshWebTorrent = false) {
   const WebTorrent = require('webtorrent')
 
   if (!webtorrent) webtorrent = new WebTorrent()
   if (refreshWebTorrent === true) webtorrent = new WebTorrent()
 
-  return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
+  webtorrent.on('error', err => console.error('Error in webtorrent', err))
+
+  return new Promise<WebTorrent.Torrent>(res => {
+    const torrent = webtorrent.add(torrentId, res)
+
+    torrent.on('error', err => console.error('Error in webtorrent torrent', err))
+    torrent.on('warning', warn => {
+      const msg = typeof warn === 'string'
+        ? warn
+        : warn.message
+
+      if (msg.includes('Unsupported')) return
+
+      console.error('Warning in webtorrent torrent', warn)
+    })
+  })
 }
 
 async function parseTorrentVideo (server: PeerTubeServer, file: VideoFile) {