"use strict"; 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; } #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) { case 'torrent-created': let initHash = e.detail.torrentHash; if (this.#torrentDB[initHash] == null) { let torrentCreated = new trtorrent(initHash); this.#torrentDB[initHash] = torrentCreated; this.#element.appendChild(torrentCreated.element); for (const [srv, control] of Object.entries(e.detail.torrentControls)) { torrentCreated.addControl(srv, control) } } else { this.#log(1, 'This event should never ever fire for a torrent that already exists'); window.alert('We be ded, check console'); } break; case 'torrentserver-added': let addedServer = e.detail.serverObject; for (const [hash, torrent] of Object.entries(this.#torrentDB)) { torrent.addControl(addedServer.name, new trdom_torrentcontrol(hash, addedServer, null, this.#logcb)) } break; default: this.#log(5, `Event type ${e.type} not supported`); break; } } }