mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-09-19 17:46:33 +00:00
use aether-torrent to persist files in indexedDB!!! p2p youtube
This commit is contained in:
parent
8c1dae269b
commit
d06a09706b
@ -49,6 +49,7 @@
|
||||
"dependencies": {
|
||||
"@walletconnect/web3-provider": "^1.7.8",
|
||||
"@zxing/library": "^0.18.6",
|
||||
"aether-torrent": "^0.3.0",
|
||||
"autolinker": "^3.14.3",
|
||||
"elliptic": "^6.5.4",
|
||||
"fuse.js": "^6.6.2",
|
||||
@ -69,8 +70,7 @@
|
||||
"react-helmet": "^6.1.0",
|
||||
"react-virtualized": "^9.22.3",
|
||||
"web3": "^1.7.4",
|
||||
"web3modal": "^1.9.8",
|
||||
"webtorrent": "^1.5.1"
|
||||
"web3modal": "^1.9.8"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "jest-preset-preact",
|
||||
|
@ -1999,14 +1999,6 @@ export default {
|
||||
}, 10);
|
||||
},
|
||||
|
||||
async getWebTorrentClient() {
|
||||
const { default: WebTorrent } = await import('webtorrent');
|
||||
if (!this.wtClient) {
|
||||
this.wtClient = new WebTorrent();
|
||||
}
|
||||
return this.wtClient;
|
||||
},
|
||||
|
||||
getProfileLink(pub: string): string {
|
||||
return `${window.location.origin}/#/profile/${encodeURIComponent(pub)}`;
|
||||
},
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { Component } from 'preact';
|
||||
import Helpers from '../Helpers';
|
||||
import { html } from 'htm/preact';
|
||||
import State from '../State';
|
||||
import Icons from '../Icons';
|
||||
@ -62,12 +61,13 @@ class MediaPlayer extends Component {
|
||||
}
|
||||
|
||||
async startTorrenting() {
|
||||
const client = await Helpers.getWebTorrentClient();
|
||||
const { default: AetherTorrent } = await import('aether-torrent');
|
||||
const client = new AetherTorrent();
|
||||
const existing = client.get(this.torrentId);
|
||||
if (existing) {
|
||||
this.onTorrent(existing);
|
||||
} else {
|
||||
client.add(this.torrentId, t => this.onTorrent(t));
|
||||
client.add(this.torrentId, (e, t) => this.onTorrent(t));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,12 +53,13 @@ class Torrent extends Component {
|
||||
async startTorrenting(clicked) {
|
||||
this.setState({torrenting: true});
|
||||
const torrentId = this.props.torrentId;
|
||||
const client = await Helpers.getWebTorrentClient();
|
||||
const { default: AetherTorrent } = await import('aether-torrent');
|
||||
const client = new AetherTorrent();
|
||||
const existing = client.get(torrentId);
|
||||
if (existing) {
|
||||
this.onTorrent(existing, clicked);
|
||||
} else {
|
||||
client.add(torrentId, t => this.onTorrent(t, clicked));
|
||||
client.add(torrentId, (err, t) => t && !err && this.onTorrent(t, clicked));
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,6 +170,10 @@ class Torrent extends Component {
|
||||
onTorrent(torrent, clicked) {
|
||||
if (!this.coverRef.current) { return; }
|
||||
this.torrent = torrent;
|
||||
if (!torrent.files) {
|
||||
console.error("no torrent.files", torrent);
|
||||
return;
|
||||
}
|
||||
const video = torrent.files.find(f => isVideo(f));
|
||||
const audio = torrent.files.find(f => isAudio(f));
|
||||
const img = torrent.files.find(f => isImage(f));
|
||||
|
Loading…
Reference in New Issue
Block a user