Skip to content

Commit

Permalink
Make webrtcTransport.connect() also receive remote IceParameters
Browse files Browse the repository at this point in the history
NOTE: Not working yet due to FBS issues.
  • Loading branch information
ibc committed Feb 16, 2024
1 parent bba4a78 commit 39e3637
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
50 changes: 38 additions & 12 deletions node/src/WebRtcTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ export type IceCandidate = {
export type DtlsParameters = {
role?: DtlsRole;
fingerprints: DtlsFingerprint[];
iceUfrag?: string;
icePwd?: string;
};

/**
Expand Down Expand Up @@ -479,14 +477,17 @@ export class WebRtcTransport<
* @override
*/
async connect({
iceParameters,
dtlsParameters,
}: {
iceParameters?: IceParameters;
dtlsParameters: DtlsParameters;
}): Promise<void> {
logger.debug('connect()');

const requestOffset = createConnectRequest({
builder: this.channel.bufferBuilder,
iceParameters,
dtlsParameters,
});

Expand Down Expand Up @@ -837,19 +838,31 @@ export function parseWebRtcTransportDumpResponse(

function createConnectRequest({
builder,
iceParameters,
dtlsParameters,
}: {
builder: flatbuffers.Builder;
iceParameters?: IceParameters;
dtlsParameters: DtlsParameters;
}): number {
// Serialize ICeParameters if given. This can throw.
const iceParametersOffset = iceParameters
? serializeIceParameters(builder, iceParameters)
: undefined;

// Serialize DtlsParameters. This can throw.
const dtlsParametersOffset = serializeDtlsParameters(builder, dtlsParameters);

const ConnectRequest = FbsWebRtcTransport.ConnectRequest;

// Create request.
return FbsWebRtcTransport.ConnectRequest.createConnectRequest(
builder,
dtlsParametersOffset
);
ConnectRequest.startConnectRequest(builder);
if (iceParametersOffset) {
ConnectRequest.addIceParameters(builder, iceParametersOffset);
}
ConnectRequest.addDtlsParameters(builder, dtlsParametersOffset);

return ConnectRequest.endConnectRequest(builder);
}

function parseGetStatsResponse(
Expand Down Expand Up @@ -918,6 +931,24 @@ function parseDtlsParameters(
};
}

function serializeIceParameters(
builder: flatbuffers.Builder,
iceParameters: IceParameters
): number {
const usernameFragmentOffset = builder.createString(
iceParameters.usernameFragment ?? ''
);
const passwordOffset = builder.createString(iceParameters.password ?? '');
const iceLiteOffset = Boolean(iceParameters.iceLite);

return FbsWebRtcTransport.IceParameters.createIceParameters(
builder,
usernameFragmentOffset,
passwordOffset,
iceLiteOffset
);
}

function serializeDtlsParameters(
builder: flatbuffers.Builder,
dtlsParameters: DtlsParameters
Expand All @@ -942,9 +973,6 @@ function serializeDtlsParameters(
fingerprints
);

const iceUfragOffset = builder.createString(dtlsParameters.iceUfrag ?? '');
const icePwdOffset = builder.createString(dtlsParameters.icePwd ?? '');

const role =
dtlsParameters.role !== undefined
? dtlsRoleToFbs(dtlsParameters.role)
Expand All @@ -953,8 +981,6 @@ function serializeDtlsParameters(
return FbsWebRtcTransport.DtlsParameters.createDtlsParameters(
builder,
fingerprintsOffset,
role,
iceUfragOffset,
icePwdOffset
role
);
}
3 changes: 1 addition & 2 deletions worker/fbs/webRtcTransport.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ enum DtlsState: uint8 {
table DtlsParameters {
fingerprints: [Fingerprint] (required);
role: DtlsRole = AUTO;
ice_ufrag: string;
ice_pwd: string;
}

table IceParameters {
Expand Down Expand Up @@ -97,6 +95,7 @@ table IceCandidate {
}

table ConnectRequest {
ice_parameters: IceParameters;
dtls_parameters: DtlsParameters (required);
}

Expand Down
5 changes: 3 additions & 2 deletions worker/src/RTC/WebRtcTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ namespace RTC
}

const auto* body = request->data->body_as<FBS::WebRtcTransport::ConnectRequest>();
const auto* iceParameters = body->iceParameters();
const auto* dtlsParameters = body->dtlsParameters();

RTC::DtlsTransport::Fingerprint dtlsRemoteFingerprint;
Expand All @@ -463,8 +464,8 @@ namespace RTC

dtlsRemoteRole = RTC::DtlsTransport::RoleFromFbs(dtlsParameters->role());

const std::string iceUsernameFragment = dtlsParameters->iceUfrag()->str();
const std::string icePassword = dtlsParameters->icePwd()->str();
const std::string iceUsernameFragment = iceParameters->usernameFragment()->str();
const std::string icePassword = iceParameters->password()->str();

if (!iceUsernameFragment.empty() && !icePassword.empty())
{
Expand Down

0 comments on commit 39e3637

Please sign in to comment.