mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-15 06:01:04 +00:00
Update websocket.js
This commit is contained in:
parent
3ae03c70a5
commit
8841b2f255
109
lib/websocket.js
109
lib/websocket.js
|
@ -11,65 +11,68 @@ var SYS = require("lib/system");
|
||||||
var FILE = require("lib/file");
|
var FILE = require("lib/file");
|
||||||
|
|
||||||
var WebsocketObject = function() {
|
var WebsocketObject = function() {
|
||||||
this.binPath = "bin\\websocat_nossl_win64";
|
this.binPath = "bin\\websocat_nossl_win64";
|
||||||
this.isSSL = false;
|
this.isSSL = false;
|
||||||
|
|
||||||
this.enableSSL = function() {
|
this.enableSSL = function() {
|
||||||
this.isSSL = true;
|
this.isSSL = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.disableSSL = function() {
|
this.disableSSL = function() {
|
||||||
this.isSSL = false;
|
this.isSSL = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setBinPath = function(path) {
|
this.setBinPath = function(path) {
|
||||||
if (typeof(path) !== "undefined") {
|
if (typeof(path) !== "undefined") {
|
||||||
this.binPath = path;
|
this.binPath = path;
|
||||||
} else {
|
} else {
|
||||||
var arch = SYS.getArch();
|
var arch = SYS.getArch();
|
||||||
|
|
||||||
if (!this.isSSL) {
|
if (!this.isSSL) {
|
||||||
if(arch.indexOf("64") > -1) {
|
if(arch.indexOf("64") > -1) {
|
||||||
this.binPath = "bin\\websocat_nossl_win64";
|
this.binPath = "bin\\websocat_nossl_win64";
|
||||||
} else {
|
} else {
|
||||||
this.binPath = "bin\\websocat_nossl_win64";
|
this.binPath = "bin\\websocat_nossl_win64";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(arch.indexOf("64") > -1) {
|
if(arch.indexOf("64") > -1) {
|
||||||
this.binPath = "bin\\websocat_win64";
|
this.binPath = "bin\\websocat_win64";
|
||||||
} else {
|
} else {
|
||||||
this.binPath = "bin\\websocat_win32";
|
this.binPath = "bin\\websocat_win32";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.send = function(uri, msg) {
|
this.send = function(uri, msg) {
|
||||||
var FN = "stdin.txt";
|
var seed = parseInt(Math.random() * 10000);
|
||||||
|
var FN = "tmp\\stdin_" + seed + ".txt";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FILE.writeFile(FN, msg + "\n", "utf-8");
|
FILE.writeFile(FN, msg + "\n", "utf-8");
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
return SHELL.exec([
|
return SHELL.exec([
|
||||||
this.binPath,
|
this.binPath,
|
||||||
"-n1",
|
"-n1",
|
||||||
"-t",
|
"-t",
|
||||||
uri,
|
uri,
|
||||||
"<",
|
"<",
|
||||||
FN
|
FN
|
||||||
]);
|
]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("WebsocketObject.send() -> " + e.message);
|
console.error("WebsocketObject.send() -> " + e.message);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
this.create = function() {
|
if (FILE.fileExists(FN)) FILE.deleteFile(FN);
|
||||||
this.setBinPath();
|
};
|
||||||
};
|
|
||||||
|
|
||||||
this.create();
|
this.create = function() {
|
||||||
|
this.setBinPath();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.create();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.VERSIONINFO = "Websocket Lib (websocket.js) version 0.1";
|
exports.VERSIONINFO = "Websocket Lib (websocket.js) version 0.1";
|
||||||
|
@ -77,5 +80,5 @@ exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
||||||
exports.create = function() {
|
exports.create = function() {
|
||||||
return new WebsocketObject();
|
return new WebsocketObject();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user