From ea7e45b1afbd5f73a85f06dedb80093a8062a797 Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Thu, 17 Apr 2025 16:23:32 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B7=D0=B0?= =?UTF-8?q?=D1=85=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/workerslocation/commands/radiusip.py | 35 ++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/workerslocation/commands/radiusip.py b/apps/workerslocation/commands/radiusip.py index 5b9231e..41a0dcf 100644 --- a/apps/workerslocation/commands/radiusip.py +++ b/apps/workerslocation/commands/radiusip.py @@ -1,5 +1,3 @@ -# Обновленный основной WebSocket и RTP клиент для Radiusip - import asyncio import datetime import json @@ -78,6 +76,8 @@ async def receive_messages(websocket, auth_dict): voip_port = API_PORT call_mapi_initialized = False source_id = auth_dict.get("client_id") + waiting_for_grant = False + current_voice_call = None async for message in websocket: message_from_json = json.loads(message) @@ -97,30 +97,31 @@ async def receive_messages(websocket, auth_dict): ssrc = message_item["payload"].get("voip_ssrc", SSRC) voip_port = message_item["payload"].get("voip_port", API_PORT) - elif identifier == "core/promise_response" and message_item["payload"]["identifier"] == "call:1/transmit_response": + elif identifier == "location:0/position_broadcast" and auth_dict.get("wlocationsystem"): + await save_location(message_item["payload"]) + + elif identifier == "core/promise_response" and message_item["payload"].get("identifier") == "call:1/transmit_response": payload = message_item["payload"] - if payload["state"] == "granted": - voice_call = await get_voice_calls() - if not voice_call: - print("Нет доступных вызовов.") - continue - await set_voice_call_sent(voice_call) + if payload["state"] == "granted" and current_voice_call: + print("Разрешение получено. Начинаем трансляцию...") + await set_voice_call_sent(current_voice_call) await start_audio_stream( - voice_call.alarm_file.audio_file.path, + current_voice_call.alarm_file.audio_file.path, auth_dict["radiusip_host_ws"], voip_port, ssrc ) await send_messages(websocket, get_promise_cancel_command(promise_id)) + print("Трансляция завершена и вызов остановлен.") promise_id += 1 - print("Трансляция завершена.") + waiting_for_grant = False + current_voice_call = None elif payload["state"] == "faulted": - print(f"[ОШИБКА] Передача отклонена: {payload.get('payload', {}).get('message')}") + print("[ОШИБКА] Передача отклонена сервером.") + waiting_for_grant = False + current_voice_call = None - elif identifier == "location:0/position_broadcast" and auth_dict.get("wlocationsystem"): - await save_location(message_item["payload"]) - - elif call_mapi_initialized and auth_dict.get("plasystem"): + elif call_mapi_initialized and auth_dict.get("plasystem") and not waiting_for_grant: voice_call = await get_voice_calls() if voice_call: print("Запрос на отправку аудио...") @@ -128,6 +129,8 @@ async def receive_messages(websocket, auth_dict): websocket, get_transmit_command(promise_id, ssrc, auth_dict["raduisip_group"], source_id) ) + current_voice_call = voice_call + waiting_for_grant = True except Exception: logging.error(traceback.format_exc())