Update websocket.js

This commit is contained in:
Namhyeon Go 2024-09-25 16:00:41 +09:00
parent 124ea0ae30
commit ce440ae7f7

View File

@ -1,29 +1,29 @@
// Websocket API for WelsonJS framework
// Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs
//
//
// references:
// - https://stackoverflow.com/questions/52783655/use-curl-with-chrome-remote-debugging
// - https://github.com/vi/websocat
//
//
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var FILE = require("lib/file");
var WebsocketObject = function() {
this.binPath = "bin\\websocat_win64";
this.timeout = 0;
this._interface = null;
this.timeout = 0;
this.setBinPath = function(path) {
if (typeof(path) !== "undefined") {
this.binPath = path;
this._interface.setPrefix(path);
} else {
var arch = SYS.getArch();
if(arch.indexOf("64") > -1) {
this.binPath = "bin\\x64\\websocat.x86_64-pc-windows-gnu.exe";
this._interface.setPrefix("bin\\x64\\websocat.x86_64-pc-windows-gnu.exe");
} else {
this.binPath = "bin\\x86\\websocat.i686-pc-windows-gnu.exe";
this._interface.setPrefix("bin\\x86\\websocat.i686-pc-windows-gnu.exe");
}
}
};
@ -40,8 +40,8 @@ var WebsocketObject = function() {
FILE.writeFile(FN, msg + "\n", FILE.CdoCharset.CdoUTF_8);
console.log(msg);
sleep(1);
var cmd = [this.binPath, "-n1", "-t"];
var cmd = ["-n1", "-t"];
if (this.timeout > 0) {
cmd.push("--ping-timeout");
cmd.push(this.timeout);
@ -50,7 +50,7 @@ var WebsocketObject = function() {
cmd.push("<");
cmd.push(FN);
return SHELL.exec(cmd);
return this._interface.exec(cmd);
} catch (e) {
console.error("WebsocketObject.send() -> " + e.message);
}
@ -59,13 +59,14 @@ var WebsocketObject = function() {
};
this.create = function() {
this._interface = SHELL.create();
this.setBinPath();
};
this.create();
};
exports.VERSIONINFO = "Websocket Lib (websocket.js) version 0.2.2";
exports.VERSIONINFO = "Websocket Interface (websocket.js) version 0.2.3";
exports.global = global;
exports.require = global.require;