Skip to main content

heldar_kernel/routes/
liveview.rs

1use axum::extract::{Path, State};
2use axum::routing::get;
3use axum::{Json, Router};
4
5use crate::auth::Principal;
6use crate::error::AppResult;
7use crate::services::mediamtx::{self, LiveUrls};
8use crate::state::AppState;
9
10pub fn router() -> Router<AppState> {
11    Router::new().route(
12        "/api/v1/cameras/{id}/liveview",
13        get(liveview).post(liveview),
14    )
15}
16
17/// Ensure a MediaMTX path exists for the camera and return live playback URLs.
18async fn liveview(
19    State(st): State<AppState>,
20    principal: Principal,
21    Path(id): Path<String>,
22) -> AppResult<Json<LiveUrls>> {
23    // Operational action (viewer+); the extractor enforces auth when it is enabled.
24    principal.require(principal.can_view(), "view live streams")?;
25    Ok(Json(mediamtx::ensure_live(&st, &id).await?))
26}