2025-10-09 10:06:29 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
2025-10-09 15:42:31 +02:00
|
|
|
class trdom_torrentmanager extends EventTarget {
|
|
|
|
|
#logcb;
|
|
|
|
|
#log(loglevel, msg) {
|
|
|
|
|
if (this.#logcb !== null) {
|
|
|
|
|
this.#logcb('trdom_torrentmanager', loglevel, msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-09 10:06:29 +02:00
|
|
|
#element = document.createElement('div');
|
|
|
|
|
getElement() {
|
|
|
|
|
return this.#element;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-09 15:42:31 +02:00
|
|
|
#torrentDB = {};
|
|
|
|
|
get torrents() {
|
|
|
|
|
return this.#torrentDB;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(logcb = null) {
|
|
|
|
|
super();
|
|
|
|
|
this.#logcb = logcb;
|
2025-10-09 10:06:29 +02:00
|
|
|
this.#element.classList.add('trweb_torrentlistview', 'container-fluid');
|
|
|
|
|
}
|
2025-10-09 15:42:31 +02:00
|
|
|
|
|
|
|
|
handleEvent(e) {
|
|
|
|
|
this.#log(6, `Handling event of type ${e.type}`);
|
|
|
|
|
switch (e.type) {
|
|
|
|
|
// if we get info of a torrent that we don't have in the DB, create it,
|
|
|
|
|
// then alert trdom_servermanager so it can add server controls to it
|
|
|
|
|
// that'll also handle alerting trtorrents of new servers
|
|
|
|
|
case 'torrent-update':
|
|
|
|
|
let hash = e.detail.torrentHash;
|
|
|
|
|
if (this.#torrentDB[hash] == null) {
|
|
|
|
|
let torrent = new trtorrent(hash);
|
|
|
|
|
this.#torrentDB[hash] = torrent;
|
|
|
|
|
this.#element.appendChild(torrent.element);
|
|
|
|
|
this.dispatchEvent(new CustomEvent(
|
|
|
|
|
'torrent-created',
|
|
|
|
|
{
|
|
|
|
|
detail: {
|
|
|
|
|
torrentHash: hash,
|
|
|
|
|
torrentObject: torrent,
|
|
|
|
|
torrentInfo: e.detail.torrentInfo,
|
|
|
|
|
serverName: e.detail.serverName,
|
|
|
|
|
serverObject: e.detail.serverObject
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'torrentserver-added':
|
|
|
|
|
let server = e.detail.serverObject;
|
|
|
|
|
// see this handler
|
|
|
|
|
server.addEventListener('torrent-update', this);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
this.#log(5, `Event type ${e.type} not supported`);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-09 10:06:29 +02:00
|
|
|
}
|