diff --git a/defs/constants.ts b/defs/constants.ts index 6397e6a0..60557d2b 100644 --- a/defs/constants.ts +++ b/defs/constants.ts @@ -21,7 +21,9 @@ export const EMAIL_VERIFICATION_VALIDITY_SECS = 3600; export const EXTERNAL_RELAY_NO_DATA_SHUTDOWN_SECS = 10; -export const EXTERNAL_RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS = 30; +export const EXTERNAL_RELAY_NO_DATA_START_SHUTDOWN_SECS = 30; + +export const EXTERNAL_RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS = 60; export const FORWARD_IP_HEADER = "x-openstream-forwarded-ip"; diff --git a/front/app/src/routes/(root)/(online)/(app)/accounts/[account]/account-station-item.svelte b/front/app/src/routes/(root)/(online)/(app)/accounts/[account]/account-station-item.svelte index 6766a5aa..2ee71de5 100644 --- a/front/app/src/routes/(root)/(online)/(app)/accounts/[account]/account-station-item.svelte +++ b/front/app/src/routes/(root)/(online)/(app)/accounts/[account]/account-station-item.svelte @@ -56,7 +56,7 @@ flex: none; width: min(30%, 8rem); aspect-ratio: 1; - margin: 1rem 2rem 1rem 1rem; + margin: 1rem 1.5rem 1rem 1rem; border-radius: 0.5rem;; background-size: contain; background-position: center; diff --git a/rs/config/constants/src/lib.rs b/rs/config/constants/src/lib.rs index 5ff28609..418caf33 100644 --- a/rs/config/constants/src/lib.rs +++ b/rs/config/constants/src/lib.rs @@ -43,7 +43,7 @@ pub const STREAM_IP_CONNECTIONS_LIMIT: u64 = 8; pub const PLAYLIST_NO_LISTENERS_SHUTDOWN_DELAY_SECS: u64 = 10; #[const_register] -pub const EXTERNAL_RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS: u64 = 30; +pub const EXTERNAL_RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS: u64 = 60; /// delay to shutdown a relay session when it run out of listeners #[const_register] @@ -53,6 +53,10 @@ pub const RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS: u64 = 10; #[const_register] pub const EXTERNAL_RELAY_NO_DATA_SHUTDOWN_SECS: u64 = 10; +/// delay of which if external doesn't produce first data chunk, it will be cancelled +#[const_register] +pub const EXTERNAL_RELAY_NO_DATA_START_SHUTDOWN_SECS: u64 = 30; + /// limit of authotization, or other sensible api endpoints requests from the same ip #[const_register] pub const API_IP_LIMIT: usize = 60; diff --git a/rs/packages/media-sessions/src/external_relay.rs b/rs/packages/media-sessions/src/external_relay.rs index 6418f02a..525826fb 100644 --- a/rs/packages/media-sessions/src/external_relay.rs +++ b/rs/packages/media-sessions/src/external_relay.rs @@ -3,8 +3,8 @@ use std::time::Instant; use crate::{SendError, Transmitter}; use constants::{ - EXTERNAL_RELAY_NO_DATA_SHUTDOWN_SECS, EXTERNAL_RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS, - /*STREAM_BURST_LENGTH,*/ + EXTERNAL_RELAY_NO_DATA_SHUTDOWN_SECS, EXTERNAL_RELAY_NO_DATA_START_SHUTDOWN_SECS, + EXTERNAL_RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS, /*STREAM_BURST_LENGTH,*/ STREAM_CHUNK_SIZE, STREAM_KBITRATE, }; use db::media_session::MediaSession; @@ -188,11 +188,26 @@ pub fn run_external_relay_session( // let chunks = chunks.rated(STREAM_KBITRATE * 1000); // tokio::pin!(chunks); + async fn chunk_timeout(first_chunk: bool) { + if first_chunk { + tokio::time::sleep(tokio::time::Duration::from_secs( + EXTERNAL_RELAY_NO_DATA_START_SHUTDOWN_SECS, + )) + .await + } else { + tokio::time::sleep(tokio::time::Duration::from_secs( + EXTERNAL_RELAY_NO_DATA_SHUTDOWN_SECS, + )) + .await + } + } + + let mut first_chunk = true; loop { let chunk = tokio::select! { - _ = tokio::time::sleep(tokio::time::Duration::from_secs(EXTERNAL_RELAY_NO_DATA_SHUTDOWN_SECS)) => { + _ = chunk_timeout(first_chunk) => { info!( - "shutting down external-relay for station {} (no data received in specified window)", + "shutting down external-relay for station {} (no data received in specified start window)", station_id ); break; @@ -201,6 +216,8 @@ pub fn run_external_relay_session( chunk = chunks.next() => chunk }; + first_chunk = false; + match chunk { None => break, Some(Err(_e)) => break, @@ -221,9 +238,9 @@ pub fn run_external_relay_session( > EXTERNAL_RELAY_NO_LISTENERS_SHUTDOWN_DELAY_SECS { info!( - "shutting down external-relay for station {} (no listeners shutdown delay elapsed)", - station_id - ); + "shutting down external-relay for station {} (no listeners shutdown delay elapsed)", + station_id + ); break; } else { continue;