Skip to content

Commit

Permalink
[node] Refactor for initial listener
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 3, 2016
1 parent d554b18 commit e2e4a1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion node/jlibtorrent.js
Expand Up @@ -134,14 +134,18 @@ const swig = require('./jlibtorrent.node');
setInterval(session_alerts_loop, 1000);
}

function Session(settings, logging) {
function Session(settings, logging, listener) {
EventEmitter.call(this);

settings = settings || new exports.SettingsPack();
logging = logging || false;

this.s = createSession(settings, logging);

if (listener) {
this.on('alert', listener);
}

alertsLoop(this, this.s);
}

Expand Down
10 changes: 5 additions & 5 deletions node/session_test.js
Expand Up @@ -2,12 +2,12 @@ const jlibtorrent = require('./jlibtorrent.js');

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

const sp = new jlibtorrent.SettingsPack();
const s = new jlibtorrent.Session(sp, false);

s.on('alert', function (a) {
const l = function (a) {
console.log(a.type() + " - " + a.what() + " - " + a.message());
});
}

const sp = new jlibtorrent.SettingsPack();
const s = new jlibtorrent.Session(sp, false, l);

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

0 comments on commit e2e4a1c

Please sign in to comment.