From f64ff1b030f202234c2b10683e634f52496746bb Mon Sep 17 00:00:00 2001 From: Torjus Date: Thu, 26 Jul 2018 16:33:20 +0200 Subject: [PATCH] Share WebTorrent client between multiple components --- app/lib/components/Chat/Chat.jsx | 12 ++++++++++-- app/lib/components/Chat/FileChatEntry.jsx | 9 +-------- app/lib/components/Chat/FileSharing.jsx | 4 +--- app/lib/components/Chat/MessageList.jsx | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/lib/components/Chat/Chat.jsx b/app/lib/components/Chat/Chat.jsx index 87480ee..620e6e4 100644 --- a/app/lib/components/Chat/Chat.jsx +++ b/app/lib/components/Chat/Chat.jsx @@ -5,9 +5,17 @@ import * as stateActions from '../../redux/stateActions'; import * as requestActions from '../../redux/requestActions'; import MessageList from './MessageList'; import FileSharing from './FileSharing'; +import WebTorrent from 'webtorrent'; class Chat extends Component { + constructor(props) + { + super(props); + + this.client = new WebTorrent(); + } + render() { const { @@ -21,9 +29,9 @@ class Chat extends Component return (
- + - +
+ this.props.client.add(this.props.message.file.magnet, (torrent) => { const onProgress = () => { diff --git a/app/lib/components/Chat/FileSharing.jsx b/app/lib/components/Chat/FileSharing.jsx index 650dfec..f2d7514 100644 --- a/app/lib/components/Chat/FileSharing.jsx +++ b/app/lib/components/Chat/FileSharing.jsx @@ -17,11 +17,9 @@ class FileSharing extends Component { componentDidMount() { - this.client = new WebTorrent(); - dragDrop('body', (files) => { - this.client.seed(files, (torrent) => { + this.props.client.seed(files, (torrent) => { this.notifyPeers({ magnet: torrent.magnetURI }); diff --git a/app/lib/components/Chat/MessageList.jsx b/app/lib/components/Chat/MessageList.jsx index ed38979..4610b80 100644 --- a/app/lib/components/Chat/MessageList.jsx +++ b/app/lib/components/Chat/MessageList.jsx @@ -74,7 +74,7 @@ class MessageList extends Component )} {message.type === 'file' && ( - + )}