Update websocket.js

This commit is contained in:
Namhyeon Go 2022-02-24 17:28:33 +09:00
parent caa57b91e4
commit 41ae841177

View File

@ -12,6 +12,7 @@ var FILE = require("lib/file");
var WebsocketObject = function() {
this.binPath = "bin\\websocat_win64";
this.timeout = 0;
this.setBinPath = function(path) {
if (typeof(path) !== "undefined") {
@ -26,6 +27,10 @@ var WebsocketObject = function() {
}
};
this.setTimeout = function(timeout) {
this.timeout = timeout;
};
this.send = function(uri, msg) {
var seed = parseInt(Math.random() * 10000);
var FN = "tmp\\stdin_" + seed + ".txt";
@ -34,17 +39,17 @@ var WebsocketObject = function() {
FILE.writeFile(FN, msg + "\n", "utf-8");
console.log(msg);
sleep(1);
var cmd = [this.binPath, "-n1", "-t"];
if (this.timeout > 0) {
cmd.push("--ping-timeout");
cmd.push(this.timeout);
}
cmd.push(uri);
cmd.push("<");
cmd.push(FN);
return SHELL.exec([
this.binPath,
"-n1",
"-t",
//"--ping-timeout",
//1,
uri,
"<",
FN
]);
return SHELL.exec(cmd);
} catch (e) {
console.error("WebsocketObject.send() -> " + e.message);
}