mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-22 08:52:20 +08:00
Add datachannel c apis and callbacks(#3328)
增加datachannel数据收发的回调通知 #3326,和控制datachannel回显的开关 --------- Co-authored-by: xiongziliang <771730766@qq.com>
This commit is contained in:
@@ -55,6 +55,9 @@ const string kStartBitrate = RTC_FIELD "start_bitrate";
|
||||
const string kMaxBitrate = RTC_FIELD "max_bitrate";
|
||||
const string kMinBitrate = RTC_FIELD "min_bitrate";
|
||||
|
||||
// 数据通道设置
|
||||
const string kDataChannelEcho = RTC_FIELD "datachannel_echo";
|
||||
|
||||
static onceToken token([]() {
|
||||
mINI::Instance()[kTimeOutSec] = 15;
|
||||
mINI::Instance()[kExternIP] = "";
|
||||
@@ -65,6 +68,8 @@ static onceToken token([]() {
|
||||
mINI::Instance()[kStartBitrate] = 0;
|
||||
mINI::Instance()[kMaxBitrate] = 0;
|
||||
mINI::Instance()[kMinBitrate] = 0;
|
||||
|
||||
mINI::Instance()[kDataChannelEcho] = true;
|
||||
});
|
||||
|
||||
} // namespace RTC
|
||||
@@ -250,22 +255,47 @@ void WebRtcTransport::OnDtlsTransportApplicationDataReceived(
|
||||
#ifdef ENABLE_SCTP
|
||||
void WebRtcTransport::OnSctpAssociationConnecting(RTC::SctpAssociation *sctpAssociation) {
|
||||
TraceL << getIdentifier();
|
||||
try {
|
||||
NOTICE_EMIT(BroadcastRtcSctpConnectArgs, Broadcast::kBroadcastRtcSctpConnecting, *this);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << "Exception occurred: " << ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnSctpAssociationConnected(RTC::SctpAssociation *sctpAssociation) {
|
||||
InfoL << getIdentifier();
|
||||
try {
|
||||
NOTICE_EMIT(BroadcastRtcSctpConnectArgs, Broadcast::kBroadcastRtcSctpConnected, *this);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << "Exception occurred: " << ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnSctpAssociationFailed(RTC::SctpAssociation *sctpAssociation) {
|
||||
WarnL << getIdentifier();
|
||||
try {
|
||||
NOTICE_EMIT(BroadcastRtcSctpConnectArgs, Broadcast::kBroadcastRtcSctpFailed, *this);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << "Exception occurred: " << ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnSctpAssociationClosed(RTC::SctpAssociation *sctpAssociation) {
|
||||
InfoL << getIdentifier();
|
||||
try {
|
||||
NOTICE_EMIT(BroadcastRtcSctpConnectArgs, Broadcast::kBroadcastRtcSctpClosed, *this);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << "Exception occurred: " << ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcTransport::OnSctpAssociationSendData(
|
||||
RTC::SctpAssociation *sctpAssociation, const uint8_t *data, size_t len) {
|
||||
try {
|
||||
NOTICE_EMIT(BroadcastRtcSctpSendArgs, Broadcast::kBroadcastRtcSctpSend, *this, data, len);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << "Exception occurred: " << ex.what();
|
||||
}
|
||||
_dtls_transport->SendApplicationData(data, len);
|
||||
}
|
||||
|
||||
@@ -274,8 +304,18 @@ void WebRtcTransport::OnSctpAssociationMessageReceived(
|
||||
InfoL << getIdentifier() << " " << streamId << " " << ppid << " " << len << " " << string((char *)msg, len);
|
||||
RTC::SctpStreamParameters params;
|
||||
params.streamId = streamId;
|
||||
// 回显数据
|
||||
_sctp->SendSctpMessage(params, ppid, msg, len);
|
||||
|
||||
GET_CONFIG(bool, datachannel_echo, Rtc::kDataChannelEcho);
|
||||
if (datachannel_echo) {
|
||||
// 回显数据
|
||||
_sctp->SendSctpMessage(params, ppid, msg, len);
|
||||
}
|
||||
|
||||
try {
|
||||
NOTICE_EMIT(BroadcastRtcSctpReceivedArgs, Broadcast::kBroadcastRtcSctpReceived, *this, streamId, ppid, msg, len);
|
||||
} catch (std::exception &ex) {
|
||||
WarnL << "Exception occurred: " << ex.what();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user