webrtc: signal shutdown over datachannel (#38185)

signal shut down, fix enabled bug
This commit is contained in:
stef
2026-06-16 21:33:59 -04:00
committed by GitHub
parent 82a945d145
commit 3939f1e92c
+7 -2
View File
@@ -262,7 +262,7 @@ class StreamSession:
self.params = Params()
builder = WebRTCAnswerBuilder(sdp)
self.enabled = enabled if enabled else True # default to enabled
self.enabled = enabled if enabled is not None else True # default to enabled
self.video_track = LiveStreamVideoStreamTrack(init_camera, self.enabled) if not debug_mode else VideoStreamTrack()
builder.add_video_stream(init_camera, self.video_track)
self.stream = builder.stream()
@@ -381,7 +381,7 @@ async def get_stream(request: 'web.Request'):
if s.run_task and not s.run_task.done():
try:
ch = s.stream.get_messaging_channel()
ch.send(json.dumps({"type": "connectionReplaced", "data": "Another device has connected, closing this session."}))
ch.send(json.dumps({"type": "disconnect", "data": "Another device has connected, closing this session."}))
except Exception:
pass
await s.stop()
@@ -431,6 +431,11 @@ async def post_notify(request: 'web.Request'):
async def on_shutdown(app: 'web.Application'):
for session in app['streams'].values():
try:
ch = session.stream.get_messaging_channel()
ch.send(json.dumps({"type": "disconnect", "data": "device stream has been stopped."}))
except Exception:
pass
await session.stop()
del app['streams']