diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-03-16 22:29:27 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-03-16 22:29:27 +0100 |
commit | f0f5567b6918fc60c8cab15e13aec03a89a91dfb (patch) | |
tree | 99dfdb9fa8273c9cda1360fd3b6bfccc515bf8be /server/lib/webtorrent.js | |
parent | 5101105ef91bfe478f97546b78b321882da2079c (diff) | |
download | PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.gz PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.zst PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.zip |
Use const/let now we use node 4.2
Diffstat (limited to 'server/lib/webtorrent.js')
-rw-r--r-- | server/lib/webtorrent.js | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/server/lib/webtorrent.js b/server/lib/webtorrent.js index cb641fead..455b086a3 100644 --- a/server/lib/webtorrent.js +++ b/server/lib/webtorrent.js | |||
@@ -1,20 +1,20 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | var config = require('config') | 3 | const config = require('config') |
4 | var ipc = require('node-ipc') | 4 | const ipc = require('node-ipc') |
5 | var pathUtils = require('path') | 5 | const pathUtils = require('path') |
6 | var spawn = require('electron-spawn') | 6 | const spawn = require('electron-spawn') |
7 | 7 | ||
8 | var logger = require('../helpers/logger') | 8 | const logger = require('../helpers/logger') |
9 | 9 | ||
10 | var host = config.get('webserver.host') | 10 | let host = config.get('webserver.host') |
11 | var port = config.get('webserver.port') | 11 | let port = config.get('webserver.port') |
12 | var nodeKey = 'webtorrentnode' + port | 12 | let nodeKey = 'webtorrentnode' + port |
13 | var processKey = 'webtorrentprocess' + port | 13 | let processKey = 'webtorrentprocess' + port |
14 | ipc.config.silent = true | 14 | ipc.config.silent = true |
15 | ipc.config.id = nodeKey | 15 | ipc.config.id = nodeKey |
16 | 16 | ||
17 | var webtorrent = { | 17 | const webtorrent = { |
18 | add: add, | 18 | add: add, |
19 | app: null, // Pid of the app | 19 | app: null, // Pid of the app |
20 | create: create, | 20 | create: create, |
@@ -42,7 +42,7 @@ function create (options, callback) { | |||
42 | if (!webtorrent.silent) logger.info('IPC server ready.') | 42 | if (!webtorrent.silent) logger.info('IPC server ready.') |
43 | 43 | ||
44 | // Run a timeout of 30s after which we exit the process | 44 | // Run a timeout of 30s after which we exit the process |
45 | var timeout_webtorrent_process = setTimeout(function () { | 45 | const timeout_webtorrent_process = setTimeout(function () { |
46 | throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.') | 46 | throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.') |
47 | }, 30000) | 47 | }, 30000) |
48 | 48 | ||
@@ -56,7 +56,7 @@ function create (options, callback) { | |||
56 | throw new Error('Received exception error from webtorrent process.' + data.exception) | 56 | throw new Error('Received exception error from webtorrent process.' + data.exception) |
57 | }) | 57 | }) |
58 | 58 | ||
59 | var webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true }) | 59 | const webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true }) |
60 | webtorrent_process.stderr.on('data', function (data) { | 60 | webtorrent_process.stderr.on('data', function (data) { |
61 | // logger.debug('Webtorrent process stderr: ', data.toString()) | 61 | // logger.debug('Webtorrent process stderr: ', data.toString()) |
62 | }) | 62 | }) |
@@ -72,9 +72,9 @@ function create (options, callback) { | |||
72 | } | 72 | } |
73 | 73 | ||
74 | function seed (path, callback) { | 74 | function seed (path, callback) { |
75 | var extension = pathUtils.extname(path) | 75 | const extension = pathUtils.extname(path) |
76 | var basename = pathUtils.basename(path, extension) | 76 | const basename = pathUtils.basename(path, extension) |
77 | var data = { | 77 | const data = { |
78 | _id: basename, | 78 | _id: basename, |
79 | args: { | 79 | args: { |
80 | path: path | 80 | path: path |
@@ -84,12 +84,12 @@ function seed (path, callback) { | |||
84 | if (!webtorrent.silent) logger.debug('Node wants to seed %s.', data._id) | 84 | if (!webtorrent.silent) logger.debug('Node wants to seed %s.', data._id) |
85 | 85 | ||
86 | // Finish signal | 86 | // Finish signal |
87 | var event_key = nodeKey + '.seedDone.' + data._id | 87 | const event_key = nodeKey + '.seedDone.' + data._id |
88 | ipc.server.on(event_key, function listener (received) { | 88 | ipc.server.on(event_key, function listener (received) { |
89 | if (!webtorrent.silent) logger.debug('Process seeded torrent %s.', received.magnetUri) | 89 | if (!webtorrent.silent) logger.debug('Process seeded torrent %s.', received.magnetUri) |
90 | 90 | ||
91 | // This is a fake object, we just use the magnetUri in this project | 91 | // This is a fake object, we just use the magnetUri in this project |
92 | var torrent = { | 92 | const torrent = { |
93 | magnetURI: received.magnetUri | 93 | magnetURI: received.magnetUri |
94 | } | 94 | } |
95 | 95 | ||
@@ -101,7 +101,7 @@ function seed (path, callback) { | |||
101 | } | 101 | } |
102 | 102 | ||
103 | function add (magnetUri, callback) { | 103 | function add (magnetUri, callback) { |
104 | var data = { | 104 | const data = { |
105 | _id: magnetUri, | 105 | _id: magnetUri, |
106 | args: { | 106 | args: { |
107 | magnetUri: magnetUri | 107 | magnetUri: magnetUri |
@@ -111,12 +111,12 @@ function add (magnetUri, callback) { | |||
111 | if (!webtorrent.silent) logger.debug('Node wants to add ' + data._id) | 111 | if (!webtorrent.silent) logger.debug('Node wants to add ' + data._id) |
112 | 112 | ||
113 | // Finish signal | 113 | // Finish signal |
114 | var event_key = nodeKey + '.addDone.' + data._id | 114 | const event_key = nodeKey + '.addDone.' + data._id |
115 | ipc.server.on(event_key, function (received) { | 115 | ipc.server.on(event_key, function (received) { |
116 | if (!webtorrent.silent) logger.debug('Process added torrent.') | 116 | if (!webtorrent.silent) logger.debug('Process added torrent.') |
117 | 117 | ||
118 | // This is a fake object, we just use the magnetUri in this project | 118 | // This is a fake object, we just use the magnetUri in this project |
119 | var torrent = { | 119 | const torrent = { |
120 | files: received.files | 120 | files: received.files |
121 | } | 121 | } |
122 | 122 | ||
@@ -128,7 +128,7 @@ function add (magnetUri, callback) { | |||
128 | } | 128 | } |
129 | 129 | ||
130 | function remove (magnetUri, callback) { | 130 | function remove (magnetUri, callback) { |
131 | var data = { | 131 | const data = { |
132 | _id: magnetUri, | 132 | _id: magnetUri, |
133 | args: { | 133 | args: { |
134 | magnetUri: magnetUri | 134 | magnetUri: magnetUri |
@@ -138,11 +138,11 @@ function remove (magnetUri, callback) { | |||
138 | if (!webtorrent.silent) logger.debug('Node wants to stop seeding %s.', data._id) | 138 | if (!webtorrent.silent) logger.debug('Node wants to stop seeding %s.', data._id) |
139 | 139 | ||
140 | // Finish signal | 140 | // Finish signal |
141 | var event_key = nodeKey + '.removeDone.' + data._id | 141 | const event_key = nodeKey + '.removeDone.' + data._id |
142 | ipc.server.on(event_key, function (received) { | 142 | ipc.server.on(event_key, function (received) { |
143 | if (!webtorrent.silent) logger.debug('Process removed torrent %s.', data._id) | 143 | if (!webtorrent.silent) logger.debug('Process removed torrent %s.', data._id) |
144 | 144 | ||
145 | var err = null | 145 | let err = null |
146 | if (received.err) err = received.err | 146 | if (received.err) err = received.err |
147 | 147 | ||
148 | ipc.server.off(event_key) | 148 | ipc.server.off(event_key) |