diff --git a/package.json b/package.json
index 9efee0284f..f4e803a13b 100644
--- a/package.json
+++ b/package.json
@@ -60,6 +60,7 @@
"nodecast-js": "^1.0.1",
"opensubtitles-api": "^3.1.0",
"peerflix": "^0.35.0",
+ "webtorrent": "0.97.2",
"q": "2.0.3",
"read-torrent": "1.3.0",
"readdirp": "*",
diff --git a/src/app/global.js b/src/app/global.js
index 70b2a75fed..ffd6e56436 100644
--- a/src/app/global.js
+++ b/src/app/global.js
@@ -57,6 +57,5 @@ var
// Torrent engines
peerflix = require('peerflix'),
-
// NodeJS
child = require('child_process');
diff --git a/src/app/settings.js b/src/app/settings.js
index 1819fbbe46..5efa1476f1 100644
--- a/src/app/settings.js
+++ b/src/app/settings.js
@@ -149,6 +149,7 @@ Settings.tmpLocation = path.join(os.tmpDir(), Settings.projectName);
Settings.databaseLocation = path.join(data_path, 'data');
Settings.deleteTmpOnClose = true;
Settings.automaticUpdating = true;
+Settings.UpdateSeed = true;
Settings.events = true;
Settings.minimizeToTray = false;
Settings.bigPicture = false;
diff --git a/src/app/templates/settings-container.tpl b/src/app/templates/settings-container.tpl
index 140be63bff..5402a28c3f 100644
--- a/src/app/templates/settings-container.tpl
+++ b/src/app/templates/settings-container.tpl
@@ -556,8 +556,12 @@
- >
-
+ >
+
+
+
+ >
+
>
diff --git a/src/app/updater.js b/src/app/updater.js
index 105b940b0d..51b29e6a7f 100644
--- a/src/app/updater.js
+++ b/src/app/updater.js
@@ -3,6 +3,8 @@
var CHANNELS = ['stable', 'beta', 'nightly'],
FILENAME = 'package.nw.new',
+ WebTorrent = require('webtorrent'),
+ client = new WebTorrent({dht: true,maxConns: '5'}),
VERIFY_PUBKEY = Settings.updateKey;
function forcedBind(func, thisVar) {
@@ -19,7 +21,7 @@
var self = this;
this.options = _.defaults(options || {}, {
- endpoint: AdvSettings.get('updateEndpoint').url + 'update3.json' + '?version=' + App.settings.version + '&nwversion=' + process.versions['node-webkit'],
+ endpoint: AdvSettings.get('updateEndpoint').url + 'p2pudpate.json' + '?version=' + App.settings.version + '&nwversion=' + process.versions['node-webkit'],
channel: 'beta'
});
@@ -77,21 +79,44 @@
self.updateData = updateData;
return true;
}
+ if (App.settings.UpdateSeed) {
+ client.add(updateData.UpdateUrl, { path: os.tmpdir() }, function (torrent) {
+ torrent.on('error', function (err) {
+ win.debug('ERROR' + err.message);
+ });
+ torrent.on('done', function () {
+ win.debug('Seeding the Current Update!');
+ });
+ });
+ }
win.debug('Not updating because we are running the latest version');
return false;
});
};
-
- Updater.prototype.download = function (source, output) {
+
+
+ Updater.prototype.download = function (source, outputDir) {
var defer = Q.defer();
- var downloadStream = request(source);
- win.debug('Downloading update... Please allow a few minutes');
- downloadStream.pipe(fs.createWriteStream(output));
- downloadStream.on('complete', function () {
- win.debug('Update downloaded!');
- defer.resolve(output);
+ client.on('error', function (err) {
+ win.debug('ERROR: ' + err.message);
+ defer.reject(err);
});
+
+ client.add(source, {
+ path: outputDir
+ }, function (torrent) {
+ win.debug('Downloading update... Please allow a few minutes');
+ torrent.on('error', function (err) {
+ win.debug('ERROR' + err.message);
+ defer.reject(err);
+ });
+ torrent.on('done', function () {
+ win.debug('Update downloaded!');
+ defer.resolve(path.join(outputDir, torrent.name));
+ });
+ });
+
return defer.promise;
};