mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 02:48:25 -05:00
Introduce ability to configure ports etc for external applications. (#785)
Introduce ability to configure ports etc for external applications, including webgui
This commit is contained in:
@@ -24,6 +24,9 @@
|
||||
|
||||
#include <modules/webgui/webguimodule.h>
|
||||
|
||||
#include <modules/server/servermodule.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <ghoul/fmt.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
@@ -38,20 +41,41 @@ namespace {
|
||||
"Enable the node js based process used to serve the Web GUI."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo AddressInfo = {
|
||||
"Address",
|
||||
"Address",
|
||||
"The network address to use when connecting to OpenSpace from the Web GUI."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo PortInfo = {
|
||||
"Port",
|
||||
"Port",
|
||||
"The network port to use when serving the Web GUI over HTTP."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo WebSocketInterfaceInfo = {
|
||||
"WebSocketInterface",
|
||||
"WebSocket Interface",
|
||||
"The identifier of the websocket interface to use when communicating."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo ServerProcessEntryPointInfo =
|
||||
{
|
||||
"ServerProcessEntryPoint",
|
||||
"Server Process Entry Point",
|
||||
"The node js command to invoke"
|
||||
"The node js command to invoke."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo
|
||||
ServerProcessWorkingDirectoryInfo =
|
||||
WebDirectoryInfo =
|
||||
{
|
||||
"ServerProcessWorkingDirectory",
|
||||
"Server Process Working Directory",
|
||||
"The working directory of the process"
|
||||
"WebDirectory",
|
||||
"Web Directory",
|
||||
"Directory from which to to serve static content",
|
||||
};
|
||||
|
||||
constexpr const char* DefaultAddress = "localhost";
|
||||
constexpr const int DefaultPort = 4680;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -60,14 +84,40 @@ WebGuiModule::WebGuiModule()
|
||||
: OpenSpaceModule(WebGuiModule::Name)
|
||||
, _enabled(ServerProcessEnabledInfo, false)
|
||||
, _entryPoint(ServerProcessEntryPointInfo)
|
||||
, _workingDirectory(ServerProcessWorkingDirectoryInfo)
|
||||
, _webDirectory(WebDirectoryInfo)
|
||||
, _address(AddressInfo, DefaultAddress)
|
||||
, _port(PortInfo, DefaultPort)
|
||||
, _webSocketInterface(WebSocketInterfaceInfo, "")
|
||||
{
|
||||
addProperty(_enabled);
|
||||
addProperty(_entryPoint);
|
||||
addProperty(_workingDirectory);
|
||||
addProperty(_webDirectory);
|
||||
addProperty(_address);
|
||||
addProperty(_port);
|
||||
}
|
||||
|
||||
void WebGuiModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
int WebGuiModule::port() const {
|
||||
return _port;
|
||||
}
|
||||
|
||||
std::string WebGuiModule::address() const {
|
||||
return _address;
|
||||
}
|
||||
|
||||
void WebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) {
|
||||
if (configuration.hasValue<int>(PortInfo.identifier)) {
|
||||
_port = configuration.value<int>(PortInfo.identifier);
|
||||
}
|
||||
|
||||
if (configuration.hasValue<std::string>(AddressInfo.identifier)) {
|
||||
_address = configuration.value<std::string>(AddressInfo.identifier);
|
||||
}
|
||||
|
||||
if (configuration.hasValue<std::string>(WebSocketInterfaceInfo.identifier)) {
|
||||
_webSocketInterface =
|
||||
configuration.value<std::string>(WebSocketInterfaceInfo.identifier);
|
||||
}
|
||||
|
||||
auto startOrStop = [this]() {
|
||||
if (_enabled) {
|
||||
startProcess();
|
||||
@@ -85,20 +135,39 @@ void WebGuiModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
|
||||
_enabled.onChange(startOrStop);
|
||||
_entryPoint.onChange(restartIfEnabled);
|
||||
_workingDirectory.onChange(restartIfEnabled);
|
||||
_webDirectory.onChange(restartIfEnabled);
|
||||
_port.onChange(restartIfEnabled);
|
||||
startOrStop();
|
||||
}
|
||||
|
||||
void WebGuiModule::startProcess() {
|
||||
ServerModule* serverModule = global::moduleEngine.module<ServerModule>();
|
||||
const ServerInterface* serverInterface =
|
||||
serverModule->serverInterfaceByIdentifier(_webSocketInterface);
|
||||
if (!serverInterface) {
|
||||
LERROR("Missing server interface. Server process could not start.");
|
||||
return;
|
||||
}
|
||||
const int webSocketPort = serverInterface->port();
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
const std::string nodePath = absPath("${MODULE_WEBGUI}/ext/nodejs/node.exe");
|
||||
#else
|
||||
const std::string nodePath = absPath("${MODULE_WEBGUI}/ext/nodejs/node");
|
||||
#endif
|
||||
|
||||
const std::string command = "\"" + nodePath + "\" "
|
||||
+ "\"" + _entryPoint.value() + "\"" +
|
||||
" --directory \"" + _webDirectory.value() + "\"" +
|
||||
" --http-port \"" + std::to_string(_port.value()) + "\" " +
|
||||
" --ws-address \"" + _address.value() + "\"" +
|
||||
" --ws-port \"" + std::to_string(webSocketPort) + "\"" +
|
||||
" --auto-close --local";
|
||||
|
||||
_process = std::make_unique<ghoul::Process>(
|
||||
"\"" + nodePath + "\" \"" + _entryPoint.value() + "\"",
|
||||
_workingDirectory.value(),
|
||||
command,
|
||||
_webDirectory.value(),
|
||||
[](const char* data, size_t n) {
|
||||
const std::string str(data, n);
|
||||
LDEBUG(fmt::format("Web GUI server output: {}", str));
|
||||
|
||||
Reference in New Issue
Block a user