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

- Worker: Set local DTLS role as "server" by default.

- Node: Expose local DTLS role in the Transport API.
上级 9ca93b4c
...@@ -49,9 +49,9 @@ class Transport extends EventEmitter ...@@ -49,9 +49,9 @@ class Transport extends EventEmitter
return this._data.iceLocalCandidates; return this._data.iceLocalCandidates;
} }
get dtlsLocalFingerprints() get dtlsLocalParameters()
{ {
return this._data.dtlsLocalFingerprints; return this._data.dtlsLocalParameters;
} }
/** /**
...@@ -132,11 +132,9 @@ class Transport extends EventEmitter ...@@ -132,11 +132,9 @@ class Transport extends EventEmitter
{ {
logger.debug('"transport.setRemoteDtlsParameters" request succeeded'); logger.debug('"transport.setRemoteDtlsParameters" request succeeded');
// TODO: Handle content of data and append it to this._data. // Take the .role field of the response data and append it to our
// TODO: do we want to return data? It is better to document that // this._data.dtlsLocalParameters
// at this point the DTLS related stuff is available via API this._data.dtlsLocalParameters.role = data.role;
return data;
}) })
.catch((error) => .catch((error) =>
{ {
......
...@@ -147,7 +147,7 @@ app.put('/test-transport', function(req) ...@@ -147,7 +147,7 @@ app.put('/test-transport', function(req)
am.fingerprint = am.fingerprint =
{ {
type : 'sha-256', type : 'sha-256',
hash : mediasoup.extra.dtlsFingerprintToSDP(transport.dtlsLocalFingerprints['sha-256']) hash : mediasoup.extra.dtlsFingerprintToSDP(transport.dtlsLocalParameters.fingerprints['sha-256'])
}; };
// SDP offer is always 'a=setup:actpass' // SDP offer is always 'a=setup:actpass'
am.setup = 'passive'; am.setup = 'passive';
...@@ -163,7 +163,7 @@ app.put('/test-transport', function(req) ...@@ -163,7 +163,7 @@ app.put('/test-transport', function(req)
// Update the transport with the remote DTLS parameters // Update the transport with the remote DTLS parameters
setTimeout(() => setTimeout(() =>
{ {
transport.start( transport.setRemoteDtlsParameters(
{ {
role : 'client', role : 'client',
fingerprint : fingerprint :
......
...@@ -125,7 +125,7 @@ namespace RTC ...@@ -125,7 +125,7 @@ namespace RTC
bool icePairedWithUseCandidate = false; bool icePairedWithUseCandidate = false;
// Others (DTLS). // Others (DTLS).
bool remoteDtlsParametersGiven = false; bool remoteDtlsParametersGiven = false;
RTC::DTLSTransport::Role dtlsLocalRole = RTC::DTLSTransport::Role::AUTO; RTC::DTLSTransport::Role dtlsLocalRole = RTC::DTLSTransport::Role::SERVER;
}; };
/* Inline methods. */ /* Inline methods. */
......
...@@ -240,7 +240,11 @@ namespace RTC ...@@ -240,7 +240,11 @@ namespace RTC
static const Json::StaticString k_iceLocalCandidates("iceLocalCandidates"); static const Json::StaticString k_iceLocalCandidates("iceLocalCandidates");
static const Json::StaticString v_RTP("RTP"); static const Json::StaticString v_RTP("RTP");
static const Json::StaticString v_RTCP("RTCP"); static const Json::StaticString v_RTCP("RTCP");
static const Json::StaticString k_dtlsLocalFingerprints("dtlsLocalFingerprints"); static const Json::StaticString k_dtlsLocalParameters("dtlsLocalParameters");
static const Json::StaticString k_fingerprints("fingerprints");
static const Json::StaticString k_role("role");
static const Json::StaticString v_client("client");
static const Json::StaticString v_server("server");
Json::Value data; Json::Value data;
...@@ -261,8 +265,21 @@ namespace RTC ...@@ -261,8 +265,21 @@ namespace RTC
data[k_iceLocalCandidates].append(iceCandidate.toJson()); data[k_iceLocalCandidates].append(iceCandidate.toJson());
} }
// Add `dtlsLocalFingerprints`. // Add `dtlsLocalParameters.fingerprints`.
data[k_dtlsLocalFingerprints] = RTC::DTLSTransport::GetLocalFingerprints(); data[k_dtlsLocalParameters][k_fingerprints] = RTC::DTLSTransport::GetLocalFingerprints();
// Add `dtlsLocalParameters.role`.
switch (this->dtlsLocalRole)
{
case RTC::DTLSTransport::Role::CLIENT:
data[k_dtlsLocalParameters][k_role] = v_client;
break;
case RTC::DTLSTransport::Role::SERVER:
data[k_dtlsLocalParameters][k_role] = v_server;
break;
default:
MS_ABORT("invalid local DTLS role");
}
return data; return data;
} }
...@@ -360,6 +377,8 @@ namespace RTC ...@@ -360,6 +377,8 @@ namespace RTC
case RTC::DTLSTransport::Role::SERVER: case RTC::DTLSTransport::Role::SERVER:
this->dtlsLocalRole = RTC::DTLSTransport::Role::CLIENT; this->dtlsLocalRole = RTC::DTLSTransport::Role::CLIENT;
break; break;
// If the peer has "auto" role let us become "client" so DTLS
// happens faster.
case RTC::DTLSTransport::Role::AUTO: case RTC::DTLSTransport::Role::AUTO:
this->dtlsLocalRole = RTC::DTLSTransport::Role::CLIENT; this->dtlsLocalRole = RTC::DTLSTransport::Role::CLIENT;
break; break;
...@@ -370,19 +389,18 @@ namespace RTC ...@@ -370,19 +389,18 @@ namespace RTC
return; return;
} }
// TODO: Provide the local DTLS role in the response so the JS can expose it.
Json::Value data; Json::Value data;
switch (this->dtlsLocalRole) switch (this->dtlsLocalRole)
{ {
case RTC::DTLSTransport::Role::CLIENT: case RTC::DTLSTransport::Role::CLIENT:
data["localDtlsRole"] = "client"; data[k_role] = v_client;
break; break;
case RTC::DTLSTransport::Role::SERVER: case RTC::DTLSTransport::Role::SERVER:
data["localDtlsRole"] = "server"; data[k_role] = v_server;
break; break;
default: default:
MS_ABORT("KAKAKAKAKAKA"); // TODO jeje MS_ABORT("invalid local DTLS role");
} }
request->Accept(data); request->Accept(data);
...@@ -423,9 +441,7 @@ namespace RTC ...@@ -423,9 +441,7 @@ namespace RTC
switch (this->dtlsLocalRole) switch (this->dtlsLocalRole)
{ {
// If 'client' then wait for the first Binding with USE-CANDIDATE. // If 'client' then wait for the first Binding with USE-CANDIDATE.
// If 'auto' then behave as 'client' since we are always ICE controlled.
case RTC::DTLSTransport::Role::CLIENT: case RTC::DTLSTransport::Role::CLIENT:
case RTC::DTLSTransport::Role::AUTO:
if (this->icePairedWithUseCandidate) if (this->icePairedWithUseCandidate)
{ {
MS_DEBUG("running DTLS transport in 'client' role"); MS_DEBUG("running DTLS transport in 'client' role");
...@@ -444,8 +460,11 @@ namespace RTC ...@@ -444,8 +460,11 @@ namespace RTC
} }
break; break;
case RTC::DTLSTransport::Role::AUTO:
MS_ABORT("local DTLS role cannot be 'auto'");
case RTC::DTLSTransport::Role::NONE: case RTC::DTLSTransport::Role::NONE:
MS_ABORT("local DTLS role cannot be none"); MS_ABORT("local DTLS role not set");
} }
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论