Use EventTarget

Getting torrent info from servers now uses Events
instead of magic callbacks.
This commit is contained in:
2025-10-09 13:08:24 +02:00
parent 4986ee0ea5
commit b2f155c0b4
3 changed files with 59 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
"use strict";
class trserver {
class trserver extends EventTarget {
#rpcurl;
#authHeader;
#sessionHeader;
@@ -9,9 +9,18 @@ class trserver {
#isOnline = false;
#logger = function(msg) {};
#torrentCallback = function(hash, torrentInfo) {};
#torrentCallback = function(hash, torrentInfo) {
let e = new CustomEvent('torrent-update', {
'detail': {
'torrentHash': hash,
'torrentInfo': torrentInfo
}
});
this.dispatchEvent(e);
};
constructor (initdata, logger, tcb) {
constructor (initdata, logger = null, tcb = null) {
super();
this.#rpcurl = initdata.rpcurl;
if (logger != null) {
this.#logger = logger;