Browse Source

Wrap image loop session.upsert() in try/except for reconnect resilience

Prevents coroutine death when WebSocket session drops (headset
removed/sleep). Coroutine stays alive and resumes sending when
a new session connects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
main
Joe DiPrima 1 month ago
parent
commit
41447cceaf
  1. 20
      src/televuer/televuer.py

20
src/televuer/televuer.py

@ -346,6 +346,7 @@ class TeleVuer:
to="bgChildren", to="bgChildren",
) )
while True: while True:
try:
session.upsert( session.upsert(
[ [
ImageBackground( ImageBackground(
@ -353,9 +354,6 @@ class TeleVuer:
aspect=self.aspect_ratio, aspect=self.aspect_ratio,
height=1, height=1,
distanceToCamera=1, distanceToCamera=1,
# The underlying rendering engine supported a layer binary bitmask for both objects and the camera.
# Below we set the two image planes, left and right, to layers=1 and layers=2.
# Note that these two masks are associated with left eye’s camera and the right eye’s camera.
layers=1, layers=1,
format="jpeg", format="jpeg",
quality=50, quality=50,
@ -376,7 +374,8 @@ class TeleVuer:
], ],
to="bgChildren", to="bgChildren",
) )
# 'jpeg' encoding should give you about 30fps with a 16ms wait in-between.
except Exception:
pass # Session dropped; coroutine stays alive for reconnect
await asyncio.sleep(1.0 / self.display_fps) await asyncio.sleep(1.0 / self.display_fps)
async def main_image_monocular_zmq(self, session): async def main_image_monocular_zmq(self, session):
@ -402,6 +401,7 @@ class TeleVuer:
) )
while True: while True:
try:
session.upsert( session.upsert(
[ [
ImageBackground( ImageBackground(
@ -417,6 +417,8 @@ class TeleVuer:
], ],
to="bgChildren", to="bgChildren",
) )
except Exception:
pass # Session dropped; coroutine stays alive for reconnect
await asyncio.sleep(1.0 / self.display_fps) await asyncio.sleep(1.0 / self.display_fps)
async def main_image_binocular_webrtc(self, session): async def main_image_binocular_webrtc(self, session):
@ -515,6 +517,7 @@ class TeleVuer:
to="bgChildren", to="bgChildren",
) )
while True: while True:
try:
session.upsert( session.upsert(
[ [
ImageBackground( ImageBackground(
@ -522,9 +525,6 @@ class TeleVuer:
aspect=self.aspect_ratio, aspect=self.aspect_ratio,
height=0.75, height=0.75,
distanceToCamera=2, distanceToCamera=2,
# The underlying rendering engine supported a layer binary bitmask for both objects and the camera.
# Below we set the two image planes, left and right, to layers=1 and layers=2.
# Note that these two masks are associated with left eye’s camera and the right eye’s camera.
layers=1, layers=1,
format="jpeg", format="jpeg",
quality=50, quality=50,
@ -545,7 +545,8 @@ class TeleVuer:
], ],
to="bgChildren", to="bgChildren",
) )
# 'jpeg' encoding should give you about 30fps with a 16ms wait in-between.
except Exception:
pass
await asyncio.sleep(1.0 / self.display_fps) await asyncio.sleep(1.0 / self.display_fps)
async def main_image_monocular_zmq_ego(self, session): async def main_image_monocular_zmq_ego(self, session):
@ -571,6 +572,7 @@ class TeleVuer:
) )
while True: while True:
try:
session.upsert( session.upsert(
[ [
ImageBackground( ImageBackground(
@ -586,6 +588,8 @@ class TeleVuer:
], ],
to="bgChildren", to="bgChildren",
) )
except Exception:
pass
await asyncio.sleep(1.0 / self.display_fps) await asyncio.sleep(1.0 / self.display_fps)
async def main_image_binocular_webrtc_ego(self, session): async def main_image_binocular_webrtc_ego(self, session):

Loading…
Cancel
Save