Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[node] Using nodejs even emitter framework
- Loading branch information
Showing
2 changed files
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
var swig = require('./jlibtorrent.node'); | ||
const EventEmitter = require('events'); | ||
const util = require('util'); | ||
|
||
const swig = require('./jlibtorrent.node'); | ||
|
||
// swig | ||
(function () { | ||
|
@@ -111,7 +114,7 @@ var swig = require('./jlibtorrent.node'); | |
return new swig.session(sp); | ||
} | ||
|
||
function alertsLoop(s) { | ||
function alertsLoop(emitter, s) { | ||
var session_alerts_loop = function () { | ||
var max_wait = swig.to_milliseconds(100); | ||
var alert = s.wait_for_alert(max_wait); | ||
|
@@ -122,7 +125,7 @@ var swig = require('./jlibtorrent.node'); | |
var size = vector.size(); | ||
for (var i = 0; i < size; i++) { | ||
var a = vector.get(i); | ||
console.log(a.type() + " - " + a.what() + " - " + a.message()); | ||
emitter.emit('alert', a); | ||
} | ||
vector.clear(); | ||
} | ||
|
@@ -132,14 +135,18 @@ var swig = require('./jlibtorrent.node'); | |
} | ||
|
||
function Session(settings, logging) { | ||
EventEmitter.call(this); | ||
|
||
settings = settings || new exports.SettingsPack(); | ||
logging = logging || false; | ||
|
||
this.s = createSession(settings, logging); | ||
|
||
alertsLoop(this.s); | ||
alertsLoop(this, this.s); | ||
} | ||
|
||
util.inherits(Session, EventEmitter); | ||
|
||
Session.prototype.swig = function () { | ||
return this.sp; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gubatron
Collaborator
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in this class I don't see where
this.sp
gets initialized.I only see this in the constructor:
I suppose
s
stands forsession
, andsp
forsession pointer
. My guess is that, after that assignment, maybe you wanted to do something like:this.sp = s.swig
or something similar.In the case of
SettingsPack
you pass thesp
in its constructor.https://github.com/frostwire/frostwire-jlibtorrent/blob/9c9b3580a9f7888746c6c49019a05a1215f0c140/node/jlibtorrent.js