mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-06-07 16:21:45 +00:00
refactor(telephone_manager): improve call initiation handling and UI update logic
This commit is contained in:
@@ -438,26 +438,25 @@ class TelephoneManager:
|
||||
finally:
|
||||
if self._is_initiation_cancelled():
|
||||
self._update_initiation_status(None, None)
|
||||
return
|
||||
else:
|
||||
# Wait for either establishment, failure, or a timeout
|
||||
# to ensure the UI has something to show (either active_call or initiation_status)
|
||||
for _ in range(40): # Max 4 seconds of defensive waiting
|
||||
if self.telephone and (
|
||||
self.telephone.active_call
|
||||
or self.telephone.call_status in [0, 1, 3, 6]
|
||||
):
|
||||
break
|
||||
await asyncio.sleep(self._status_poll_interval_s)
|
||||
|
||||
# Wait for either establishment, failure, or a timeout
|
||||
# to ensure the UI has something to show (either active_call or initiation_status)
|
||||
for _ in range(40): # Max 4 seconds of defensive waiting
|
||||
# If call was successful, keep status for a moment to prevent UI flicker
|
||||
# while the frontend picks up the new active_call state
|
||||
if self.telephone and (
|
||||
self.telephone.active_call
|
||||
or self.telephone.call_status in [0, 1, 3, 6]
|
||||
(self.telephone.active_call and self.telephone.call_status == 6)
|
||||
or self.telephone.call_status in [2, 4, 5]
|
||||
):
|
||||
break
|
||||
await asyncio.sleep(self._status_poll_interval_s)
|
||||
|
||||
# If call was successful, keep status for a moment to prevent UI flicker
|
||||
# while the frontend picks up the new active_call state
|
||||
if self.telephone and (
|
||||
(self.telephone.active_call and self.telephone.call_status == 6)
|
||||
or self.telephone.call_status in [2, 4, 5]
|
||||
):
|
||||
await asyncio.sleep(1.0)
|
||||
self._update_initiation_status(None, None)
|
||||
await asyncio.sleep(1.0)
|
||||
self._update_initiation_status(None, None)
|
||||
|
||||
def mute_transmit(self):
|
||||
if self.telephone:
|
||||
|
||||
@@ -17,9 +17,11 @@ from meshchatx.src.backend.telephone_manager import TelephoneManager
|
||||
|
||||
|
||||
class _DummyThread:
|
||||
def __init__(self, target=None, daemon=None):
|
||||
def __init__(self, target=None, daemon=None, args=(), kwargs=None, **_extra):
|
||||
self.target = target
|
||||
self.daemon = daemon
|
||||
self.args = args
|
||||
self.kwargs = kwargs or {}
|
||||
|
||||
def start(self):
|
||||
return None
|
||||
@@ -85,6 +87,7 @@ def test_lxst_telephone_lifecycle_and_timeouts(monkeypatch):
|
||||
def test_lxst_switch_profile_updates_codec_and_frame_time(monkeypatch):
|
||||
_install_lxst_stubs(monkeypatch)
|
||||
identity = _mock_identity()
|
||||
fake_codec = object()
|
||||
|
||||
class _FakeMixer:
|
||||
def __init__(self, target_frame_ms=None, gain=0.0):
|
||||
@@ -130,6 +133,11 @@ def test_lxst_switch_profile_updates_codec_and_frame_time(monkeypatch):
|
||||
monkeypatch.setattr(LXSTTelephony, "Mixer", _FakeMixer)
|
||||
monkeypatch.setattr(LXSTTelephony, "LineSource", _FakeLineSource)
|
||||
monkeypatch.setattr(LXSTTelephony, "Pipeline", _FakePipeline)
|
||||
monkeypatch.setattr(
|
||||
LXSTTelephony.Profiles,
|
||||
"get_codec",
|
||||
lambda _profile: fake_codec,
|
||||
)
|
||||
|
||||
telephone = LXSTTelephony.Telephone(identity)
|
||||
telephone.call_status = LXSTTelephony.Signalling.STATUS_ESTABLISHED
|
||||
@@ -148,7 +156,7 @@ def test_lxst_switch_profile_updates_codec_and_frame_time(monkeypatch):
|
||||
assert telephone.target_frame_time_ms == LXSTTelephony.Profiles.get_frame_time(
|
||||
LXSTTelephony.Profiles.QUALITY_HIGH
|
||||
)
|
||||
assert telephone.transmit_codec is not None
|
||||
assert telephone.transmit_codec is fake_codec
|
||||
|
||||
telephone.active_call = None
|
||||
telephone.teardown()
|
||||
|
||||
Reference in New Issue
Block a user