package leenkx.logicnode; import leenkx.system.Event; #if js import leenkx.network.Leenkx; #end import iron.object.Object; class AddTorrentNode extends LogicNode { public var title: String; public var values: Array; public var net_Url: String; public var data: Dynamic; public var runner: Bool = false; public function new(tree:LogicTree) { super(tree); } public function promiseResult(connection,torrentid,net_Url){ #if js if (runner == false){ values = []; var script = 'var torrentId = "' + torrentid + '"; lx_' + net_Url +'.wt.add(torrentId, function (torrent) { leenkx.network.Leenkx.torrent.set("' + net_Url +'", torrent.files); torrent.on("done", function () { leenkx.network.Leenkx.connections.h["' + net_Url +'"].ontorrentdone(); }) }); '; js.Syntax.code('(1, eval)({0})', script.toString()); runner = true; promiseResult(connection,torrentid,net_Url); return; }else{ try{ values = leenkx.network.Leenkx.torrent.get(net_Url); if(values.length > 0){ runOutput(0); runner = false; return; } } catch(error){ haxe.Timer.delay(function () { promiseResult(connection,torrentid,net_Url); return; }, 100); } } #end } override function run(from:Int) { var connection = inputs[1].get(); if (connection == null) return; var torrentid = inputs[2].get(); if (torrentid == null) return; #if js net_Url = connection._url; promiseResult(connection,torrentid,net_Url); #end } override function get(from: Int): Dynamic { #if js return switch (from) { case 1: Leenkx.id.get(net_Url); case 2: leenkx.network.Leenkx.torrent.get(net_Url); default: throw "Unreachable"; } #else return null; #end } }