0.1.17
build / test (push) Waiting to run

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-17 16:50:28 +01:00
1 parent 528017b0e6
commit 9e65aa0103
27 files changed
+1053 -101

No files matched your search

+25 -1
View File
@@ -32,6 +32,16 @@ pub struct StreamQuery {
channels: Option<String>,
/// M3U: only this channel group
group: Option<String>,
/// HLS: viewer id of a player instance (lets the server end its old sessions at once)
v: Option<String>,
}
impl StreamQuery {
fn viewer(&self) -> Option<&str> {
self.v
.as_deref()
.filter(|v| (8..=40).contains(&v.len()) && v.chars().all(|c| c.is_ascii_alphanumeric()))
}
}
impl StreamQuery {
@@ -211,6 +221,9 @@ fn hls_suffix(ctx: &Ctx, q: &StreamQuery, profile: &str) -> String {
if profile != "pass" {
parts.push(format!("profile={profile}"));
}
if let Some(v) = q.viewer() {
parts.push(format!("v={v}"));
}
match &ctx.access {
StreamAccess::Token(t) => parts.push(format!("token={}", t.token)),
StreamAccess::Share(_) => {
@@ -247,7 +260,7 @@ pub async fn hls_playlist(
Ok(p) => p,
Err(e) => return e.into_response(),
};
let sess = state.hls.get_or_start(&state, id, &profile);
let sess = state.hls.get_or_start(&state, id, &profile, q.viewer());
sess.touch();
if let Err(e) = sess.wait_ready(Duration::from_secs(25)).await {
return (
@@ -289,6 +302,14 @@ pub async fn hls_playlist(
.into_response()
}
/// `POST /hls/leave?v=<viewer>` – a player stopped (channel change, page closed).
pub async fn hls_leave(AxState(state): AxState<State>, Query(q): Query<StreamQuery>) -> Response {
if let Some(v) = q.viewer() {
state.hls.leave(v);
}
StatusCode::NO_CONTENT.into_response()
}
pub async fn hls_segment(
AxState(state): AxState<State>,
ConnectInfo(peer): ConnectInfo<SocketAddr>,
@@ -322,6 +343,9 @@ pub async fn hls_segment(
.into_response();
};
sess.touch();
if let Some(v) = q.viewer() {
sess.see(v);
}
let Some(data) = sess.wait_segment(seq, Duration::from_secs(12)).await else {
return (StatusCode::NOT_FOUND, "segment unavailable").into_response();
};