Updated tunnel client
This commit is contained in:
parent
2a3a74fade
commit
5e8f95b613
26
client.js
26
client.js
@ -42,6 +42,7 @@ function initClient(options) {
|
||||
profile: options.profile,
|
||||
clientIdSub: clientIdSub,
|
||||
serverUrl: serverUrl,
|
||||
access: options.access,
|
||||
};
|
||||
|
||||
const initParams = {
|
||||
@ -49,7 +50,6 @@ function initClient(options) {
|
||||
transports: ["websocket"],
|
||||
auth: {
|
||||
token: options.token,
|
||||
token_free: options.token_free,
|
||||
...defaultParams,
|
||||
},
|
||||
headers: {
|
||||
@ -77,8 +77,8 @@ function initClient(options) {
|
||||
console.log(`${clientLogPrefix} connect error!`, e && e.message);
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log(`${clientLogPrefix} disconnected!`);
|
||||
socket.on("disconnect", (reason) => {
|
||||
console.log(`${clientLogPrefix} disconnected: ${reason}!`);
|
||||
});
|
||||
|
||||
socket.on("request", (requestId, request) => {
|
||||
@ -199,8 +199,8 @@ program
|
||||
config.server = SERVER_DEFAULT_URL;
|
||||
}
|
||||
|
||||
if (!config.token && !config.token_free) {
|
||||
console.info(`Please set token for ${config.server}!`);
|
||||
if (!config.token) {
|
||||
console.info(`Please set token for ${config.server}`);
|
||||
console.info(
|
||||
"If you don't have token yet, please contact to: sombochea@cubetiqs.com"
|
||||
);
|
||||
@ -209,7 +209,7 @@ program
|
||||
|
||||
if (!config.clientId) {
|
||||
if (!config.apiKey) {
|
||||
console.info(`Please create client for ${config.server}!`);
|
||||
console.info(`Please create client for ${config.server}`);
|
||||
} else {
|
||||
config.clientId = config.apiKey;
|
||||
}
|
||||
@ -218,7 +218,7 @@ program
|
||||
|
||||
options.port = port;
|
||||
options.token = config.token;
|
||||
options.token_free = config.token_free;
|
||||
options.access = config.access;
|
||||
options.server = config.server;
|
||||
options.clientId = config.clientId;
|
||||
options.apiKey = config.apiKey;
|
||||
@ -249,7 +249,7 @@ program
|
||||
|
||||
if (!fs.existsSync(configDir)) {
|
||||
fs.mkdirSync(configDir);
|
||||
console.log(`config file ${configDir} was created!`);
|
||||
console.log(`config file ${configDir} was created`);
|
||||
}
|
||||
|
||||
let config = {};
|
||||
@ -274,7 +274,7 @@ program
|
||||
} else {
|
||||
config.clientId = value;
|
||||
}
|
||||
console.log(`client: ${config.clientId} was set to config!`);
|
||||
console.log(`client: ${config.clientId} was set to config`);
|
||||
} else if (type === "apiKey" || type === "key") {
|
||||
config.apiKey = value;
|
||||
} else if (type === "access") {
|
||||
@ -287,14 +287,14 @@ program
|
||||
.then((resp) => {
|
||||
console.log("data = ", resp.data);
|
||||
if (resp.data?.token) {
|
||||
config.token_free = resp.data?.token;
|
||||
config.token = resp.data?.token;
|
||||
} else {
|
||||
console.log("free token return with null or empty from server!");
|
||||
console.log("free token return with null or empty from server");
|
||||
return;
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("cannot get free token from server!", err);
|
||||
console.error("cannot get free token from server", err);
|
||||
return;
|
||||
});
|
||||
}
|
||||
@ -305,7 +305,7 @@ program
|
||||
}
|
||||
|
||||
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
|
||||
console.log(`${type} config saved successfully to: ${configFilePath}!`);
|
||||
console.log(`${type} config saved successfully to: ${configFilePath}`);
|
||||
});
|
||||
|
||||
program.parse();
|
||||
|
Loading…
Reference in New Issue
Block a user