Update appConfig to load synchronously (#14)

This commit is contained in:
mattherzog 2024-01-17 08:53:28 -08:00 committed by GitHub
parent aff08a2530
commit 26720c3389
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,4 @@
import jsYaml from "js-yaml";
import { useEffect, useState } from "react";
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
const defaultConfig: AppConfig = {
title: "Agent Playground",
description: "A playground for testing LiveKit agents",
title: "Agents Playground",
description: "A playground for testing LiveKit Agents",
theme_color: "cyan",
outputs: {
audio: true,
@ -38,20 +37,16 @@ const defaultConfig: AppConfig = {
};
export const useAppConfig = (): AppConfig => {
const [config, setConfig] = useState<any>(null);
useEffect(() => {
if (APP_CONFIG) {
try {
if (APP_CONFIG) {
const parsedConfig = jsYaml.load(APP_CONFIG);
setConfig(parsedConfig);
console.log("parsedConfig:", parsedConfig);
} else {
setConfig(defaultConfig);
}
} catch (error) {
console.error("Error parsing NEXT_PUBLIC_APP_CONFIG:", error);
const parsedConfig = jsYaml.load(APP_CONFIG);
console.log("parsedConfig:", parsedConfig);
return parsedConfig as AppConfig;
} catch (e) {
console.error("Error parsing app config:", e);
return defaultConfig;
}
}, []);
return config;
} else {
return defaultConfig;
}
};