From 8e69adab3c02268b20d20043df36a036a07ba506 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 19 Jan 2018 17:38:44 +0800 Subject: [PATCH] WebTorrent supporting judgement --- src/js/player.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index c6ff50e..983e92e 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -374,17 +374,22 @@ class DPlayer { // https://github.com/webtorrent/webtorrent case 'webtorrent': if (WebTorrent) { - this.container.classList.add('dplayer-loading'); - const client = new WebTorrent(); - const torrentId = video.src; - client.add(torrentId, (torrent) => { - const file = torrent.files.find((file) => file.name.endsWith('.mp4')); - file.renderTo(this.video, { - autoplay: this.options.autoplay - }, () => { - this.container.classList.remove('dplayer-loading'); + if (WebTorrent.WEBRTC_SUPPORT) { + this.container.classList.add('dplayer-loading'); + const client = new WebTorrent(); + const torrentId = video.src; + client.add(torrentId, (torrent) => { + const file = torrent.files.find((file) => file.name.endsWith('.mp4')); + file.renderTo(this.video, { + autoplay: this.options.autoplay + }, () => { + this.container.classList.remove('dplayer-loading'); + }); }); - }); + } + else { + this.notice('Error: Webtorrent is not supported.'); + } } else { this.notice('Error: Can\'t find Webtorrent.');