Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch authored and feross committed Nov 11, 2016
1 parent d51edea commit 548c863
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
31 changes: 15 additions & 16 deletions app/browser/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@ const ipc = electron.ipcMain
const messages = require('../../js/constants/messages')
const WebTorrentRemoteServer = require('webtorrent-remote/server')

var DEBUG_IPC = false // Set to see communication between WebTorrent and torrent viewer tabs
var ANNOUNCE = [
'wss://tracker.btorrent.xyz',
'wss://tracker.openwebtorrent.com',
'wss://tracker.fastcast.nz'
]
module.exports = {init}

// Set to see communication between WebTorrent and torrent viewer tabs
const DEBUG_IPC = false

// Connects to the BitTorrent network
// Communicates with the WebTorrentRemoteClients via message passing
var server = new WebTorrentRemoteServer(send, {
announce: ANNOUNCE
})
var channels = {}
let server = null
let channels = {}

// Receive messages via the window process, ultimately from the UI in a <webview> process
ipc.on(messages.TORRENT_MESSAGE, function (e, msg) {
if (DEBUG_IPC) console.log('Received IPC: ' + JSON.stringify(msg))
channels[msg.clientKey] = e.sender
server.receive(msg)
})
function init () {
server = new WebTorrentRemoteServer(send)
ipc.on(messages.TORRENT_MESSAGE, function (e, msg) {
if (DEBUG_IPC) console.log('Received IPC: ' + JSON.stringify(msg))
channels[msg.clientKey] = e.sender
server.receive(msg)
})
}

// Send messages from the browser process (here), thru the window process, to the <webview>
function send (msg) {
if (DEBUG_IPC) console.log('Sending IPC: ' + JSON.stringify(msg))
var channel = channels[msg.clientKey]
const channel = channels[msg.clientKey]
if (!channel) throw new Error('Unrecognized clientKey ' + msg.clientKey)
channel.send(messages.TORRENT_MESSAGE, msg)
}
3 changes: 2 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const basicAuth = require('./browser/basicAuth')
const async = require('async')
const tabs = require('./browser/tabs')
const settings = require('../js/constants/settings')
require('./browser/webtorrent')
const webtorrent = require('./browser/webtorrent')

// temporary fix for #4517, #4518 and #4472
app.commandLine.appendSwitch('enable-use-zoom-for-dsf', 'false')
Expand Down Expand Up @@ -432,6 +432,7 @@ app.on('ready', () => {
TrackingProtection.init()
AdBlock.init()
AdInsertion.init()
webtorrent.init()

if (!loadedPerWindowState || loadedPerWindowState.length === 0) {
if (!CmdLine.newWindowURL()) {
Expand Down
4 changes: 0 additions & 4 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,6 @@ class Frame extends ImmutableComponent {
if (typeof message.channelID !== 'string') {
throw new Error('Invalid or missing channelID: ' + JSON.stringify(message))
}
if (this.torrentChannelID && this.torrentChannelID !== message.channelID) {
throw new Error('ChannelID changed, expected ' + this.torrentChannelID +
': ' + JSON.stringify(message))
}
this.torrentChannelID = message.channelID
ipc.send(messages.TORRENT_MESSAGE, message)
}
Expand Down

0 comments on commit 548c863

Please sign in to comment.