Skip to content

Commit

Permalink
added console frontend to separated packages inside this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm committed Nov 26, 2024
1 parent 31c1a8e commit 8ba1678
Show file tree
Hide file tree
Showing 155 changed files with 12,677 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ jobs:
with:
use-cross: ${{ matrix.cross }}
command: build
args: --verbose --release --package ${{ env.APP_NAME }} --target ${{ matrix.target }} --features embed_static
args: --verbose --release --package ${{ env.APP_NAME }} --target ${{ matrix.target }}

- name: Build record tool
if: matrix.build_record_tool
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ tarpaulin-report.html
.atm0s
/maxminddb-data
.vscode
book
book
*.db
39 changes: 29 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"packages/media_secure",
"packages/media_gateway",
"packages/audio_mixer",
"packages/media_console_front",
"packages/media_connector",
"packages/media_record",
"packages/media_codecs",
Expand Down
10 changes: 4 additions & 6 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sans-io-runtime = { workspace = true }
atm0s-sdn = { workspace = true }
media-server-protocol = { path = "../packages/protocol", features = ["quinn-rpc"] }
media-server-secure = { path = "../packages/media_secure" }
media-console-front = { path = "../packages/media_console_front", optional = true }
media-server-runner = { path = "../packages/media_runner", optional = true }
media-server-gateway = { path = "../packages/media_gateway", optional = true }
media-server-connector = { path = "../packages/media_connector", optional = true }
Expand All @@ -36,19 +37,16 @@ derive_more = { workspace = true, features = ["full"] }
rcgen = { version = "0.13", optional = true }
maxminddb = { version = "0.24", optional = true }
sysinfo = { version = "0.32", optional = true }
hex = { version = "0.4", optional = true }
mime_guess = { version = "2.0", optional = true }
reqwest = { version = "0.12", features = ["json"]}
sentry = "0.34"

[features]
default = ["console", "gateway", "media", "connector", "standalone", "cert_utils"]
standalone = ["console", "gateway", "media", "connector"]
gateway = ["media-server-gateway", "media-server-connector", "quinn_vnet", "node_metrics", "maxminddb", "rust-embed", "media-server-multi-tenancy"]
media = ["media-server-runner", "media-server-record", "quinn_vnet", "node_metrics"]
console = []
gateway = ["media-server-gateway", "media-server-connector", "quinn_vnet", "node_metrics", "maxminddb", "media-server-multi-tenancy", "media-server-utils/embed-files", "rust-embed"]
media = ["media-server-runner", "media-server-record", "quinn_vnet", "node_metrics", "media-server-utils/embed-files", "rust-embed"]
console = ["media-console-front", "media-server-utils/embed-files", "rust-embed"]
connector = ["quinn_vnet", "media-server-connector", "media-server-utils", "media-server-multi-tenancy"]
cert_utils = ["rcgen", "rustls"]
quinn_vnet = ["rustls", "quinn"]
node_metrics = ["sysinfo"]
embed_static = ["rust-embed", "hex", "mime_guess"]
Empty file removed bin/public/console/.gitignore
Empty file.
34 changes: 10 additions & 24 deletions bin/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ use media_server_protocol::protobuf::cluster_connector::MediaConnectorServiceCli
use media_server_protocol::rpc::quinn::{QuinnClient, QuinnStream};
use media_server_protocol::transport::{RpcReq, RpcRes};
use media_server_secure::{MediaEdgeSecure, MediaGatewaySecure};
#[cfg(not(feature = "embed_static"))]
use poem::endpoint::StaticFilesEndpoint;
use poem::{listener::TcpListener, middleware::Cors, EndpointExt, Route, Server};
use poem_openapi::types::{ToJSON, Type};
use poem_openapi::OpenApiService;
use poem_openapi::{types::ParseFromJSON, Object};
use serde::Deserialize;
use tokio::sync::mpsc::Sender;
#[cfg(feature = "embed_static")]
use utils::EmbeddedFilesEndpoint;

mod api_console;
mod api_media;
Expand All @@ -27,16 +23,11 @@ mod api_node;
mod api_token;
mod utils;

#[cfg(feature = "embed_static")]
#[cfg(feature = "gateway")]
#[derive(rust_embed::RustEmbed)]
#[folder = "public/media"]
pub struct PublicMediaFiles;

#[cfg(feature = "embed_static")]
#[derive(rust_embed::RustEmbed)]
#[folder = "public/console"]
pub struct PublicConsoleFiles;

