Skip to content

Commit

Permalink
[node] Implemented SettingsPack.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Jan 28, 2016
1 parent 14a9cbf commit 8bb9cae
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
49 changes: 46 additions & 3 deletions node/jlibtorrent.js
Expand Up @@ -3,9 +3,7 @@ var swig = require('./jlibtorrent.node');
// swig
(function () {

exports.swig = {
swig: swig
}
exports.swig = swig;

}());

Expand Down Expand Up @@ -46,3 +44,48 @@ var swig = require('./jlibtorrent.node');
};

}());

// SettingsPack
(function () {

function SettingsPack(sp) {
this.sp = sp || new swig.settings_pack();
}

SettingsPack.prototype.swig = function () {
return this.sp;
}

SettingsPack.prototype.boolean = function (name, value) {
if (value) {
this.sp.set_bool(name, value);
} else {
value = this.sp.get_bool(name);
}

return value;
}

SettingsPack.prototype.integer = function (name, value) {
if (value) {
this.sp.set_int(name, value);
} else {
value = this.sp.get_int(name);
}

return value;
}

SettingsPack.prototype.string = function (name, value) {
if (value) {
this.sp.set_str(name, value);
} else {
value = this.sp.get_str(name);
}

return value;
}

exports.SettingsPack = SettingsPack;

}());
5 changes: 5 additions & 0 deletions node/session_test.js
Expand Up @@ -28,6 +28,11 @@ var jlibtorrent = require('./jlibtorrent.js');

console.log("Using libtorrent version: " + jlibtorrent.LibTorrent.fullVersion());

var sp = new jlibtorrent.SettingsPack();
var name = jlibtorrent.swig.settings_pack.peer_fingerprint;
sp.string(name, "test");
console.log(sp.string(name));

process.stdout.write('Press ENTER to exit...');
process.stdin.once('data', function (data) {
process.exit(0);
Expand Down

0 comments on commit 8bb9cae

Please sign in to comment.