REVERT: I'm not proud
This is slow af Definitely needs more work
This commit is contained in:
@@ -1,12 +1,63 @@
|
||||
"use strict";
|
||||
|
||||
class trdom_torrentmanager {
|
||||
class trdom_torrentmanager extends EventTarget {
|
||||
#logcb;
|
||||
#log(loglevel, msg) {
|
||||
if (this.#logcb !== null) {
|
||||
this.#logcb('trdom_torrentmanager', loglevel, msg);
|
||||
}
|
||||
}
|
||||
|
||||
#element = document.createElement('div');
|
||||
getElement() {
|
||||
return this.#element;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
#torrentDB = {};
|
||||
get torrents() {
|
||||
return this.#torrentDB;
|
||||
}
|
||||
|
||||
constructor(logcb = null) {
|
||||
super();
|
||||
this.#logcb = logcb;
|
||||
this.#element.classList.add('trweb_torrentlistview', 'container-fluid');
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user