Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cargo toml bin #227

Merged
merged 6 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ jobs:
run: npm run build
- name: Build
run: cargo build --all --release --verbose
- name: Run tests
run: cargo test --all --verbose
- name: Setup ffmpeg
if: ${{ matrix.os != 'windows-latest' }}
uses: AnimMouse/setup-ffmpeg@v1
- name: Run tests
run: cargo test --all --verbose
- name: Run e2e tests
if: ${{ matrix.os != 'windows-latest' }}
run: npm run e2e:cluster
Expand Down
78 changes: 31 additions & 47 deletions Cargo.lock

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

41 changes: 38 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ edition.workspace = true
license.workspace = true
repository.workspace = true

default-run = "live777"

[[bin]]
name = "live777"
path = "src/main.rs"

[[bin]]
name = "liveman"
path = "src/liveman.rs"

[[bin]]
name = "whipinto"
path = "src/whipinto.rs"

[[bin]]
name = "whepfrom"
path = "src/whepfrom.rs"

[workspace]
members = [
".",
Expand All @@ -15,10 +33,9 @@ members = [
"libs/libwish",
"libs/signal",
"libs/net4mqtt",
"tools/whepfrom",
"tools/whipinto",
"liveion",
"liveman",
"livetwo",
]

[workspace.package]
Expand All @@ -38,8 +55,25 @@ serde = "1"
tokio = "1.36"
tracing = "0.1"

[dev-dependencies]
http = { workspace = true }
serde = { workspace = true, features = ["serde_derive"] }
serde_json = "1.0"

api = { path = "libs/api" }
cli = { path = "libs/cli" }
reqwest = { version = "0.12", features = [
"rustls-tls",
"socks",
"json"
], default-features = false }

tempfile = "3"

[dependencies]
liveion = { path = "liveion" }
liveman = { path = "liveman" }
livetwo = { path = "livetwo" }
signal = { path = "libs/signal" }
utils = { path = "libs/utils" }

Expand All @@ -49,7 +83,8 @@ tracing = { workspace = true }

[features]
default = ["net4mqtt"]
net4mqtt = ["liveion/net4mqtt"]
liveion = ["liveman/liveion"]
net4mqtt = ["liveion/net4mqtt", "liveman/net4mqtt"]

# cargo install cargo-deb
# Reference: https://github.com/kornelski/cargo-deb
Expand Down
35 changes: 9 additions & 26 deletions cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ describe("test cluster", () => {
const fileContentVerge = `
[strategy]
reforward_close_sub = true
each_stream_max_sub = 1
`

const fileContentCloud = `
Expand All @@ -258,7 +259,6 @@ close_other_sub = true
[[nodes]]
alias = "test-verge"
url = "http://${localhost}:${live777VergePort}"
sub_max = 1

[[nodes]]
alias = "test-cloud"
Expand Down Expand Up @@ -321,25 +321,16 @@ url = "http://${localhost}:${live777CloudPort}"

await until(() => hasPublishStreams(live777CloudHost))

const whepfromPort = "5004"
await using _1 = await tempFile(tmpFileSdpWhepfrom, `
v=0
m=video ${whepfromPort} RTP/AVP 96
c=IN IP4 127.0.0.1
a=rtpmap:96 VP8/90000
`)

using _whepfrom = spawn([
appWhepfrom,
"--mode", "rtp",
"--codec", "vp8",
"--url", `${live777CloudHost}/whep/${live777CloudStream}`,
"--target", `127.0.0.1:${whepfromPort}`,
"--port", "5004",
"-o", tmpFileSdpWhepfrom,
"-w", `${live777CloudHost}/whep/${live777CloudStream}`,
], {
onExit: e => { e.exitCode && console.log(e.stderr) },
})

await until(() => existsSync(tmpFileSdpWhepfrom))

const res = spawnSync(["ffprobe", "-v", "error", "-hide_banner",
"-protocol_whitelist", "file,rtp,udp", "-i", tmpFileSdpWhepfrom,
"-show_format", "-show_streams", "-of", "json"])
Expand Down Expand Up @@ -380,26 +371,18 @@ a=rtpmap:96 VP8/90000
await until(() => hasPublishStreams(live777VergeHost))
await until(() => hasPublishStreams(live777LivemanHost))

const whepfromPort = "5008"
using _whepfrom1 = spawn([
appWhepfrom,
"--mode", "rtp",
"--codec", "vp8",
"--url", `${live777LivemanHost}/whep/${live777LivemanStream}`,
"--target", `127.0.0.1:${whepfromPort}`,
"--port", whepfromPort,
"-o", tmpFileSdpWhepfrom,
"-w", `${live777LivemanHost}/whep/${live777LivemanStream}`,
], { onExit: e => { e.exitCode && console.log("whepfrom 1", e.stderr) } })

await until(() => hasSubscribeStreams(live777VergeHost))

const whepfrom2Port = "5010"
using _whepfrom2 = spawn([
appWhepfrom,
"--mode", "rtp",
"--codec", "vp8",
"--url", `${live777LivemanHost}/whep/${live777LivemanStream}`,
"--target", `127.0.0.1:${whepfrom2Port}`,
"--port", whepfrom2Port,
"-o", tmpFileSdpWhepfrom,
"-w", `${live777LivemanHost}/whep/${live777LivemanStream}`,
], { onExit: e => { e.exitCode && console.log("whepfrom 2", e.stderr) } })

await Promise.all([
Expand Down
2 changes: 0 additions & 2 deletions liveion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ api = { path = "../libs/api" }
auth = { path = "../libs/auth" }
http-log = { path = "../libs/http-log" }
libwish = { path = "../libs/libwish" }
signal = { path = "../libs/signal" }
utils = { path = "../libs/utils" }

net4mqtt = { path = "../libs/net4mqtt", optional = true }

Expand Down
4 changes: 3 additions & 1 deletion liveman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition.workspace = true
license.workspace = true
repository.workspace = true

[lib]
crate-type = ["lib"]

[dependencies]
liveion = { path = "../liveion", optional = true }
net4mqtt = { path = "../libs/net4mqtt", optional = true }
Expand All @@ -14,7 +17,6 @@ api = { path = "../libs/api" }
auth = { path = "../libs/auth" }
http-log = { path = "../libs/http-log" }
signal = { path = "../libs/signal" }
utils = { path = "../libs/utils" }

anyhow = { workspace = true, features = ["backtrace"] }
clap = { workspace = true, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion liveman/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Default for CheckReforwardTickTime {
}

impl Config {
pub(crate) fn parse(path: Option<String>) -> Self {
pub fn parse(path: Option<String>) -> Self {
let result = fs::read_to_string(path.unwrap_or(String::from("liveman.toml")))
.or(fs::read_to_string("/etc/live777/liveman.toml"))
.unwrap_or("".to_string());
Expand Down
50 changes: 5 additions & 45 deletions liveman/src/main.rs → liveman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use axum::response::IntoResponse;
use axum::routing::post;
use axum::Router;

use clap::Parser;
use http::{header, StatusCode, Uri};
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::rt::TokioExecutor;
Expand All @@ -15,7 +14,10 @@ use tokio::net::TcpListener;
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use tower_http::validate_request::ValidateRequestHeaderLayer;
use tracing::{debug, error, info, info_span, warn};
use tracing::{error, info_span};

#[cfg(feature = "liveion")]
use tracing::info;

use auth::{access::access_middleware, ManyValidate};

Expand All @@ -28,7 +30,7 @@ use crate::mem::{MemStorage, Node, NodeKind, Server};
struct Assets;

mod admin;
mod config;
pub mod config;
mod error;
mod mem;
mod result;
Expand All @@ -38,43 +40,6 @@ mod tick;
#[cfg(feature = "liveion")]
mod cluster;

#[derive(Parser)]
#[command(version)]
struct Args {
/// Set config file path
#[arg(short, long)]
config: Option<String>,
}

#[tokio::main]
async fn main() {
let args = Args::parse();
let cfg = Config::parse(args.config);

#[cfg(debug_assertions)]
utils::set_log(format!(
"liveman={},liveion={},http_log={},webrtc=error",
cfg.log.level, cfg.log.level, cfg.log.level
));

#[cfg(not(debug_assertions))]
utils::set_log(format!(
"liveman={},http_log={},webrtc=error",
cfg.log.level, cfg.log.level
));

warn!("set log level : {}", cfg.log.level);
debug!("config : {:?}", cfg);

let listener = tokio::net::TcpListener::bind(cfg.http.listen)
.await
.unwrap();
info!("Server listening on {}", listener.local_addr().unwrap());

server_up(cfg, listener, shutdown_signal()).await;
info!("Server shutdown");
}

pub async fn server_up<F>(cfg: Config, listener: TcpListener, signal: F)
where
F: Future<Output = ()> + Send + 'static,
Expand Down Expand Up @@ -230,11 +195,6 @@ async fn static_handler(uri: Uri) -> impl IntoResponse {
}
}

async fn shutdown_signal() {
let str = signal::wait_for_stop_signal().await;
debug!("Received signal: {}", str);
}

type Client = hyper_util::client::legacy::Client<HttpConnector, Body>;

#[derive(Clone)]
Expand Down
Loading
Loading