-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
264 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod server_config; | ||
pub mod server_http_verb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use log::{debug, error, info, warn}; | ||
use reqwest; | ||
use serde_json::Value; | ||
|
||
|
||
#[tauri::command] | ||
pub async fn get_server_request(url: &str) -> Result<String, String> { | ||
let response = reqwest::Client::new() | ||
.get(url) | ||
.send() | ||
.await | ||
.map_err(|err| { | ||
error!("GET request error: {:?}", err); | ||
err.to_string() | ||
})?; | ||
debug!("GET response: {:?}", response); | ||
|
||
info!("GET request to URL: {}", url); | ||
|
||
if response.status().is_redirection() { | ||
warn!("Redirection: {:?}", response); | ||
} | ||
|
||
if response.status().is_success() { | ||
// Deserialize the JSON response into a Value | ||
let body_json: Value = response.json().await.map_err(|err| { | ||
error!("JSON deserialization error: {:?}", err); | ||
err.to_string() | ||
})?; | ||
|
||
// Serialize the Value back to a JSON string | ||
let body_json_string = serde_json::to_string(&body_json).map_err(|err| { | ||
error!("JSON serialization error: {:?}", err); | ||
err.to_string() | ||
})?; | ||
|
||
Ok(body_json_string) | ||
} else if response.status().is_server_error() { | ||
error!("Server error: {:?}", response.status()); | ||
Err(format!("Server error: {:?}", response.status())) | ||
} else { | ||
error!("Request was not successful: {:?}", response.status()); | ||
Err(format!("Request was not successful: {:?}", response.status())) | ||
} | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn patch_server_request(config_data: Value, url: &str) -> Result<(), String> { | ||
// Serialize the JSON data to a string | ||
let data = config_data.to_string(); | ||
info!("PATCH data: {}", data); | ||
info!("PATCH request to URL: {}", url); | ||
|
||
|
||
let response = reqwest::Client::new() | ||
.patch(url) | ||
.header("Content-Type", "application/json") | ||
.body(data) | ||
.send() | ||
.await | ||
.map_err(|err| { | ||
error!("PATCH request error: {:?}", err); | ||
err.to_string() | ||
})?; | ||
|
||
debug!("Response: {:?}", response); | ||
|
||
if response.status().is_success() { | ||
Ok(()) | ||
} else { | ||
response.status().is_server_error().then(|| { | ||
error!("Server error: {:?}", response); | ||
}); | ||
error!("PATCH request was not successful: {:?}", response); | ||
Err(format!("PATCH request was not successful: {:?}", response.text().await)) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
"request": true, | ||
"scope": [ | ||
"http://*", | ||
"http://localhost", | ||
"https://*" | ||
] | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
interface ListBoxProps { | ||
data: any; // JSON data | ||
// An array of field names to display | ||
} | ||
|
||
function ListBox({ data }: ListBoxProps): JSX.Element { | ||
const { itemCount, pageCount, items } = data; | ||
console.log("itemCount:" + itemCount); | ||
console.log("pageCount:" + pageCount); | ||
console.log("items:" + items); | ||
return ( | ||
<div className="p-4"> | ||
<h2 className="text-2xl font-bold">Data Information</h2> | ||
<p className="text-lg">Total Items: {itemCount}</p> | ||
<p className="text-lg">Total Pages: {pageCount}</p> | ||
|
||
<div className="mt-4"> | ||
{items.map((item) => ( | ||
<div | ||
key={item.id} | ||
className=" bg-window-dark-500 text-white p-2 my-2 rounded" | ||
> | ||
<p>ID: {item.id}</p> | ||
<p>Created: {new Date(item.created).toDateString()}</p> | ||
<p>Remote Address: {item.remoteAddr}</p> | ||
<p>Bytes Received: {item.bytesReceived} bytes</p> | ||
<p>Bytes Sent: {item.bytesSent} bytes</p> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default ListBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
interface ListBoxProps { | ||
data: Array<{ [key: string]: any }>; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useEffect, useState } from "react"; | ||
import { Titlebar } from "../components/titlebar/titlebar"; | ||
import SideMenu from "../components/sideMenu/sideMenu"; | ||
import Toast from "../components/toast/Toast"; | ||
import RtspServerInfo from "./ServerInfoView/RtspServerInfo"; | ||
export default function ServerInfo() { | ||
const [error, setError] = useState<string | null>(null); | ||
const [currentSetting, setCurrentSetting] = useState("RTSP"); // Initially show the "API Setting" component | ||
|
||
const menuItems = [ | ||
{ label: "HLS" }, | ||
{ label: "RTSP" }, | ||
{ label: "RTMP" }, | ||
{ label: "WebRTC" }, | ||
{ label: "SRT" } | ||
].sort((a, b) => a.label.localeCompare(b.label)); | ||
|
||
function handleDismissErrorToast() { | ||
setError(null); | ||
} | ||
|
||
return ( | ||
<> | ||
<Titlebar /> | ||
<div className="flex flex-col h-screen"> | ||
<div className="flex"> | ||
<div className="w-1/4 mx-auto fixed h-full"> | ||
<SideMenu | ||
menuItems={menuItems} | ||
onMenuItemClick={(menuItem) => | ||
setCurrentSetting(menuItem.label) | ||
} | ||
/> | ||
</div> | ||
<div className="w-3/4 mx-auto mt-4 mr-24"> | ||
<div className="mx-auto mt-24"> | ||
{currentSetting === "RTSP" && <RtspServerInfo />} | ||
</div> | ||
{error && ( | ||
<Toast | ||
message={error} | ||
timer={5000} | ||
type={"error"} | ||
onDismiss={handleDismissErrorToast} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useEffect, useState } from "react"; | ||
import { motion } from "framer-motion"; | ||
import { fadeIn } from "../../utils/animation/screenAnimation"; | ||
import { invoke } from "@tauri-apps/api"; | ||
import ListBox from "../../components/ListBox/listBox"; | ||
|
||
export default function RtspServerInfo() { | ||
const [Rtspdata, setRtspdata] = useState<any[]>([]); // Initialize as an empty array | ||
|
||
useEffect(() => { | ||
invoke("get_server_request", { | ||
url: "http://127.0.0.1:9997/v3/rtspconns/list" | ||
}).then((response: any) => { | ||
console.log("response:" + response); | ||
setRtspdata(response as any[]); | ||
console.log("parsed option:" + JSON.stringify(response)); | ||
}); | ||
}, []); | ||
const data = { | ||
itemCount: 2, | ||
pageCount: 1, | ||
items: [ | ||
{ | ||
id: "f0181de0-b1fb-4efd-93ad-1ede297eea03", | ||
created: "2023-10-26T09:19:19.376827665-04:00", | ||
remoteAddr: "127.0.0.1:46702", | ||
bytesReceived: 127, | ||
bytesSent: 128 | ||
}, | ||
{ | ||
id: "4a98da7a-16ad-42db-82c2-c4cae87f77b0", | ||
created: "2023-10-26T10:31:22.643908707-04:00", | ||
remoteAddr: "127.0.0.1:36982", | ||
bytesReceived: 127, | ||
bytesSent: 128 | ||
} | ||
] | ||
}; | ||
|
||
return ( | ||
<motion.div | ||
variants={fadeIn} | ||
initial="hidden" | ||
animate="visible" | ||
exit="exit" | ||
> | ||
<div className=" my-4"> | ||
<h2 className="text-center font-bold text-3xl"> | ||
RTSP Server Information | ||
</h2> | ||
<div className="grid grid-cols-2 mt-6 content-between place-content-start gap-4"> | ||
<div className="col-span-1"> | ||
<div className="flex flex-col text-right items-end"> | ||
<label className="font-semibold text-lg my-2"> | ||
RTSP Server: | ||
</label> | ||
</div> | ||
</div> | ||
<div className="col-span-1"> | ||
<div className="flex flex-col"> | ||
<ListBox data={data} /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</motion.div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.