логи на ошибку

This commit is contained in:
zakhy 2025-02-27 11:21:33 +07:00
parent 054f9949be
commit a5820d4930

View File

@ -7,6 +7,7 @@ import struct
import subprocess
import sys
import time
import traceback
import django
import websockets
@ -66,60 +67,65 @@ def get_promise_cancel_command(promise_id):
async def send_messages(websocket, message):
print(f">>> Отправка сообщения: {json.dumps(message, indent=4)}")
await websocket.send(json.dumps(message))
await asyncio.sleep(0)
try:
print(f">>> Отправка сообщения: {json.dumps(message, indent=4)}")
await websocket.send(json.dumps(message))
await asyncio.sleep(0)
except Exception:
logging.error(traceback.format_exc())
async def receive_messages(websocket, auth_dict):
promise_id = 2 # id для идентификации вызовов
ssrc = SSRC
call_mapi_initialized = False
voip_port = API_PORT
async for message in websocket:
message_from_json = json.loads(message)
for message_item in message_from_json:
voice_call = await get_voice_calls()
print(f"<<< Ответ получен: {message_item}")
identifier = message_item.get("identifier")
try:
promise_id = 2 # id для идентификации вызовов
ssrc = SSRC
call_mapi_initialized = False
voip_port = API_PORT
async for message in websocket:
message_from_json = json.loads(message)
for message_item in message_from_json:
voice_call = await get_voice_calls()
print(f"<<< Ответ получен: {message_item}")
identifier = message_item.get("identifier")
if identifier == "core/connection_response":
print(f"Соединение установлено. Инициализация модулей...")
await send_messages(websocket, get_call_initialize_command())
await send_messages(websocket, get_location_initialize_command())
if identifier == "core/connection_response":
print(f"Соединение установлено. Инициализация модулей...")
await send_messages(websocket, get_call_initialize_command())
await send_messages(websocket, get_location_initialize_command())
if identifier == "call:1/initialization_response":
call_mapi_initialized = True
ssrc = message_item["payload"].get("voip_ssrc", SSRC)
voip_port = message_item["payload"].get("voip_port", API_PORT)
if identifier == "call:1/initialization_response":
call_mapi_initialized = True
ssrc = message_item["payload"].get("voip_ssrc", SSRC)
voip_port = message_item["payload"].get("voip_port", API_PORT)
elif (
identifier == "location:0/position_broadcast"
and auth_dict["wlocationsystem"]
):
print(message_item["payload"])
await save_location(message_item["payload"])
elif call_mapi_initialized and voice_call and auth_dict["plasystem"]:
print(
"Запрос на отправку аудио. Инициализация трансляции трансляцию..."
)
await set_voice_call_sent(voice_call)
await send_messages(
websocket,
get_transmit_command(promise_id, ssrc, auth_dict["raduisip_group"]),
)
print("Начало трансляции файла.")
await start_audio_stream(
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))
promise_id += 1
print("Трансляция завершена и вызов остановлен.")
elif (
identifier == "location:0/position_broadcast"
and auth_dict["wlocationsystem"]
):
print(message_item["payload"])
await save_location(message_item["payload"])
elif call_mapi_initialized and voice_call and auth_dict["plasystem"]:
print(
"Запрос на отправку аудио. Инициализация трансляции трансляцию..."
)
await set_voice_call_sent(voice_call)
await send_messages(
websocket,
get_transmit_command(promise_id, ssrc, auth_dict["raduisip_group"]),
)
print("Начало трансляции файла.")
await start_audio_stream(
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))
promise_id += 1
print("Трансляция завершена и вызов остановлен.")
except Exception:
logging.error(traceback.format_exc())
@sync_to_async
def get_voice_calls():