diff --git a/src/auracast/server/multicast_frontend.py b/src/auracast/server/multicast_frontend.py index 7a09ac9..a4b44ec 100644 --- a/src/auracast/server/multicast_frontend.py +++ b/src/auracast/server/multicast_frontend.py @@ -111,6 +111,20 @@ if audio_mode in ["Webapp", "USB"]: st.success("Stream was not running.") except Exception as e: st.error(f"Error: {e}") + # Ensure existing WebRTC connection is fully closed so that a fresh + # connection is created the next time we start the stream. + if audio_mode == "Webapp": + cleanup_js = """ + + """ + st.components.v1.html(cleanup_js, height=0) if start_stream: # Always send stop to ensure backend is in a clean state, regardless of current status @@ -158,10 +172,15 @@ if audio_mode in ["Webapp", "USB"]: component = f"""