Update appConfig to load synchronously (#14)
This commit is contained in:
parent
aff08a2530
commit
26720c3389
@ -1,5 +1,4 @@
|
|||||||
import jsYaml from "js-yaml";
|
import jsYaml from "js-yaml";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
|
|
||||||
const APP_CONFIG = process.env.NEXT_PUBLIC_APP_CONFIG;
|
const APP_CONFIG = process.env.NEXT_PUBLIC_APP_CONFIG;
|
||||||
|
|
||||||
@ -22,8 +21,8 @@ export type AppConfig = {
|
|||||||
|
|
||||||
// Fallback if NEXT_PUBLIC_APP_CONFIG is not set
|
// Fallback if NEXT_PUBLIC_APP_CONFIG is not set
|
||||||
const defaultConfig: AppConfig = {
|
const defaultConfig: AppConfig = {
|
||||||
title: "Agent Playground",
|
title: "Agents Playground",
|
||||||
description: "A playground for testing LiveKit agents",
|
description: "A playground for testing LiveKit Agents",
|
||||||
theme_color: "cyan",
|
theme_color: "cyan",
|
||||||
outputs: {
|
outputs: {
|
||||||
audio: true,
|
audio: true,
|
||||||
@ -38,20 +37,16 @@ const defaultConfig: AppConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useAppConfig = (): AppConfig => {
|
export const useAppConfig = (): AppConfig => {
|
||||||
const [config, setConfig] = useState<any>(null);
|
|
||||||
useEffect(() => {
|
|
||||||
try {
|
|
||||||
if (APP_CONFIG) {
|
if (APP_CONFIG) {
|
||||||
|
try {
|
||||||
const parsedConfig = jsYaml.load(APP_CONFIG);
|
const parsedConfig = jsYaml.load(APP_CONFIG);
|
||||||
setConfig(parsedConfig);
|
|
||||||
console.log("parsedConfig:", parsedConfig);
|
console.log("parsedConfig:", parsedConfig);
|
||||||
|
return parsedConfig as AppConfig;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error parsing app config:", e);
|
||||||
|
return defaultConfig;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setConfig(defaultConfig);
|
return defaultConfig;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error("Error parsing NEXT_PUBLIC_APP_CONFIG:", error);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return config;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user