Update websocket.js

This commit is contained in:
Namhyeon Go 2021-08-11 16:29:20 +09:00 committed by GitHub
parent 3ae03c70a5
commit 8841b2f255
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,65 +11,68 @@ var SYS = require("lib/system");
var FILE = require("lib/file");
var WebsocketObject = function() {
this.binPath = "bin\\websocat_nossl_win64";
this.isSSL = false;
this.binPath = "bin\\websocat_nossl_win64";
this.isSSL = false;
this.enableSSL = function() {
this.isSSL = true;
};
this.enableSSL = function() {
this.isSSL = true;
};
this.disableSSL = function() {
this.isSSL = false;
};
this.setBinPath = function(path) {
if (typeof(path) !== "undefined") {
this.binPath = path;
} else {
var arch = SYS.getArch();
this.disableSSL = function() {
this.isSSL = false;
};
this.setBinPath = function(path) {
if (typeof(path) !== "undefined") {
this.binPath = path;
} else {
var arch = SYS.getArch();
if (!this.isSSL) {
if(arch.indexOf("64") > -1) {
this.binPath = "bin\\websocat_nossl_win64";
} else {
this.binPath = "bin\\websocat_nossl_win64";
}
} else {
if(arch.indexOf("64") > -1) {
this.binPath = "bin\\websocat_win64";
} else {
this.binPath = "bin\\websocat_win32";
}
}
}
};
this.send = function(uri, msg) {
var FN = "stdin.txt";
if (!this.isSSL) {
if(arch.indexOf("64") > -1) {
this.binPath = "bin\\websocat_nossl_win64";
} else {
this.binPath = "bin\\websocat_nossl_win64";
}
} else {
if(arch.indexOf("64") > -1) {
this.binPath = "bin\\websocat_win64";
} else {
this.binPath = "bin\\websocat_win32";
}
}
}
};
this.send = function(uri, msg) {
var seed = parseInt(Math.random() * 10000);
var FN = "tmp\\stdin_" + seed + ".txt";
try {
FILE.writeFile(FN, msg + "\n", "utf-8");
console.log(msg);
sleep(1);
try {
FILE.writeFile(FN, msg + "\n", "utf-8");
console.log(msg);
sleep(1);
return SHELL.exec([
this.binPath,
"-n1",
"-t",
uri,
"<",
FN
]);
} catch (e) {
console.error("WebsocketObject.send() -> " + e.message);
}
};
return SHELL.exec([
this.binPath,
"-n1",
"-t",
uri,
"<",
FN
]);
} catch (e) {
console.error("WebsocketObject.send() -> " + e.message);
}
this.create = function() {
this.setBinPath();
};
if (FILE.fileExists(FN)) FILE.deleteFile(FN);
};
this.create();
this.create = function() {
this.setBinPath();
};
this.create();
};
exports.VERSIONINFO = "Websocket Lib (websocket.js) version 0.1";
@ -77,5 +80,5 @@ exports.global = global;
exports.require = global.require;
exports.create = function() {
return new WebsocketObject();
return new WebsocketObject();
};