From c13f9712d17ac820e41a8fb2d100374e24bf2d2d Mon Sep 17 00:00:00 2001 From: Alex Kern Date: Wed, 12 Aug 2015 03:35:06 -0700 Subject: [PATCH] Extract webtorrent client in a module. --- lib/stores/DownloadStore.js | 5 ++--- lib/stores/UploadStore.js | 5 ++--- lib/webtorrent.js | 3 +++ 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 lib/webtorrent.js diff --git a/lib/stores/DownloadStore.js b/lib/stores/DownloadStore.js index ffabbd5..786b406 100644 --- a/lib/stores/DownloadStore.js +++ b/lib/stores/DownloadStore.js @@ -1,5 +1,5 @@ import DownloadActions from '../actions/DownloadActions' -import WebTorrent from 'webtorrent' +import webtorrent from '../webtorrent' import alt from '../alt' import socket from 'filepizza-socket' @@ -34,8 +34,7 @@ export default alt.createStore(class DownloadStore { if (this.status !== 'ready') return this.status = 'requesting' - const client = new WebTorrent() - client.download(this.infoHash, (torrent) => { + webtorrent.download(this.infoHash, (torrent) => { this.setState({ status: 'downloading' }) const updateSpeed = () => { diff --git a/lib/stores/UploadStore.js b/lib/stores/UploadStore.js index 3f37d37..510974d 100644 --- a/lib/stores/UploadStore.js +++ b/lib/stores/UploadStore.js @@ -1,7 +1,7 @@ import UploadActions from '../actions/UploadActions' import alt from '../alt' import socket from 'filepizza-socket' -import WebTorrent from 'webtorrent' +import webtorrent from '../webtorrent' const SPEED_REFRESH_TIME = 2000 @@ -24,8 +24,7 @@ export default alt.createStore(class UploadStore { if (this.status !== 'ready') return this.status = 'processing' - const client = new WebTorrent() - client.seed(file, (torrent) => { + webtorrent.seed(file, (torrent) => { const updateSpeed = () => { this.setState({ diff --git a/lib/webtorrent.js b/lib/webtorrent.js new file mode 100644 index 0000000..6ee6237 --- /dev/null +++ b/lib/webtorrent.js @@ -0,0 +1,3 @@ +import WebTorrent from 'webtorrent' + +export default new WebTorrent({})