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