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() { var WebsocketObject = function() {
this.binPath = "bin\\websocat_win64"; this.binPath = "bin\\websocat_win64";
this.timeout = 0;
this.setBinPath = function(path) { this.setBinPath = function(path) {
if (typeof(path) !== "undefined") { if (typeof(path) !== "undefined") {
@ -26,6 +27,10 @@ var WebsocketObject = function() {
} }
}; };
this.setTimeout = function(timeout) {
this.timeout = timeout;
};
this.send = function(uri, msg) { this.send = function(uri, msg) {
var seed = parseInt(Math.random() * 10000); var seed = parseInt(Math.random() * 10000);
var FN = "tmp\\stdin_" + seed + ".txt"; var FN = "tmp\\stdin_" + seed + ".txt";
@ -35,16 +40,16 @@ var WebsocketObject = function() {
console.log(msg); console.log(msg);
sleep(1); sleep(1);
return SHELL.exec([ var cmd = [this.binPath, "-n1", "-t"];
this.binPath, if (this.timeout > 0) {
"-n1", cmd.push("--ping-timeout");
"-t", cmd.push(this.timeout);
//"--ping-timeout", }
//1, cmd.push(uri);
uri, cmd.push("<");
"<", cmd.push(FN);
FN
]); return SHELL.exec(cmd);
} catch (e) { } catch (e) {
console.error("WebsocketObject.send() -> " + e.message); console.error("WebsocketObject.send() -> " + e.message);
} }