Skip to content

Commit

Permalink
bug fixes for checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Sir-Thom committed Oct 24, 2023
1 parent 0864a13 commit 0278331
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/server/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub async fn patch_server_config_options(config_data: Value, url: &str) -> Resul
err.to_string()
})?;

debug!("Response: {:?}", response);
info!("Response: {:?}", response);

if response.status().is_success() {
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/components/titlebar/titlebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function Titlebar() {
title="About"
href="#"
onClick={handleOpen}
className="block justify-start item-center rounded-lg px-4 py-2 dark:text-text-dark text-text-light hover:dark:bg-window-dark-100 hover:bg-window-light-600"
className="flex justify-start item-center rounded-lg px-4 py-2 dark:text-text-dark text-text-light hover:dark:bg-window-dark-100 hover:bg-window-light-600"
>
<IconInfoCircle
className="flex justify-center item-center dark:text-text-dark text-text-light text-center pr-2"
Expand All @@ -169,7 +169,7 @@ export function Titlebar() {
<Link
to="/"
title="Server"
className="block rounded-lg px-4 py-2 text-md dark:text-text-dark text-text-light hover:dark:bg-window-dark-100 hover:bg-window-light-600"
className="flex rounded-lg px-4 py-2 text-md dark:text-text-dark text-text-light hover:dark:bg-window-dark-100 hover:bg-window-light-600"
>
<IconServer
className="flex justify-center item-center dark:text-text-dark text-text-light text-center pr-2"
Expand All @@ -181,7 +181,7 @@ export function Titlebar() {
<Link
to="/settings"
title="Setting"
className="block rounded-lg px-4 py-2 text-md dark:text-text-dark text-text-light hover:dark:bg-window-dark-100 hover:bg-window-light-600"
className="flex rounded-lg px-4 py-2 text-md dark:text-text-dark text-text-light hover:dark:bg-window-dark-100 hover:bg-window-light-600"
>
<IconSettings
size={26}
Expand Down
2 changes: 0 additions & 2 deletions src/interfaces/IServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ interface IServer {
hlsTrustedProxies: string[];
hlsDirectory: string;
webrtc: boolean;
webrtcDisable: boolean;
webrtcAddress: string;
webrtcEncryption: boolean;
webrtcServerKey: string;
Expand Down Expand Up @@ -209,7 +208,6 @@ interface IRtmpSettings {

interface IWebrtcSettings {
webrtc: boolean;
webrtcDisable: boolean;
webrtcAddress: string;
webrtcEncryption: boolean;
webrtcServerKey: string;
Expand Down
50 changes: 26 additions & 24 deletions src/views/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default function Setting() {
const [webrtcSettings, setWebrtcSettings] = useState<IWebrtcSettings>({
webrtc: configData?.webrtc || true,
webrtcAddress: configData?.webrtcAddress || ":8080",
webrtcDisable: configData?.webrtcDisable || false,
webrtcEncryption: configData?.webrtcEncryption || false,
webrtcServerKey: configData?.webrtcServerKey || "server.key",
webrtcServerCert: configData?.webrtcServerCert || "server.crt",
Expand Down Expand Up @@ -117,7 +116,7 @@ export default function Setting() {
recordDeleteAfter: configData?.recordDeleteAfter || "24h"
});

console.log(apiSettings);
console.log(webrtcSettings);

useEffect(() => {
setError(null);
Expand Down Expand Up @@ -212,7 +211,7 @@ export default function Setting() {
setWebrtcSettings({
webrtc: parsedResponse.webrtc || true,
webrtcAddress: parsedResponse.webrtcAddress || ":8080",
webrtcDisable: parsedResponse.webrtcDisable || false,

webrtcEncryption: parsedResponse.webrtcEncryption || false,
webrtcServerKey:
parsedResponse.webrtcServerKey || "server.key",
Expand Down Expand Up @@ -255,46 +254,49 @@ export default function Setting() {
});
}, []);

async function postSetting(configData) {
async function patchSetting(configData) {
try {
if (configData == null) {
throw new Error("the configuation data is empty");
setError(
"ConfigData is empty."

);
}


await invoke("patch_server_config_options", {
configData: configData,
url: "http://127.0.0.1:9997/v3/config/global/patch"
}).then((response: string) => {

console.log("response: " + response);
const parsedResponse: IServer = JSON.parse(response);
console.log(
"parsed option in post:" + JSON.stringify(parsedResponse)
"parsed option in patch:" + JSON.stringify(parsedResponse)
);
setConfigData(parsedResponse);
setSuccessMessage("Settings saved successfully");
// get the updated config
const serverUrl = "http://127.0.0.1:9997/v3/config/global/get";
invoke("get_server_config_options", { url: serverUrl })
.then((response: string) => {
invoke("get_server_config_options", { url: serverUrl }).then(
(response: string) => {
const parsedResponse: IServer = JSON.parse(response);
console.log(parsedResponse.metrics);
console.log(parsedResponse.webrtc);
setConfigData(parsedResponse);
console.log(
"new parsed option:" +
JSON.stringify(parsedResponse)
);
})
.catch((e) => {
console.error(
"Unable to connect to the server. Please check your connection." +
e.message
);
});
}
);
});
} catch (e) {
setError(
"Unable to connect to the server. Please check your connection." +
e.message
);
}
console.log("configData: " + JSON.stringify(configData));
}

const menuItems = [
Expand Down Expand Up @@ -354,7 +356,7 @@ export default function Setting() {
)
);
}}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
{currentSetting === "Logging Setting" && (
Expand All @@ -365,7 +367,7 @@ export default function Setting() {
updatedLoggingSettings
)
}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
{currentSetting === "HLS Setting" && (
Expand All @@ -374,7 +376,7 @@ export default function Setting() {
onSave={(updatedHlsSettings) =>
setHlsSettings(updatedHlsSettings)
}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
{currentSetting === "RTSP Setting" && (
Expand All @@ -383,7 +385,7 @@ export default function Setting() {
onSave={(updatedRtspSettings) =>
setRtspSettings(updatedRtspSettings)
}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
{currentSetting === "RTMP Setting" && (
Expand All @@ -392,7 +394,7 @@ export default function Setting() {
onSave={(updatedRtmpSettings) =>
setRtmpSettings(updatedRtmpSettings)
}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
{currentSetting === "SRT Setting" && (
Expand All @@ -401,7 +403,7 @@ export default function Setting() {
onSave={(updatedSrtSettings) =>
setSrtSettings(updatedSrtSettings)
}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
{currentSetting === "WebRTC Setting" && (
Expand All @@ -410,7 +412,7 @@ export default function Setting() {
onSave={(updatWebRtcSettings) =>
setWebrtcSettings(updatWebRtcSettings)
}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
{currentSetting === "Record Setting" && (
Expand All @@ -419,7 +421,7 @@ export default function Setting() {
onSave={(updatedRecordSettings) =>
setRecordSettings(updatedRecordSettings)
}
postSetting={postSetting}
patchSetting={patchSetting}
/>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/views/serverSetting/ApiSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { motion } from "framer-motion";
import { fadeIn } from "../../utils/animation/screenAnimation";
import Checkbox from "../../components/checkBox/checkBox";

export default function ApiSetting({ settings, onSave, postSetting }) {
export default function ApiSetting({ settings, onSave, patchSetting }) {
const [apiEnabled, setApiEnabled] = useState(Boolean(settings.api));
const [apiAddress, setApiAddress] = useState(settings.apiAddress);
const [metricsEnabled, setMetricsEnabled] = useState(
Expand Down Expand Up @@ -79,7 +79,7 @@ export default function ApiSetting({ settings, onSave, postSetting }) {

// Call the onSave prop to save the changes
onSave(updatedSettings);
postSetting(updatedSettings);
patchSetting(updatedSettings);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/views/serverSetting/LoggingSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { motion } from "framer-motion";
import { fadeIn } from "../../utils/animation/screenAnimation";
import Dropdown from "../../components/dropdowns/dropdown";

export default function LoggingSetting({ settings, onSave, postSetting }) {
export default function LoggingSetting({ settings, onSave, patchSetting }) {
const [logLevel, setLogLevel] = useState(settings.logLevel || "info");

const [logDestinations, setLogDestinations] = useState(
Expand Down Expand Up @@ -41,7 +41,7 @@ export default function LoggingSetting({ settings, onSave, postSetting }) {

// Call the onSave prop to save the changes
onSave(updatedSettings);
postSetting(updatedSettings);
patchSetting(updatedSettings);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/views/serverSetting/RecordSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fadeIn } from "../../utils/animation/screenAnimation";
import Checkbox from "../../components/checkBox/checkBox";
import Toast from "../../components/toast/Toast";

export default function RecordSetting({ settings, onSave, postSetting }) {
export default function RecordSetting({ settings, onSave, patchSetting }) {
const [error, setError] = useState<string | null>(null);
const [record, setRecord] = useState(Boolean(settings.record));
const [recordPath, setRecordPath] = useState(settings.recordPath);
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function RecordSetting({ settings, onSave, postSetting }) {
recordDeleteAfter: recordDeleteAfter
};
onSave(updatedSettings);
postSetting(updatedSettings);
patchSetting(updatedSettings);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/views/serverSetting/RtmpSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { motion } from "framer-motion";
import { fadeIn } from "../../utils/animation/screenAnimation";
import Checkbox from "../../components/checkBox/checkBox";

export default function RtmpSetting({ settings, onSave, postSetting }) {
export default function RtmpSetting({ settings, onSave, patchSetting }) {
const [rtmp, setRtmp] = useState(settings.rtmp || true);
const [rtmpDisabled, setRtmpDisabled] = useState(
settings.rtmpDisabled || false
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function RtmpSetting({ settings, onSave, postSetting }) {
rtmpServerCert: rtmpServerCert
};
onSave(updatedSettings);
postSetting(updatedSettings);
patchSetting(updatedSettings);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/views/serverSetting/RtspSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { motion } from "framer-motion";
import Checkbox from "../../components/checkBox/checkBox";
import { fadeIn } from "../../utils/animation/screenAnimation";

export default function RtspSetting({ settings, onSave, postSetting }) {
export default function RtspSetting({ settings, onSave, patchSetting }) {
const [rtsp, setRtsp] = useState(settings.rtsp || true);
const [rtspDisable, setRtspDisable] = useState(
settings.rtspDisable || false
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function RtspSetting({ settings, onSave, postSetting }) {
multicastRTCPPort: multicastRTCPPort
};
onSave(updatedSettings);
postSetting(updatedSettings);
patchSetting(updatedSettings);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/views/serverSetting/SrtSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { motion } from "framer-motion";
import { fadeIn } from "../../utils/animation/screenAnimation";
import Checkbox from "../../components/checkBox/checkBox";

export default function SRTSetting({ settings, onSave, postSetting }) {
export default function SRTSetting({ settings, onSave, patchSetting }) {
const [srt, setSRT] = useState(Boolean(settings.srt));
const [srtAddress, setSRTAddress] = useState(settings.srtAddress);

Expand All @@ -27,7 +27,7 @@ export default function SRTSetting({ settings, onSave, postSetting }) {
srtAddress: srtAddress
};
onSave(updatedSettings);
postSetting(updatedSettings);
patchSetting(updatedSettings);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/views/serverSetting/hlsSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fadeIn } from "../../utils/animation/screenAnimation";

import Checkbox from "../../components/checkBox/checkBox";

export default function HlsSetting({ settings, onSave, postSetting }) {
export default function HlsSetting({ settings, onSave, patchSetting }) {
const [hlsEnabled, setHlsEnabled] = useState(settings.hls || true);
const [hlsAddress, setHlsAddress] = useState(
settings.hlsAddress || ":8888"
Expand Down Expand Up @@ -146,7 +146,7 @@ export default function HlsSetting({ settings, onSave, postSetting }) {
hlsVariant: hlsVariant
};
onSave(updatedSettings);
postSetting(updatedSettings);
patchSetting(updatedSettings);
};

return (
Expand Down
Loading

0 comments on commit 0278331

Please sign in to comment.