From fbcd44d2333bdd093334a90fd99f6d99bfd72744 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 2 Sep 2021 09:53:27 +0200 Subject: [PATCH] Add debug messages to webtorrent tests --- shared/extra-utils/miscs/webtorrent.ts | 19 +++++++++++++++++-- 1 file 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' 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(res => webtorrent.add(torrent, res)) + webtorrent.on('error', err => console.error('Error in webtorrent', err)) + + return new Promise(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) {