diff --git a/src/svxlink/reflector/Reflector.cpp b/src/svxlink/reflector/Reflector.cpp index 7899d16..c3a9938 100644 --- a/src/svxlink/reflector/Reflector.cpp +++ b/src/svxlink/reflector/Reflector.cpp @@ -1415,6 +1415,10 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port, { kv.second->onParentAudio(tg, msg.audioData()); } + if (m_twin_link != nullptr) + { + m_twin_link->onLocalAudio(tg, msg.audioData()); + } } } } @@ -1477,6 +1481,10 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port, { kv.second->onParentFlush(tg); } + if (m_twin_link != nullptr) + { + m_twin_link->onLocalFlush(tg); + } } } // To be 100% correct the reflector should wait for all connected @@ -1629,6 +1637,13 @@ void Reflector::onTalkerUpdated(uint32_t tg, ReflectorClient* old_talker, kv.second->onParentTalkerStop(tg); } } + // Notify twin partner about local talker changes. + if (m_twin_link != nullptr) + { + std::string callsign = (new_talker != nullptr) ? new_talker->callsign() + : ""; + m_twin_link->onLocalTalkerUpdated(tg, callsign); + } } } /* Reflector::onTalkerUpdated */ diff --git a/src/svxlink/reflector/TwinLink.cpp b/src/svxlink/reflector/TwinLink.cpp index 778350d..3a194e7 100644 --- a/src/svxlink/reflector/TwinLink.cpp +++ b/src/svxlink/reflector/TwinLink.cpp @@ -194,23 +194,33 @@ void TwinLink::acceptInboundConnection(Async::FramedTcpConnection* con, } /* TwinLink::acceptInboundConnection */ -void TwinLink::onLocalTalkerUpdated(uint32_t /*tg*/, - const std::string& /*callsign*/) +void TwinLink::onLocalTalkerUpdated(uint32_t tg, + const std::string& callsign) { - // Phase C1 + if (!isActive()) return; + if (callsign.empty()) + { + sendMsg(MsgTrunkTalkerStop(tg)); + } + else + { + sendMsg(MsgTrunkTalkerStart(tg, callsign)); + } } /* TwinLink::onLocalTalkerUpdated */ -void TwinLink::onLocalAudio(uint32_t /*tg*/, - const std::vector& /*audio*/) +void TwinLink::onLocalAudio(uint32_t tg, + const std::vector& audio) { - // Phase C1 + if (!isActive()) return; + sendMsg(MsgTrunkAudio(tg, audio)); } /* TwinLink::onLocalAudio */ -void TwinLink::onLocalFlush(uint32_t /*tg*/) +void TwinLink::onLocalFlush(uint32_t tg) { - // Phase C1 + if (!isActive()) return; + sendMsg(MsgTrunkFlush(tg)); } /* TwinLink::onLocalFlush */ @@ -399,27 +409,58 @@ void TwinLink::handleMsgTrunkHello(std::istream& is, bool is_inbound) } /* TwinLink::handleMsgTrunkHello */ -void TwinLink::handleMsgTrunkTalkerStart(std::istream& /*is*/) +void TwinLink::handleMsgTrunkTalkerStart(std::istream& is) { - // Phase C1 + MsgTrunkTalkerStart msg; + if (!msg.unpack(is)) + { + cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkTalkerStart" << endl; + return; + } + // setTrunkTalkerForTG fires trunkTalkerUpdated → onTrunkTalkerUpdated in + // Reflector, which broadcasts MsgTalkerStart to all local clients on this TG. + TGHandler::instance()->setTrunkTalkerForTG(msg.tg(), msg.callsign()); } /* TwinLink::handleMsgTrunkTalkerStart */ -void TwinLink::handleMsgTrunkTalkerStop(std::istream& /*is*/) +void TwinLink::handleMsgTrunkTalkerStop(std::istream& is) { - // Phase C1 + MsgTrunkTalkerStop msg; + if (!msg.unpack(is)) + { + cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkTalkerStop" << endl; + return; + } + // clearTrunkTalkerForTG fires trunkTalkerUpdated → onTrunkTalkerUpdated, + // which broadcasts MsgTalkerStop and MsgUdpFlushSamples to local clients. + TGHandler::instance()->clearTrunkTalkerForTG(msg.tg()); } /* TwinLink::handleMsgTrunkTalkerStop */ -void TwinLink::handleMsgTrunkAudio(std::istream& /*is*/) +void TwinLink::handleMsgTrunkAudio(std::istream& is) { - // Phase C1 + MsgTrunkAudio msg; + if (!msg.unpack(is)) + { + cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkAudio" << endl; + return; + } + if (msg.audio().empty()) return; + MsgUdpAudio udp_msg(msg.audio()); + m_reflector->broadcastUdpMsg(udp_msg, ReflectorClient::TgFilter(msg.tg())); } /* TwinLink::handleMsgTrunkAudio */ -void TwinLink::handleMsgTrunkFlush(std::istream& /*is*/) +void TwinLink::handleMsgTrunkFlush(std::istream& is) { - // Phase C1 + MsgTrunkFlush msg; + if (!msg.unpack(is)) + { + cerr << "*** ERROR[TWIN]: Failed to unpack MsgTrunkFlush" << endl; + return; + } + m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(), + ReflectorClient::TgFilter(msg.tg())); } /* TwinLink::handleMsgTrunkFlush */