diff --git a/src/auracast/server/multicast_frontend.py b/src/auracast/server/multicast_frontend.py index c3cf809..7a09ac9 100644 --- a/src/auracast/server/multicast_frontend.py +++ b/src/auracast/server/multicast_frontend.py @@ -5,6 +5,10 @@ import requests from auracast import auracast_config import logging as log +# Track whether WebRTC stream is active across Streamlit reruns +if 'stream_started' not in st.session_state: + st.session_state['stream_started'] = False + # Global: desired packetization time in ms for Opus (should match backend) PTIME = 40 BACKEND_URL = "http://localhost:5000" @@ -47,6 +51,11 @@ if audio_mode in ["Webapp", "USB"]: default_input = saved_settings.get('input_device') or 'default' stream_name = st.text_input("Channel Name", value=default_name) language = st.text_input("Language (ISO 639-3)", value=default_lang) + # Gain slider for Webapp mode + if audio_mode == "Webapp": + mic_gain = st.slider("Microphone Gain", 0.0, 4.0, 1.0, 0.1, help="Adjust microphone volume sent to Auracast") + else: + mic_gain = 1.0 # Input device selection for USB mode if audio_mode == "USB": @@ -83,7 +92,17 @@ if audio_mode in ["Webapp", "USB"]: start_stream = st.button("Start Auracast") stop_stream = st.button("Stop Auracast") + # If gain slider moved while streaming, send update to JS without restarting + if audio_mode == "Webapp" and st.session_state.get('stream_started'): + update_js = f""" + + """ + st.components.v1.html(update_js, height=0) + if stop_stream: + st.session_state['stream_started'] = False try: r = requests.post(f"{BACKEND_URL}/stop_audio").json() if r['was_running']: @@ -133,14 +152,28 @@ if audio_mode in ["Webapp", "USB"]: except Exception as e: st.error(f"Error: {e}") - if audio_mode == "Webapp" and start_stream: + # Render / maintain WebRTC component + if audio_mode == "Webapp" and (start_stream or st.session_state.get('stream_started')): st.markdown("Starting microphone; allow access if prompted and speak.") component = f""" """ st.components.v1.html(component, height=0) + st.session_state['stream_started'] = True else: st.header("Advertised Streams (Cloud Announcements)") st.info("This feature requires backend support to list advertised streams.")