From e2e4a1c681430049dac28ae089270c3e4519c1cf Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 3 Feb 2016 15:14:00 -0500 Subject: [PATCH] [node] Refactor for initial listener --- node/jlibtorrent.js | 6 +++++- node/session_test.js | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/node/jlibtorrent.js b/node/jlibtorrent.js index aec5f51eb..45a9d8c8b 100644 --- a/node/jlibtorrent.js +++ b/node/jlibtorrent.js @@ -134,7 +134,7 @@ 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(); @@ -142,6 +142,10 @@ const swig = require('./jlibtorrent.node'); this.s = createSession(settings, logging); + if (listener) { + this.on('alert', listener); + } + alertsLoop(this, this.s); } diff --git a/node/session_test.js b/node/session_test.js index 8dfaf59bb..830ccc3b4 100644 --- a/node/session_test.js +++ b/node/session_test.js @@ -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) {