#[derive(Debug, Default, Object, Deserialize)]
pub struct Pagination {
pub total: usize,
Expand Down Expand Up @@ -98,13 +89,8 @@ pub async fn run_console_http_server(

let ctx = api_console::ConsoleApisCtx { secure, storage, connector };

#[cfg(not(feature = "embed_static"))]
let console_panel = StaticFilesEndpoint::new("./public/console/").index_file("index.html");
#[cfg(feature = "embed_static")]
let console_panel = EmbeddedFilesEndpoint::<PublicConsoleFiles>::new();

let route = Route::new()
.nest("/", console_panel)
.nest("/", media_console_front::frontend_app())
//node
.nest("/api/node/", node_service)
.nest("/api/node/ui", node_ui)
Expand Down Expand Up @@ -189,10 +175,10 @@ pub async fn run_gateway_http_server<ES: 'static + MediaEdgeSecure + Send + Sync
let rtpengine_ui = rtpengine_service.swagger_ui();
let rtpengine_spec = rtpengine_service.spec();

#[cfg(not(feature = "embed_static"))]
let samples = StaticFilesEndpoint::new("./public/media/").index_file("index.html");
#[cfg(feature = "embed_static")]
let samples = EmbeddedFilesEndpoint::<PublicMediaFiles>::new();
#[cfg(debug_assertions)]
let samples = poem::endpoint::StaticFilesEndpoint::new("./public/media/").index_file("index.html");
#[cfg(not(debug_assertions))]
let samples = media_server_utils::EmbeddedFilesEndpoint::<PublicMediaFiles>::new();

let route = Route::new()
.nest("/samples", samples)
Expand Down Expand Up @@ -324,10 +310,10 @@ pub async fn run_media_http_server<ES: 'static + MediaEdgeSecure + Send + Sync,
let rtpengine_ui = rtpengine_service.swagger_ui();
let rtpengine_spec = rtpengine_service.spec();

#[cfg(not(feature = "embed_static"))]
let samples = StaticFilesEndpoint::new("./public/media/").index_file("index.html");
#[cfg(feature = "embed_static")]
let samples = EmbeddedFilesEndpoint::<PublicMediaFiles>::new();
#[cfg(debug_assertions)]
let samples = poem::endpoint::StaticFilesEndpoint::new("./public/media/").index_file("index.html");
#[cfg(not(debug_assertions))]
let samples = media_server_utils::EmbeddedFilesEndpoint::<PublicMediaFiles>::new();

let route = route
.nest("/samples", samples)
Expand Down
2 changes: 1 addition & 1 deletion bin/src/http/api_console/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Apis;
#[OpenApi]
impl Apis {
/// login with user credentials
#[oai(path = "/user/login", method = "post")]
#[oai(path = "/login", method = "post")]
async fn user_login(&self, Data(ctx): Data<&ConsoleApisCtx>, body: Json<UserLoginReq>) -> Json<Response<UserLoginRes>> {
if ctx.secure.validate_secret(&body.secret) {
Json(Response {
Expand Down
4 changes: 0 additions & 4 deletions bin/src/http/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#[cfg(feature = "embed_static")]
mod embedded_files;
mod payload_protobuf;
mod payload_sdp;
mod remote_ip;
mod token;
mod user_agent;

#[cfg(feature = "embed_static")]
pub use embedded_files::*;
pub use payload_protobuf::*;
pub use payload_sdp::*;
pub use remote_ip::*;
Expand Down
11 changes: 11 additions & 0 deletions packages/media_console_front/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "media-console-front"
version = "0.1.0"
edition = "2021"

[dependencies]
poem = { version = "3.0", features = [] }
rust-embed = { version = "8.0", features = ["compression"] }
reqwest = { version = "0.12" }
log = { workspace = true }
media-server-utils = { path = "../media_utils", features = ["embed-files"] }
21 changes: 21 additions & 0 deletions packages/media_console_front/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::process::Command;

fn main() {
// Build Vite project when compiling in release mode
if !cfg!(debug_assertions) {
Command::new("pnpm")
.current_dir(format!("{}/react-app", env!("CARGO_MANIFEST_DIR")))
.args(&["install"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to install Vite project");
Command::new("pnpm")
.current_dir(format!("{}/react-app", env!("CARGO_MANIFEST_DIR")))
.args(&["run", "build"])
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()
.expect("Failed to build Vite project");
}
}
1 change: 1 addition & 0 deletions packages/media_console_front/react-app/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_APP_API_URL=
26 changes: 26 additions & 0 deletions packages/media_console_front/react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

.env
1 change: 1 addition & 0 deletions packages/media_console_front/react-app/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

18 changes: 18 additions & 0 deletions packages/media_console_front/react-app/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"singleQuote": true,
"semi": false,
"printWidth": 125,
"bracketSameLine": false,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": false,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"tabWidth": 2,
"trailingComma": "es5",
"vueIndentScriptAndStyle": false,
"plugins": ["prettier-plugin-organize-imports", "prettier-plugin-tailwindcss", "prettier-plugin-packagejson"],
"tailwindFunctions": ["cn", "tv", "cx", "clsx", "cva"]
}
Loading

0 comments on commit 8ba1678

Please sign in to comment.