Update websocket.js for improved path handling

Refactored default WebSocket executable path selection to check for a user-specific installation before falling back to architecture-based defaults. Updated comments for clarity and incremented version to 0.2.4.
This commit is contained in:
Namhyeon Go 2025-11-21 18:57:23 +09:00
parent 49ebde6835
commit fd3a34fc20

View File

@ -1,11 +1,15 @@
// websocket.js // websocket.js
// Copyright 2019-2025, Namhyeon Go <gnh1201@catswords.re.kr> and the WelsonJS contributors. // Namhyeon Go <gnh1201@catswords.re.kr> and the WelsonJS contributors.
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// https://github.com/gnh1201/welsonjs // https://github.com/gnh1201/welsonjs
// //
// references: // Please Note:
// https://stackoverflow.com/questions/52783655/use-curl-with-chrome-remote-debugging // If you want more fine-grained control over WebSockets, please refer to the WebSocket implementation in the WelsonJS Launcher.
// https://github.com/vi/websocat // This file exists for compatibility with previous versions.
//
// References:
// * https://stackoverflow.com/questions/52783655/use-curl-with-chrome-remote-debugging
// * https://github.com/vi/websocat
// //
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
var SYS = require("lib/system"); var SYS = require("lib/system");
@ -19,6 +23,10 @@ var WebsocketObject = function() {
this.setBinPath = function(path) { this.setBinPath = function(path) {
if (typeof(path) !== "undefined") { if (typeof(path) !== "undefined") {
this._interface.setPrefix(path); this._interface.setPrefix(path);
} else {
var default_websocat_path = SYS.getAppDataDir() + "\\websocat\\websocat.exe";
if (FILE.fileExists(default_websocat_path)) {
this._interface.setPrefix(default_websocat_path);
} else { } else {
var arch = SYS.getArch(); var arch = SYS.getArch();
if(arch.indexOf("64") > -1) { if(arch.indexOf("64") > -1) {
@ -27,6 +35,7 @@ var WebsocketObject = function() {
this._interface.setPrefix("bin\\x86\\websocat.i686-pc-windows-gnu.exe"); this._interface.setPrefix("bin\\x86\\websocat.i686-pc-windows-gnu.exe");
} }
} }
}
}; };
this.setTimeout = function(timeout) { this.setTimeout = function(timeout) {
@ -67,7 +76,7 @@ var WebsocketObject = function() {
this.create(); this.create();
}; };
exports.VERSIONINFO = "Websocket Interface (websocket.js) version 0.2.3"; exports.VERSIONINFO = "Websocket interface (websocket.js) version 0.2.4";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;