Browse Source

WebTorrent supporting judgement

DIYgod 7 years ago
parent
commit
8e69adab3c
1 changed files with 15 additions and 10 deletions
  1. 15 10
      src/js/player.js

+ 15 - 10
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.');