Files
buzz/desktop/src-tauri/src/huddle/reconnect.rs
Tyler ccb021d713 Relay mesh: cross-pod tunnel + huddle transport (buzz-relay-mesh) (#1670)
Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
Signed-off-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: npub17jjz49l9jjmhhk7cac63j8yt9z555n9cw8vk7v5jz4vzw4ppld5qgj57cc <f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: Tyler Longwell <tlongwell@squareup.com>
Signed-off-by: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com>
Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1cc3ha7z055mu0rwwu7806t2wt8mj3pvu0uv5mfp2c50dahaqhczshdalg6 <c6237ef84fa537c78dcee78efd2d4e59f728859c7f194da42ac51ededfa0be05@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub17jjz49l9jjmhhk7cac63j8yt9z555n9cw8vk7v5jz4vzw4ppld5qgj57cc <f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
2026-07-14 16:56:48 -04:00

53 lines
2.0 KiB
Rust

//! Audio-only huddle reconnection after an unexpected relay disconnect.
use std::sync::atomic::Ordering;
use tauri::State;
use crate::app_state::AppState;
use super::{relay_api, HuddlePhase};
/// Re-establish only the audio relay WebSocket after an unexpected owner/pod
/// disconnect. Huddle membership, mic capture, STT/TTS, and frontend state stay
/// live, so a successful reconnect is a short audio blip rather than a leave.
///
/// The session generation and channel id are re-checked after the network dial:
/// an intentional leave/end racing this command wins and the newly-opened audio
/// pipeline is cancelled instead of resurrecting a terminal huddle.
#[tauri::command]
pub async fn reconnect_huddle_audio(state: State<'_, AppState>) -> Result<(), String> {
let (ephemeral_channel_id, parent_channel_id, session_generation) = {
let hs = state.huddle()?;
if matches!(hs.phase, HuddlePhase::Idle | HuddlePhase::Leaving) {
return Err("huddle is no longer active".into());
}
(
hs.ephemeral_channel_id
.clone()
.ok_or("active huddle has no channel id")?,
hs.parent_channel_id.clone(),
hs.session_generation.load(Ordering::Acquire),
)
};
let (cancel, pcm_tx) =
relay_api::connect_audio_relay(&ephemeral_channel_id, parent_channel_id.as_deref(), &state)
.await?;
let mut hs = state.huddle()?;
let still_current = !matches!(hs.phase, HuddlePhase::Idle | HuddlePhase::Leaving)
&& hs.ephemeral_channel_id.as_deref() == Some(ephemeral_channel_id.as_str())
&& hs.session_generation.load(Ordering::Acquire) == session_generation;
if !still_current {
cancel.cancel();
return Err("huddle ended while audio was reconnecting".into());
}
if let Some(old_cancel) = hs.audio_ws_cancel.replace(cancel) {
old_cancel.cancel();
}
hs.audio_relay_pcm_tx = Some(pcm_tx);
Ok(())
}