提交 f462f5c4 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

SRTP in PlainRtpTransport may be done. Not tested.

上级 5dd9a605
......@@ -85,6 +85,8 @@ export declare type PlainRtpTransportStat = {
export declare class PlainRtpTransport extends Transport {
/**
* @private
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
......@@ -96,7 +98,7 @@ export declare class PlainRtpTransport extends Transport {
/**
* Transport RTCP tuple.
*/
get rtcpTuple(): TransportTuple;
get rtcpTuple(): TransportTuple | undefined;
/**
* SCTP parameters.
*/
......@@ -118,6 +120,8 @@ export declare class PlainRtpTransport extends Transport {
* @emits newconsumer - (producer: Producer)
* @emits newdataproducer - (dataProducer: DataProducer)
* @emits newdataconsumer - (dataProducer: DataProducer)
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
......@@ -147,8 +151,8 @@ export declare class PlainRtpTransport extends Transport {
* @override
*/
connect({ ip, port, rtcpPort, srtpParameters }: {
ip: string;
port: number;
ip?: string;
port?: number;
rtcpPort?: number;
srtpParameters?: SrtpParameters;
}): Promise<void>;
......
{"version":3,"file":"PlainRtpTransport.d.ts","sourceRoot":"","sources":["../src/PlainRtpTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,cAAc,EAEd,SAAS,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAA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EACJ,QAAQ,EACR,cAAc,EACd,EACD;QACC,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,cAAc,CAAC,EAAE,cAAc,CAAC;KAChC,GACC,OAAO,CAAC,IAAI,CAAC;IAmBhB;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQzD,OAAO,CAAC,0BAA0B;CAmElC"}
\ No newline at end of file
......@@ -31,6 +31,8 @@ class PlainRtpTransport extends Transport_1.Transport {
// - .keyBase64
/**
* @private
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
......@@ -87,6 +89,8 @@ class PlainRtpTransport extends Transport_1.Transport {
* @emits newconsumer - (producer: Producer)
* @emits newdataproducer - (dataProducer: DataProducer)
* @emits newdataconsumer - (dataProducer: DataProducer)
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
......@@ -137,8 +141,10 @@ class PlainRtpTransport extends Transport_1.Transport {
const reqData = { ip, port, rtcpPort, srtpParameters };
const data = await this._channel.request('transport.connect', this._internal, reqData);
// Update data.
this._data.tuple = data.tuple;
this._data.rtcpTuple = data.rtcpTuple;
if (data.tuple)
this._data.tuple = data.tuple;
if (data.rtcpTuple)
this._data.rtcpTuple = data.rtcpTuple;
this._data.srtpParameters = data.srtpParameters;
}
/**
......@@ -154,6 +160,24 @@ class PlainRtpTransport extends Transport_1.Transport {
_handleWorkerNotifications() {
this._channel.on(this._internal.transportId, (event, data) => {
switch (event) {
case 'tuple':
{
const tuple = data.tuple;
this._data.tuple = tuple;
this.safeEmit('tuple', tuple);
// Emit observer event.
this._observer.safeEmit('tuple', tuple);
break;
}
case 'rtcpTuple':
{
const rtcpTuple = data.rtcpTuple;
this._data.rtcpTuple = rtcpTuple;
this.safeEmit('rtcpTuple', rtcpTuple);
// Emit observer event.
this._observer.safeEmit('rtcpTuple', rtcpTuple);
break;
}
case 'sctpstatechange':
{
const sctpState = data.sctpState;
......
......@@ -138,6 +138,8 @@ export class PlainRtpTransport extends Transport
/**
* @private
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
......@@ -172,7 +174,7 @@ export class PlainRtpTransport extends Transport
/**
* Transport RTCP tuple.
*/
get rtcpTuple(): TransportTuple
get rtcpTuple(): TransportTuple | undefined
{
return this._data.rtcpTuple;
}
......@@ -210,6 +212,8 @@ export class PlainRtpTransport extends Transport
* @emits newconsumer - (producer: Producer)
* @emits newdataproducer - (dataProducer: DataProducer)
* @emits newdataconsumer - (dataProducer: DataProducer)
* @emits tuple - (tuple: TransportTuple)
* @emits rtcpTuple - (rtcpTuple: TransportTuple)
* @emits sctpstatechange - (sctpState: SctpState)
* @emits trace - (trace: TransportTraceEventData)
*/
......@@ -276,8 +280,8 @@ export class PlainRtpTransport extends Transport
srtpParameters
}:
{
ip: string;
port: number;
ip?: string;
port?: number;
rtcpPort?: number;
srtpParameters?: SrtpParameters;
}
......@@ -291,8 +295,12 @@ export class PlainRtpTransport extends Transport
await this._channel.request('transport.connect', this._internal, reqData);
// Update data.
this._data.tuple = data.tuple;
this._data.rtcpTuple = data.rtcpTuple;
if (data.tuple)
this._data.tuple = data.tuple;
if (data.rtcpTuple)
this._data.rtcpTuple = data.rtcpTuple;
this._data.srtpParameters = data.srtpParameters;
}
......@@ -315,6 +323,34 @@ export class PlainRtpTransport extends Transport
{
switch (event)
{
case 'tuple':
{
const tuple = data.tuple as TransportTuple;
this._data.tuple = tuple;
this.safeEmit('tuple', tuple);
// Emit observer event.
this._observer.safeEmit('tuple', tuple);
break;
}
case 'rtcpTuple':
{
const rtcpTuple = data.rtcpTuple as TransportTuple;
this._data.rtcpTuple = rtcpTuple;
this.safeEmit('rtcpTuple', rtcpTuple);
// Emit observer event.
this._observer.safeEmit('rtcpTuple', rtcpTuple);
break;
}
case 'sctpstatechange':
{
const sctpState = data.sctpState as SctpState;
......
......@@ -35,6 +35,7 @@ namespace RTC
private:
bool IsConnected() const override;
bool HasSrtp() const;
bool IsSrtpReady() const;
void SendRtpPacket(RTC::RtpPacket* packet, RTC::Transport::onSendCallback* cb = nullptr) override;
void SendRtcpPacket(RTC::RTCP::Packet* packet) override;
void SendRtcpCompoundPacket(RTC::RTCP::CompoundPacket* packet) override;
......@@ -69,6 +70,7 @@ namespace RTC
};
std::string srtpKey;
std::string srtpKeyBase64;
bool connectCalled{ false }; // Whether connect() was succesfully called.
};
} // namespace RTC
......
......@@ -115,7 +115,7 @@ namespace RTC
RTC::Transport::FillJson(jsonObject);
// Add tuple.
if (this->tuple != nullptr)
if (this->tuple)
{
this->tuple->FillJson(jsonObject["tuple"]);
}
......@@ -159,7 +159,7 @@ namespace RTC
// Add type.
jsonObject["type"] = "pipe-transport";
if (this->tuple != nullptr)
if (this->tuple)
{
this->tuple->FillJson(jsonObject["tuple"]);
}
......@@ -188,7 +188,7 @@ namespace RTC
case Channel::Request::MethodId::TRANSPORT_CONNECT:
{
// Ensure this method is not called twice.
if (this->tuple != nullptr)
if (this->tuple)
MS_THROW_ERROR("connect() already called");
try
......@@ -333,7 +333,7 @@ namespace RTC
reinterpret_cast<struct sockaddr_in*>(&this->remoteAddrStorage));
if (err != 0)
MS_ABORT("uv_ip4_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ip4_addr() failed: %s", uv_strerror(err));
break;
}
......@@ -346,7 +346,7 @@ namespace RTC
reinterpret_cast<struct sockaddr_in6*>(&this->remoteAddrStorage));
if (err != 0)
MS_ABORT("uv_ip6_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ip6_addr() failed: %s", uv_strerror(err));
break;
}
......@@ -402,7 +402,7 @@ namespace RTC
inline bool PipeTransport::IsConnected() const
{
return this->tuple != nullptr;
return this->tuple;
}
inline bool PipeTransport::HasSrtp() const
......@@ -533,14 +533,6 @@ namespace RTC
if (!IsConnected())
return;
// Verify that the packet's tuple matches our tuple.
if (!this->tuple->Compare(tuple))
{
MS_DEBUG_TAG(rtp, "ignoring RTP packet from unknown IP:port");
return;
}
// Decrypt the SRTP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &len))
{
......@@ -565,6 +557,14 @@ namespace RTC
return;
}
// Verify that the packet's tuple matches our tuple.
if (!this->tuple->Compare(tuple))
{
MS_DEBUG_TAG(rtp, "ignoring RTP packet from unknown IP:port");
return;
}
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len);
if (packet == nullptr)
......@@ -586,6 +586,12 @@ namespace RTC
if (!IsConnected())
return;
// Decrypt the SRTCP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &len))
{
return;
}
// Verify that the packet's tuple matches our tuple.
if (!this->tuple->Compare(tuple))
{
......@@ -594,10 +600,6 @@ namespace RTC
return;
}
// Decrypt the SRTCP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &len))
return;
RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len);
if (packet == nullptr)
......
......@@ -5,6 +5,7 @@
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "Channel/Notifier.hpp"
namespace RTC
{
......@@ -192,7 +193,7 @@ namespace RTC
jsonObject["multiSource"] = this->multiSource;
// Add tuple.
if (this->tuple != nullptr)
if (this->tuple)
{
this->tuple->FillJson(jsonObject["tuple"]);
}
......@@ -213,7 +214,7 @@ namespace RTC
// Add rtcpTuple.
if (!this->rtcpMux)
{
if (this->rtcpTuple != nullptr)
if (this->rtcpTuple)
{
this->rtcpTuple->FillJson(jsonObject["rtcpTuple"]);
}
......@@ -265,7 +266,7 @@ namespace RTC
// Add multiSource.
jsonObject["multiSource"] = this->multiSource;
if (this->tuple != nullptr)
if (this->tuple)
{
// Add tuple.
this->tuple->FillJson(jsonObject["tuple"]);
......@@ -286,7 +287,7 @@ namespace RTC
}
// Add rtcpTuple.
if (!this->rtcpMux && this->rtcpTuple != nullptr)
if (!this->rtcpMux && this->rtcpTuple)
this->rtcpTuple->FillJson(jsonObject["rtcpTuple"]);
}
......@@ -298,16 +299,16 @@ namespace RTC
{
case Channel::Request::MethodId::TRANSPORT_CONNECT:
{
// Ensure this method is not called twice.
if (this->connectCalled)
MS_THROW_ERROR("connect() already called");
// Reject if comedia mode or multiSource is set.
if (this->comedia)
MS_THROW_ERROR("cannot call connect() when comedia mode is set");
else if (this->multiSource)
MS_THROW_ERROR("cannot call connect() when multiSource is set");
// Ensure this method is not called twice.
if (this->tuple != nullptr)
MS_THROW_ERROR("connect() already called");
try
{
std::string ip;
......@@ -315,50 +316,6 @@ namespace RTC
uint16_t rtcpPort{ 0u };
std::string srtpKeyBase64;
auto jsonIpIt = request->data.find("ip");
if (jsonIpIt == request->data.end() || !jsonIpIt->is_string())
MS_THROW_TYPE_ERROR("missing ip");
ip = jsonIpIt->get<std::string>();
// This may throw.
Utils::IP::NormalizeIp(ip);
auto jsonPortIt = request->data.find("port");
// clang-format off
if (
jsonPortIt == request->data.end() ||
!Utils::Json::IsPositiveInteger(*jsonPortIt)
)
// clang-format on
{
MS_THROW_TYPE_ERROR("missing port");
}
port = jsonPortIt->get<uint16_t>();
auto jsonRtcpPortIt = request->data.find("rtcpPort");
// clang-format off
if (
jsonRtcpPortIt != request->data.end() &&
Utils::Json::IsPositiveInteger(*jsonRtcpPortIt)
)
// clang-format on
{
if (this->rtcpMux)
MS_THROW_TYPE_ERROR("cannot set rtcpPort with rtcpMux enabled");
rtcpPort = jsonRtcpPortIt->get<uint16_t>();
}
else
{
if (!this->rtcpMux)
MS_THROW_TYPE_ERROR("missing rtcpPort (required with rtcpMux disabled)");
}
auto jsonSrtpParametersIt = request->data.find("srtpParameters");
if (!HasSrtp() && jsonSrtpParametersIt != request->data.end())
......@@ -462,62 +419,65 @@ namespace RTC
delete[] srtpRemoteKey;
}
int err;
switch (Utils::IP::GetFamily(ip))
if (!this->comedia && !this->multiSource)
{
case AF_INET:
{
err = uv_ip4_addr(
ip.c_str(),
static_cast<int>(port),
reinterpret_cast<struct sockaddr_in*>(&this->remoteAddrStorage));
auto jsonIpIt = request->data.find("ip");
if (err != 0)
MS_ABORT("uv_ip4_addr() failed: %s", uv_strerror(err));
if (jsonIpIt == request->data.end() || !jsonIpIt->is_string())
MS_THROW_TYPE_ERROR("missing ip");
break;
}
ip = jsonIpIt->get<std::string>();
case AF_INET6:
{
err = uv_ip6_addr(
ip.c_str(),
static_cast<int>(port),
reinterpret_cast<struct sockaddr_in6*>(&this->remoteAddrStorage));
// This may throw.
Utils::IP::NormalizeIp(ip);
if (err != 0)
MS_ABORT("uv_ip6_addr() failed: %s", uv_strerror(err));
auto jsonPortIt = request->data.find("port");
break;
// clang-format off
if (
jsonPortIt == request->data.end() ||
!Utils::Json::IsPositiveInteger(*jsonPortIt)
)
// clang-format on
{
MS_THROW_TYPE_ERROR("missing port");
}
default:
port = jsonPortIt->get<uint16_t>();
auto jsonRtcpPortIt = request->data.find("rtcpPort");
// clang-format off
if (
jsonRtcpPortIt != request->data.end() &&
Utils::Json::IsPositiveInteger(*jsonRtcpPortIt)
)
// clang-format on
{
MS_THROW_ERROR("invalid IP '%s'", ip.c_str());
}
}
if (this->rtcpMux)
MS_THROW_TYPE_ERROR("cannot set rtcpPort with rtcpMux enabled");
// Create the tuple.
this->tuple = new RTC::TransportTuple(
this->udpSocket, reinterpret_cast<struct sockaddr*>(&this->remoteAddrStorage));
rtcpPort = jsonRtcpPortIt->get<uint16_t>();
}
else
{
if (!this->rtcpMux)
MS_THROW_TYPE_ERROR("missing rtcpPort (required with rtcpMux disabled)");
}
if (!this->listenIp.announcedIp.empty())
this->tuple->SetLocalAnnouncedIp(this->listenIp.announcedIp);
int err;
if (!this->rtcpMux)
{
switch (Utils::IP::GetFamily(ip))
{
case AF_INET:
{
err = uv_ip4_addr(
ip.c_str(),
static_cast<int>(rtcpPort),
reinterpret_cast<struct sockaddr_in*>(&this->rtcpRemoteAddrStorage));
static_cast<int>(port),
reinterpret_cast<struct sockaddr_in*>(&this->remoteAddrStorage));
if (err != 0)
MS_ABORT("uv_ip4_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ip4_addr() failed: %s", uv_strerror(err));
break;
}
......@@ -526,11 +486,11 @@ namespace RTC
{
err = uv_ip6_addr(
ip.c_str(),
static_cast<int>(rtcpPort),
reinterpret_cast<struct sockaddr_in6*>(&this->rtcpRemoteAddrStorage));
static_cast<int>(port),
reinterpret_cast<struct sockaddr_in6*>(&this->remoteAddrStorage));
if (err != 0)
MS_ABORT("uv_ip6_addr() failed: %s", uv_strerror(err));
MS_THROW_ERROR("uv_ip6_addr() failed: %s", uv_strerror(err));
break;
}
......@@ -542,11 +502,56 @@ namespace RTC
}
// Create the tuple.
this->rtcpTuple = new RTC::TransportTuple(
this->rtcpUdpSocket, reinterpret_cast<struct sockaddr*>(&this->rtcpRemoteAddrStorage));
this->tuple = new RTC::TransportTuple(
this->udpSocket, reinterpret_cast<struct sockaddr*>(&this->remoteAddrStorage));
if (!this->listenIp.announcedIp.empty())
this->rtcpTuple->SetLocalAnnouncedIp(this->listenIp.announcedIp);
this->tuple->SetLocalAnnouncedIp(this->listenIp.announcedIp);
if (!this->rtcpMux)
{
switch (Utils::IP::GetFamily(ip))
{
case AF_INET:
{
err = uv_ip4_addr(
ip.c_str(),
static_cast<int>(rtcpPort),
reinterpret_cast<struct sockaddr_in*>(&this->rtcpRemoteAddrStorage));
if (err != 0)
MS_THROW_ERROR("uv_ip4_addr() failed: %s", uv_strerror(err));
break;
}
case AF_INET6:
{
err = uv_ip6_addr(
ip.c_str(),
static_cast<int>(rtcpPort),
reinterpret_cast<struct sockaddr_in6*>(&this->rtcpRemoteAddrStorage));
if (err != 0)
MS_THROW_ERROR("uv_ip6_addr() failed: %s", uv_strerror(err));
break;
}
default:
{
MS_THROW_ERROR("invalid IP '%s'", ip.c_str());
}
}
// Create the tuple.
this->rtcpTuple = new RTC::TransportTuple(
this->rtcpUdpSocket,
reinterpret_cast<struct sockaddr*>(&this->rtcpRemoteAddrStorage));
if (!this->listenIp.announcedIp.empty())
this->rtcpTuple->SetLocalAnnouncedIp(this->listenIp.announcedIp);
}
}
}
catch (const MediaSoupError& error)
......@@ -566,12 +571,15 @@ namespace RTC
throw;
}
this->connectCalled = true;
// Tell the caller about the selected local DTLS role.
json data = json::object();
this->tuple->FillJson(data["tuple"]);
if (this->tuple)
this->tuple->FillJson(data["tuple"]);
if (!this->rtcpMux)
if (!this->rtcpMux && this->rtcpTuple)
this->rtcpTuple->FillJson(data["rtcpTuple"]);
if (HasSrtp())
......@@ -603,7 +611,7 @@ namespace RTC
inline bool PlainRtpTransport::IsConnected() const
{
return this->tuple != nullptr;
return this->tuple;
}
inline bool PlainRtpTransport::HasSrtp() const
......@@ -611,6 +619,11 @@ namespace RTC
return !this->srtpKey.empty();
}
inline bool PlainRtpTransport::IsSrtpReady() const
{
return HasSrtp() && this->srtpSendSession && this->srtpRecvSession;
}
void PlainRtpTransport::SendRtpPacket(RTC::RtpPacket* packet, RTC::Transport::onSendCallback* cb)
{
MS_TRACE();
......@@ -739,8 +752,32 @@ namespace RTC
{
MS_TRACE();
// TODO: Check SRTP and connect() called, but may be it was called just to provide
// us with the remote SRTP parameters, etc.
if (HasSrtp() && !IsSrtpReady())
return;
// Decrypt the SRTP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast<uint8_t*>(data), &len))
{
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len);
if (!packet)
{
MS_WARN_TAG(srtp, "DecryptSrtp() failed due to an invalid RTP packet");
}
else
{
MS_WARN_TAG(
srtp,
"DecryptSrtp() failed [ssrc:%" PRIu32 ", payloadType:%" PRIu8 ", seq:%" PRIu16 "]",
packet->GetSsrc(),
packet->GetPayloadType(),
packet->GetSequenceNumber());
delete packet;
}
return;
}
// If multiSource is set allow it without any checking.
if (this->multiSource)
......@@ -769,7 +806,16 @@ namespace RTC
// If not yet connected do it now.
if (!wasConnected)
{
// Notify the Node PlainRtpTransport.
json data = json::object();
this->tuple->FillJson(data["tuple"]);
Channel::Notifier::Emit(this->id, "tuple", data);
RTC::Transport::Connected();
}
}
// Otherwise, if RTP tuple is set, verify that it matches the origin
// of the packet.
......@@ -798,6 +844,15 @@ namespace RTC
{
MS_TRACE();
if (HasSrtp() && !IsSrtpReady())
return;
// Decrypt the SRTCP packet.
if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &len))
{
return;
}
// If multiSource is set allow it without any checking.
if (this->multiSource)
{
......@@ -825,7 +880,16 @@ namespace RTC
// If not yet connected do it now.
if (!wasConnected)
{
// Notify the Node PlainRtpTransport.
json data = json::object();
this->tuple->FillJson(data["tuple"]);
Channel::Notifier::Emit(this->id, "tuple", data);
RTC::Transport::Connected();
}
}
// Otherwise, if RTCP-mux is unset and RTCP tuple is unset, set it if we
// are in comedia mode.
......@@ -844,6 +908,13 @@ namespace RTC
if (!this->listenIp.announcedIp.empty())
this->rtcpTuple->SetLocalAnnouncedIp(this->listenIp.announcedIp);
// Notify the Node PlainRtpTransport.
json data = json::object();
this->rtcpTuple->FillJson(data["rtcpTuple"]);
Channel::Notifier::Emit(this->id, "rtcpTuple", data);
}
// If RTCP-mux verify that the packet's tuple matches our RTP tuple.
else if (this->rtcpMux && !this->tuple->Compare(tuple))
......@@ -907,7 +978,16 @@ namespace RTC
// If not yet connected do it now.
if (!wasConnected)
{
// Notify the Node PlainRtpTransport.
json data = json::object();
this->tuple->FillJson(data["tuple"]);
Channel::Notifier::Emit(this->id, "tuple", data);
RTC::Transport::Connected();
}
}
// Otherwise, if RTP tuple is set, verify that it matches the origin
// of the packet.
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论