From 8041e5faa3762dce7205737eb7a0513d136efebd Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 3 Mar 2016 15:43:41 -0800 Subject: [PATCH] no TURN server --- main/index.js | 44 ++++++++++++++++++++++-------------------- main/lib/get-client.js | 39 ------------------------------------- package.json | 4 +--- 3 files changed, 24 insertions(+), 63 deletions(-) delete mode 100644 main/lib/get-client.js diff --git a/main/index.js b/main/index.js index b3bf9823..8b42f8f3 100644 --- a/main/index.js +++ b/main/index.js @@ -2,21 +2,31 @@ var airplay = require('airplay-js') var chromecasts = require('chromecasts')() +var createTorrent = require('create-torrent') var dragDrop = require('drag-drop') var electron = require('electron') var networkAddress = require('network-address') var path = require('path') var throttle = require('throttleit') var torrentPoster = require('./lib/torrent-poster') -var getClient = require('./lib/get-client') +var WebTorrent = require('webtorrent') var createElement = require('virtual-dom/create-element') var diff = require('virtual-dom/diff') var patch = require('virtual-dom/patch') +var App = require('./views/app') + var HEADER_HEIGHT = 38 -var App = require('./views/app') +// Force use of webtorrent trackers on all torrents +global.WEBTORRENT_ANNOUNCE = createTorrent.announceList + .map(function (arr) { + return arr[0] + }) + .filter(function (url) { + return url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0 + }) var state = global.state = { server: null, @@ -26,7 +36,7 @@ var state = global.state = { }, view: { title: 'WebTorrent', - client: null, + client: null, // TODO: remove this from the view savedWindowBounds: null, history: [], historyIndex: 0, @@ -35,7 +45,7 @@ var state = global.state = { } } -var currentVDom, rootElement, updateThrottled +var client, currentVDom, rootElement, updateThrottled function init () { currentVDom = App(state, dispatch) @@ -44,13 +54,11 @@ function init () { updateThrottled = throttle(update, 1000) - getClient(function (err, client) { - if (err) return onError(err) - global.client = client - state.view.client = client - client.on('warning', onWarning) - client.on('error', onError) - }) + var client = new WebTorrent() + client.on('warning', onWarning) + client.on('error', onError) + + state.view.client = client dragDrop('body', onFiles) @@ -152,20 +160,14 @@ function isNotTorrentFile (file) { } function addTorrent (torrentId) { - getClient(function (err, client) { - if (err) return onError(err) - var torrent = client.add(torrentId) - addTorrentEvents(torrent) - }) + var torrent = client.add(torrentId) + addTorrentEvents(torrent) } function seed (files) { if (files.length === 0) return - getClient(function (err, client) { - if (err) return onError(err) - var torrent = client.seed(files) - addTorrentEvents(torrent) - }) + var torrent = client.seed(files) + addTorrentEvents(torrent) } function addTorrentEvents (torrent) { diff --git a/main/lib/get-client.js b/main/lib/get-client.js deleted file mode 100644 index c2bb5bad..00000000 --- a/main/lib/get-client.js +++ /dev/null @@ -1,39 +0,0 @@ -var createTorrent = require('create-torrent') -var thunky = require('thunky') -var WebTorrent = require('webtorrent') -var xhr = require('xhr') - -module.exports = thunky(getClient) - -global.WEBTORRENT_ANNOUNCE = createTorrent.announceList - .map(function (arr) { - return arr[0] - }) - .filter(function (url) { - return url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0 - }) - -function getClient (cb) { - getRtcConfig('https://instant.io/rtcConfig', function (err, rtcConfig) { - if (err) console.error(err) - var client = new WebTorrent({ rtcConfig: rtcConfig }) - cb(null, client) - }) -} - -function getRtcConfig (url, cb) { - xhr(url, function (err, res) { - if (err || res.statusCode !== 200) { - cb(new Error('Could not get WebRTC config from server. Using default (without TURN).')) - } else { - var rtcConfig - try { rtcConfig = JSON.parse(res.body) } catch (err) {} - if (rtcConfig) { - console.log('got rtc config: %o', rtcConfig) - cb(null, rtcConfig) - } else { - cb(new Error('Got invalid WebRTC config from server: ' + res.body)) - } - } - }) -} diff --git a/package.json b/package.json index fec9afc9..5ea97728 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,9 @@ "network-address": "^1.1.0", "pretty-bytes": "^3.0.0", "throttleit": "^1.0.0", - "thunky": "^0.1.0", "upload-element": "^1.0.1", "virtual-dom": "^2.1.1", - "webtorrent": "^0.82.0", - "xhr": "^2.2.0" + "webtorrent": "^0.82.0" }, "devDependencies": { "electron-packager": "^5.0.0",