Remove config file for client, moved to .env
This commit is contained in:
@@ -1,23 +0,0 @@
|
|||||||
// Core config settings for the node, these are the settings that are checked with the server
|
|
||||||
const path = require("path");
|
|
||||||
exports.clientConfig = {
|
|
||||||
"id": 13,
|
|
||||||
"name": "boilin balls in the hall",
|
|
||||||
"ip": "172.16.100.150",
|
|
||||||
"port": 3010,
|
|
||||||
"location": "the house",
|
|
||||||
"nearbySystems": ["Westchester Cty. Simulcast"],
|
|
||||||
"online": true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration for the connection to the server
|
|
||||||
exports.serverConfig = {
|
|
||||||
"ip": "172.16.100.108",
|
|
||||||
"hostname": "localhost",
|
|
||||||
"port": 3000
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration of the local OP25 application
|
|
||||||
exports.radioAppConfig = {
|
|
||||||
"bin": "H:/Logan/Projects/Discord-Radio-Bot-CnC/Client/.idea/testOP25Dir/multi_rx.py"
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||||
const log = new DebugBuilder("client", "clientController");
|
const log = new DebugBuilder("client", "clientController");
|
||||||
// Configs
|
// Configs
|
||||||
const config = require("../config/clientConfig");
|
require('dotenv').config();
|
||||||
const modes = require("../config/modes");
|
const modes = require("../config/modes");
|
||||||
// Modules
|
// Modules
|
||||||
const { executeAsyncConsoleCommand } = require("../utilities/executeConsoleCommands.js");
|
const { executeAsyncConsoleCommand } = require("../utilities/executeConsoleCommands.js");
|
||||||
@@ -10,6 +10,9 @@ const { executeAsyncConsoleCommand } = require("../utilities/executeConsoleComma
|
|||||||
const { updateId, updateConfig } = require("../utilities/updateConfig");
|
const { updateId, updateConfig } = require("../utilities/updateConfig");
|
||||||
const updatePreset = require("../utilities/updatePresets");
|
const updatePreset = require("../utilities/updatePresets");
|
||||||
const requests = require("../utilities/httpRequests");
|
const requests = require("../utilities/httpRequests");
|
||||||
|
const { nodeObject } = require("../utilities/recordHelper.js");
|
||||||
|
|
||||||
|
var runningClientConfig = new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: process.env.CLIENT_NEARBY_SYSTEMS, _online: process.env.CLIENT_ONLINE});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the body for the required fields to update or add a preset
|
* Check the body for the required fields to update or add a preset
|
||||||
@@ -66,23 +69,23 @@ async function checkLocalIP() {
|
|||||||
* Checks the config file for all required fields or gets and updates the required fields
|
* Checks the config file for all required fields or gets and updates the required fields
|
||||||
*/
|
*/
|
||||||
exports.checkConfig = async function checkConfig() {
|
exports.checkConfig = async function checkConfig() {
|
||||||
if (!config.clientConfig.ip) {
|
if (!runningClientConfig.ip) {
|
||||||
const ipAddr = await checkLocalIP();
|
const ipAddr = await checkLocalIP();
|
||||||
updateConfig('ip', ipAddr);
|
updateConfig('ip', ipAddr);
|
||||||
config.clientConfig.ip = ipAddr;
|
runningClientConfig.ip = ipAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!config.clientConfig.name) {
|
if(!runningClientConfig.name) {
|
||||||
const lastOctet = await String(checkLocalIP()).spit('.')[-1];
|
const lastOctet = await String(checkLocalIP()).spit('.')[-1];
|
||||||
const clientName = `Radio-Node-${lastOctet}`;
|
const name = `Radio-Node-${lastOctet}`;
|
||||||
updateConfig('name', clientName);
|
updateConfig('name', name);
|
||||||
config.clientConfig.name = clientName;
|
runningClientConfig.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!config.clientConfig.port) {
|
if(!runningClientConfig.port) {
|
||||||
const port = 3010;
|
const port = 3010;
|
||||||
updateConfig('port', port);
|
updateConfig('port', port);
|
||||||
config.clientConfig.port = port;
|
runningClientConfig.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -95,13 +98,13 @@ exports.checkIn = async () => {
|
|||||||
let reqOptions;
|
let reqOptions;
|
||||||
await this.checkConfig();
|
await this.checkConfig();
|
||||||
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
|
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
|
||||||
if (config.clientConfig.id === 0) {
|
if (clientId === 0) {
|
||||||
// ID was not found in the config, creating a new node
|
// ID was not found in the config, creating a new node
|
||||||
reqOptions = new requests.requestOptions("/nodes/newNode", "POST");
|
reqOptions = new requests.requestOptions("/nodes/newNode", "POST");
|
||||||
requests.sendHttpRequest(reqOptions, JSON.stringify(config.clientConfig), (responseObject) => {
|
requests.sendHttpRequest(reqOptions, JSON.stringify(), (responseObject) => {
|
||||||
// Update the client's ID if the server accepted it
|
// Update the client's ID if the server accepted it
|
||||||
if (responseObject.statusCode === 202) {
|
if (responseObject.statusCode === 202) {
|
||||||
config.clientConfig.id = responseObject.body.nodeId;
|
runningClientConfig.id = responseObject.body.nodeId;
|
||||||
updateId(responseObject.body.nodeId);
|
updateId(responseObject.body.nodeId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -109,7 +112,7 @@ exports.checkIn = async () => {
|
|||||||
else {
|
else {
|
||||||
// ID is in the config, checking in with the server
|
// ID is in the config, checking in with the server
|
||||||
reqOptions = new requests.requestOptions("/nodes/nodeCheckIn", "POST");
|
reqOptions = new requests.requestOptions("/nodes/nodeCheckIn", "POST");
|
||||||
requests.sendHttpRequest(reqOptions, JSON.stringify(config.clientConfig), (responseObject) => {
|
requests.sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), (responseObject) => {
|
||||||
if (responseObject.statusCode === 202) {
|
if (responseObject.statusCode === 202) {
|
||||||
// Server accepted an update
|
// Server accepted an update
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
|||||||
const log = new DebugBuilder("client", "radioController");
|
const log = new DebugBuilder("client", "radioController");
|
||||||
// Modules
|
// Modules
|
||||||
const { resolve, dirname } = require('path');
|
const { resolve, dirname } = require('path');
|
||||||
|
require('dotenv').config();
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const radioConfig = require('../config/clientConfig').radioAppConfig;
|
|
||||||
const radioConfigHelper = require("../utilities/radioConfigHelper");
|
const radioConfigHelper = require("../utilities/radioConfigHelper");
|
||||||
const presetWrappers = require("../utilities/updatePresets");
|
const presetWrappers = require("../utilities/updatePresets");
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const converter = require("convert-units");
|
const converter = require("convert-units");
|
||||||
|
|
||||||
|
const radioBinPath = process.env.OP25_BIN_PATH;
|
||||||
let radioChildProcess, tempRes, radioConfigPath;
|
let radioChildProcess, tempRes, radioConfigPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +61,7 @@ exports.openRadioSession = () => {
|
|||||||
* Get the location of the 'multi_rx.py' binary from the config
|
* Get the location of the 'multi_rx.py' binary from the config
|
||||||
*/
|
*/
|
||||||
function getRadioBinPath(){
|
function getRadioBinPath(){
|
||||||
return resolve(radioConfig.bin);
|
return resolve(radioBinPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,16 +2,18 @@
|
|||||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||||
const log = new DebugBuilder("client", "httpRequests");
|
const log = new DebugBuilder("client", "httpRequests");
|
||||||
// Config
|
// Config
|
||||||
const config = require("../config/clientConfig");
|
require('dotenv').config();
|
||||||
// Modules
|
// Modules
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
|
|
||||||
|
var runningClientConfig = new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: process.env.CLIENT_NEARBY_SYSTEMS, _online: process.env.CLIENT_ONLINE});
|
||||||
|
|
||||||
exports.requestOptions = class requestOptions {
|
exports.requestOptions = class requestOptions {
|
||||||
constructor(path, method, hostname = undefined, headers = undefined, port = undefined) {
|
constructor(path, method, hostname = undefined, headers = undefined, port = undefined) {
|
||||||
if (method === "POST"){
|
if (method === "POST"){
|
||||||
this.hostname = hostname ?? config.serverConfig.hostname
|
this.hostname = hostname ?? runningClientConfig.hostname
|
||||||
this.path = path
|
this.path = path
|
||||||
this.port = port ?? config.serverConfig.port
|
this.port = port ?? runningClientConfig.port
|
||||||
this.method = method
|
this.method = method
|
||||||
this.headers = headers ?? {
|
this.headers = headers ?? {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
26
Client/utilities/recordHelper.js
Normal file
26
Client/utilities/recordHelper.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class nodeObject {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {*} param0._id The ID of the node
|
||||||
|
* @param {*} param0._name The name of the node
|
||||||
|
* @param {*} param0._ip The IP that the master can contact the node at
|
||||||
|
* @param {*} param0._port The port that the client is listening on
|
||||||
|
* @param {*} param0._location The physical location of the node
|
||||||
|
* @param {*} param0._online An integer representation of the online status of the bot, ie 0=off, 1=on
|
||||||
|
* @param {*} param0._nearbySystems An object array of nearby systems
|
||||||
|
*/
|
||||||
|
constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null, _online = null }) {
|
||||||
|
this.id = _id;
|
||||||
|
this.name = _name;
|
||||||
|
this.ip = _ip;
|
||||||
|
this.port = _port;
|
||||||
|
this.location = _location;
|
||||||
|
this.nearbySystems = _nearbySystems;
|
||||||
|
this.online = _online;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.nodeObject = nodeObject;
|
||||||
@@ -6,12 +6,12 @@ const replace = require('replace-in-file');
|
|||||||
|
|
||||||
class Options {
|
class Options {
|
||||||
constructor(key, updatedValue) {
|
constructor(key, updatedValue) {
|
||||||
this.files = "./config/clientConfig.js";
|
this.files = "./.env";
|
||||||
// A regex of the line containing the key in the config file
|
// A regex of the line containing the key in the config file
|
||||||
this.from = new RegExp(`"${key}": (.+),`, "g");
|
this.from = new RegExp(`${key}="(.+)",`, "g");
|
||||||
// Check to see if the value is a string and needs to be wrapped in double quotes
|
// Check to see if the value is a string and needs to be wrapped in double quotes
|
||||||
if (typeof updatedValue === "string") this.to = `"${key}": "${updatedValue}",`;
|
if (Array(["string", "number"]).includes(typeof updatedValue)) this.to = `${key}="${updatedValue}",`;
|
||||||
else this.to = `"${key}": ${updatedValue},`;
|
else this.to = `${key}=${updatedValue},`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user