diff --git a/src/call/call.c b/src/call/call.c index a8f6db23..2a13ee76 100644 --- a/src/call/call.c +++ b/src/call/call.c @@ -15,6 +15,7 @@ #include "call_priv.h" #include "call_video_transport.h" #include "call_proto.h" +#include "../radio/radio_call.h" #include "../dm/dm_core.h" #include "../utun_instance.h" #include "../chat/chat_event.h" @@ -538,6 +539,12 @@ static void call_handle_invite(struct call_ctx* ctx, uint64_t from, uint64_t gro return; } + if (radio_call_busy(ctx->inst)) { + struct call_pkt_busy busy = {CALL_SUBCMD_BUSY, call_id}; + DEBUG_INFO(DEBUG_CATEGORY_CALL, "call busy: pending radio invitation id=%016llx", (unsigned long long)call_id); + call_send(ctx, group, from, (const uint8_t*)&busy, sizeof(busy), ROUTE_CRYPTO_SIGN | ROUTE_CRYPTO_ENCRYPT); + return; + } /* занятость: есть другая активная сессия */ struct ll_entry* e = ctx->sessions ? ctx->sessions->head : NULL; while (e) { @@ -838,6 +845,13 @@ void call_destroy(struct UTUN_INSTANCE* inst) { DEBUG_INFO(DEBUG_CATEGORY_CALL, "%s: destroyed (started=%u ended=%u)", CALL_ID, started, ended); } +int call_busy(struct UTUN_INSTANCE* inst) { + struct call_ctx* ctx = call_of(inst); + for (struct ll_entry* e = ctx && ctx->sessions ? ctx->sessions->head : NULL; e; e = e->next) + if (((struct call_session*)e->data)->state != CALL_ST_ENDED) return 1; + return 0; +} + int call_is_online(struct UTUN_INSTANCE* inst, const char* ch_id, uint64_t peer_node_id) { if (!inst || !ch_id || !ch_id[0] || !inst->topo_groups) return 0; if (peer_node_id == inst->node_id) return 1; @@ -957,6 +971,11 @@ void call_start(struct UTUN_INSTANCE* inst, const char* ch_id, uint64_t peer_nod DEBUG_WARN(DEBUG_CATEGORY_CALL, "%s: call_start self-call rejected", CALL_ID); return; } + if (radio_call_busy(inst)) { + DEBUG_INFO(DEBUG_CATEGORY_CALL, "call start rejected: pending radio invitation"); + call_event_id(ctx, CHAT_EVT_CALL_ENDED, out_call_id, CALL_REASON_BUSY); + return; + } uint64_t group_id = 0; char route_ch[64]; diff --git a/src/call/call.h b/src/call/call.h index ce28b5fe..32437200 100644 --- a/src/call/call.h +++ b/src/call/call.h @@ -35,6 +35,8 @@ void call_start (struct UTUN_INSTANCE* inst, const char* ch_id, uint64_t peer_n void call_accept (struct UTUN_INSTANCE* inst, uint64_t call_id); void call_decline(struct UTUN_INSTANCE* inst, uint64_t call_id); void call_hangup (struct UTUN_INSTANCE* inst, uint64_t call_id); +/* Проверка занятости обычным звонком; только uasync, включая входящий/исходящий. */ +int call_busy(struct UTUN_INSTANCE* inst); /* Read-only онлайн-проверка (GUI может звать из любого потока). */ int call_is_online(struct UTUN_INSTANCE* inst, const char* ch_id, uint64_t peer_node_id);