mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-11 20:21:03 +00:00
Create websocket.js
This commit is contained in:
parent
fe8867953c
commit
e535963013
67
lib/websocket.js
Normal file
67
lib/websocket.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// Websocket API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 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 WebsocketObject = function() {
|
||||
this.binPath = "bin\\websocat_nossl_win64";
|
||||
this.isSSL = false;
|
||||
|
||||
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();
|
||||
|
||||
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) {
|
||||
return SHELL.exec([
|
||||
this.binPath,
|
||||
"-t",
|
||||
uri
|
||||
]);
|
||||
};
|
||||
|
||||
this.create = function() {
|
||||
this.setBinPath();
|
||||
};
|
||||
|
||||
this.create();
|
||||
};
|
||||
|
||||
exports.VERSIONINFO = "Websocket Lib (websocket.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
exports.create = function() {
|
||||
return new WebsocketObject();
|
||||
};
|
Loading…
Reference in New Issue
Block a user