Files
UnrealEngineUWP/Samples/PixelStreaming/WebServers/SignallingWebServer/modules/config.js
Luke Bermingham 16fb0841c4 Fixing VCam input.
- CreateInputDevice is only called once on a module so it cannot be used to create multiple input devices when we're creating mutliple streamers. Only the default will work since it's the first being made.
- Fixing signalling config loading when it is readonly.

#fyi Matthew.Cotton, David.Hibbitts
#preflight 628dd36faf7a2e956bb09db8

[CL 20361009 by Luke Bermingham in ue5-main branch]
2022-05-25 03:12:06 -04:00

57 lines
2.0 KiB
JavaScript

// Copyright Epic Games, Inc. All Rights Reserved.
//-- Provides configuration information from file and combines it with default values and command line arguments --//
//-- Hierachy of values: Default Values < Config File < Command Line arguments --//
const fs = require('fs');
const path = require('path');
const argv = require('yargs').argv;
function initConfig(configFile, defaultConfig){
defaultConfig = defaultConfig || {};
// Using object spread syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_object_literals
let config = {...defaultConfig};
try{
let configData = fs.readFileSync(configFile, 'UTF8');
fileConfig = JSON.parse(configData);
config = {...config, ...fileConfig}
try {
accessSync('configFile', constants.W_OK);
// Update config file with any additional defaults (does not override existing values if default has changed)
fs.writeFileSync(configFile, JSON.stringify(config, null, '\t'), 'UTF8');
} catch (err) {
console.log("Config file is readonly, skipping writing config...");
return config;
}
} catch(err) {
if (err.code === 'ENOENT') {
console.log("No config file found, writing defaults to log file " + configFile);
fs.writeFileSync(configFile, JSON.stringify(config, null, '\t'), 'UTF8');
} else if (err instanceof SyntaxError) {
console.log(`ERROR: Invalid JSON in ${configFile}, ignoring file config, ${err}`)
} else {
console.log(`ERROR: ${err}`);
}
}
try{
//Make a copy of the command line args and remove the unneccessary ones
//The _ value is an array of any elements without a key
let commandLineConfig = {...argv}
delete commandLineConfig._;
delete commandLineConfig.help;
delete commandLineConfig.version;
delete commandLineConfig['$0'];
config = {...config, ...commandLineConfig}
} catch(err) {
console.log(`ERROR: ${err}`);
}
return config;
}
module.exports = {
init: initConfig
}