Skip to content

Commit 2bc9fd9

Browse files
authored
Update network.js
1 parent fbdd6ae commit 2bc9fd9

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/nodes/network.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,61 @@
362362
};
363363

364364
LiteGraph.registerNodeType("network/sillyclient", LGSillyClient);
365+
366+
//HTTP Request
367+
function HTTPRequestNode() {
368+
this.addInput("request", LiteGraph.ACTION);
369+
this.addInput("url", "string");
370+
this.addProperty("url", "string");
371+
this.addOutput("ready", LiteGraph.EVENT);
372+
this.addOutput("data", "string");
373+
this._data = null;
374+
this._fetching = null;
375+
}
376+
377+
HTTPRequestNode.title = "HTTP Request";
378+
HTTPRequestNode.desc = "Fetch data through HTTP";
379+
380+
HTTPRequestNode.prototype.fetch = function()
381+
{
382+
this.boxcolor = "#FF0";
383+
var that = this;
384+
this._fetching = fetch(url)
385+
.then(resp=>{
386+
if(!resp.ok)
387+
{
388+
this.boxcolor = "#F00";
389+
that.trigger("error");
390+
}
391+
else
392+
{
393+
this.boxcolor = "#0F0";
394+
return resp.text();
395+
}
396+
})
397+
.then(data=>{
398+
that._data = data;
399+
that._fetching = null;
400+
that.trigger("ready");
401+
});
402+
}
403+
404+
HTTPRequestNode.prototype.onAction = function(evt)
405+
{
406+
if(evt == "request")
407+
this.fetch();
408+
}
409+
410+
HTTPRequestNode.prototype.onExecute = function() {
411+
this.setOutputData(1, this._data);
412+
};
413+
414+
HTTPRequestNode.prototype.onGetOutputs = function() {
415+
return [["error",LiteGraph.EVENT]];
416+
}
417+
418+
LiteGraph.registerNodeType("network/httprequest", HTTPRequestNode);
419+
420+
421+
365422
})(this);

0 commit comments

Comments
 (0)