no TURN server

This commit is contained in:
Feross Aboukhadijeh
2016-03-03 15:43:41 -08:00
parent edba6ce467
commit 8041e5faa3
3 changed files with 24 additions and 63 deletions

View File

@@ -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) {

View File

@@ -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))
}
}
})
}

View File

@@ -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",