WebTorrent supporting judgement

This commit is contained in:
DIYgod 2018-01-19 17:38:44 +08:00
parent 5a12be0554
commit 8e69adab3c
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
1 changed files with 15 additions and 10 deletions

View File

@ -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.');