Новый заход

This commit is contained in:
zakhy 2025-04-17 16:23:32 +07:00
parent 0b0f3af789
commit ea7e45b1af

View File

@ -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())