Skip to content
Open
Changes from all commits
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
10 changes: 7 additions & 3 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Roon API.
* @param {RoonApi~core_found} [desc.core_found] - Called when a Roon Core is found. Usually, you want to implement pairing instead of using this.
* @param {RoonApi~core_lost} [desc.core_lost] - Called when Roon Core is lost. Usually, you want to implement pairing instead of using this.
* @param {RoonApi~onerror} [desc.moo_onerror] - Called when there is an error on the connection to a core.
* @param {string} [desc.configDir] - The directory to store configuration files.
*/
/**
* @callback RoonApi~core_paired
Expand Down Expand Up @@ -107,6 +108,7 @@ function RoonApi(o) {
this.log_level = o.log_level;
this.extension_opts = o;
this.is_paired = false;
this.configDir = o.configDir;

// - pull in Sood and provide discovery methods in Node, but not in WebBrowser
//
Expand Down Expand Up @@ -180,8 +182,9 @@ function RoonApi(o) {
RoonApi.prototype.save_config = function(k, v) {
try {
let config;
let configPath = this.configDir ? this.configDir + "/config.json" : "config.json";
try {
let content = fs.readFileSync("config.json", { encoding: 'utf8' });
let content = fs.readFileSync(configPath, { encoding: "utf8" });
config = JSON.parse(content) || {};
} catch (e) {
config = {};
Expand All @@ -190,7 +193,7 @@ function RoonApi(o) {
delete(config[k]);
else
config[k] = v;
fs.writeFileSync("config.json", JSON.stringify(config, null, ' '));
fs.writeFileSync(configPath, JSON.stringify(config, null, " "));
} catch (e) { }
};

Expand All @@ -201,7 +204,8 @@ function RoonApi(o) {
*/
RoonApi.prototype.load_config = function(k) {
try {
let content = fs.readFileSync("config.json", { encoding: 'utf8' });
let configPath = this.configDir ? this.configDir + "/config.json" : "config.json";
let content = fs.readFileSync(configPath, { encoding: "utf8" });
return JSON.parse(content)[k];
} catch (e) {
return undefined;
Expand Down