Skip to content

Commit

Permalink
lazy-load WebTorrentRemoteServer
Browse files Browse the repository at this point in the history
  • Loading branch information
dcposch committed Nov 29, 2016
1 parent 05692a3 commit 540f029
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/browser/webtorrent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const electron = require('electron')
const ipc = electron.ipcMain
const messages = require('../../js/constants/messages')
const WebTorrentRemoteServer = require('webtorrent-remote/server')

module.exports = {init}

Expand All @@ -17,8 +16,11 @@ let channels = {}
// Receive messages via the window process, ultimately from the UI in a <webview> process
function init () {
if (DEBUG_IPC) console.log('WebTorrent IPC init')
server = new WebTorrentRemoteServer(send, {trace: DEBUG_IPC})
ipc.on(messages.TORRENT_MESSAGE, function (e, msg) {
if (server === null) {
const WebTorrentRemoteServer = require('webtorrent-remote/server')
server = new WebTorrentRemoteServer(send, {trace: DEBUG_IPC})
}
if (DEBUG_IPC) console.log('Received IPC: ' + JSON.stringify(msg))
channels[msg.clientKey] = e.sender
server.receive(msg)
Expand Down

0 comments on commit 540f029

Please sign in to comment.