Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added interface support #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const path = require('path');

var config = {};

config.webPort = process.env.WEB_PORT || 8000;
config.webPort = process.env.WEB_PORT || 8002;
Copy link
Member

@cprezzi cprezzi Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change the default port to 8002. Users can change their port in the env file via "WEB_PORT=".

And config.js is anyways the wrong place to set user config, because it will be compiled into the runtime (for runtime versions). User configuration should be done in the env file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a server running on this port on my dev machine already. I thought I had changed that back before doing the pull request. Sorry. I fixed it now.

config.serverVersion = '4.0.136';
config.apiVersion = '4.0.7';
//config.interface = 'Wi-Fi' //Windows Name
//config.interface = 'wlan0' //linux name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done like all the other user configurable presets:
config.interface = process.env.WEB_INTERFACE || null;

Then the user can set the interface in his .env file with:
WEB_INTERFACE = "wlan0"


config.verboseLevel = process.env.VERBOSE_LEVEL || 1;
config.logLevel = process.env.LOG_LEVEL || 0;
Expand Down
29 changes: 26 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const request = require('request'); // proxy for remote webcams
const grblStrings = require('./grblStrings.js');
const firmwareFeatures = require('./firmwareFeatures.js');
const { exec } = require('child_process'); //Support for running OS commands before and after jobs
const dns = require('dns');

exports.LWCommServer=function(config){

Expand Down Expand Up @@ -96,12 +97,34 @@ var xPos = 0.00, yPos = 0.00, zPos = 0.00, aPos = 0.00;
var xOffset = 0.00, yOffset = 0.00, zOffset = 0.00, aOffset = 0.00;
var has4thAxis = false;

require('dns').lookup(require('os').hostname(), function (err, add, fam) {
//Get a listing of all interfaces on system
var interfaces = os.networkInterfaces();

if (config.interface != null) { //If the interface name is set in the config file
const interfaces = os.networkInterfaces();
Object.keys(interfaces).forEach((netInterface) => {
if (netInterface == config.interface) {
interfaces[netInterface].forEach((interfaceObject) => {
if (interfaceObject.family === 'IPv4' && !interfaceObject.internal) {
start_server(interfaceObject.address);
}
});
}
});
} else {
//Use hostname vs interface property from config.js
dns.lookup(os.hostname(), function (err, add, fam) {
start_server(add);
});
}


function start_server(address) {
writeLog(chalk.green(' '), 0);
writeLog(chalk.green('***************************************************************'), 0);
writeLog(chalk.white(' ---- LaserWeb Comm Server ' + config.serverVersion + ' ---- '), 0);
writeLog(chalk.green('***************************************************************'), 0);
writeLog(chalk.white(' Use ') + chalk.yellow(' http://' + add + ':' + config.webPort) + chalk.white(' to connect this server.'), 0);
writeLog(chalk.white(' Use ') + chalk.yellow(' http://' + address + ':' + config.webPort) + chalk.white(' to connect this server.'), 0);
writeLog(chalk.green('***************************************************************'));
writeLog(chalk.green(' '), 0);
writeLog(chalk.red('* Updates: '), 0);
Expand All @@ -115,7 +138,7 @@ require('dns').lookup(require('os').hostname(), function (err, add, fam) {
writeLog(chalk.green(' ') + chalk.yellow('https://plus.google.com/communities/115879488566665599508'), 0);
writeLog(chalk.green('***************************************************************'), 0);
writeLog(chalk.green(' '), 0);
});
}


// Init webserver
Expand Down