Исправление логики ретраев и промис id
This commit is contained in:
parent
0485b41c40
commit
60f22e30b6
@ -77,8 +77,8 @@ async def send_messages(websocket, message):
|
||||
async def handle_channel_transmission(channel, voice_call, websocket, auth_dict, promise_id_start):
|
||||
ssrc = SSRC
|
||||
source_id = auth_dict["client_id"]
|
||||
promise_id = promise_id_start
|
||||
retry_attempts = 0
|
||||
promise_id = promise_id_start
|
||||
|
||||
while retry_attempts < MAX_RETRY_ATTEMPTS:
|
||||
log(f"[{channel}] Попытка #{retry_attempts + 1} для отправки")
|
||||
@ -86,10 +86,11 @@ async def handle_channel_transmission(channel, voice_call, websocket, auth_dict,
|
||||
|
||||
promise_granted = False
|
||||
own_tx_received = False
|
||||
retry_due_to_timeout = False
|
||||
|
||||
try:
|
||||
while True:
|
||||
raw = await asyncio.wait_for(websocket.recv(), timeout=5)
|
||||
raw = await asyncio.wait_for(websocket.recv(), timeout=10)
|
||||
message_items = json.loads(raw)
|
||||
|
||||
for item in message_items:
|
||||
@ -97,14 +98,18 @@ async def handle_channel_transmission(channel, voice_call, websocket, auth_dict,
|
||||
payload = item.get("payload")
|
||||
if identifier != "location:0/position_broadcast":
|
||||
log(f"<<< Ответ получен: {item}")
|
||||
|
||||
if identifier == "core/promise_response" and payload.get("promise_id") == promise_id:
|
||||
state = payload.get("state")
|
||||
if state == "granted":
|
||||
promise_granted = True
|
||||
log(f"[{channel}] Promise granted.")
|
||||
elif state == "queued":
|
||||
log(f"[{channel}] Promise queued...")
|
||||
elif state == "faulted":
|
||||
log(f"[{channel}] Promise faulted. Ретрай...")
|
||||
break
|
||||
|
||||
elif identifier == "call:1/participant_state_broadcast":
|
||||
if payload.get("state") == "own_tx" and "65280" in payload.get("source", ""):
|
||||
own_tx_received = True
|
||||
@ -122,10 +127,12 @@ async def handle_channel_transmission(channel, voice_call, websocket, auth_dict,
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
log(f"[{channel}] Timeout ожидания. Ретрай...")
|
||||
retry_due_to_timeout = True
|
||||
|
||||
retry_attempts += 1
|
||||
promise_id += 1
|
||||
await asyncio.sleep(RETRY_DELAY_SECONDS)
|
||||
if retry_attempts < MAX_RETRY_ATTEMPTS:
|
||||
await asyncio.sleep(RETRY_DELAY_SECONDS)
|
||||
|
||||
log(f"[{channel}] Не удалось отправить после {MAX_RETRY_ATTEMPTS} попыток.")
|
||||
return False
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user