Skip to content

Commit

Permalink
fbs: FBS WebRtcTransport (#1153)
Browse files Browse the repository at this point in the history
fbs: FBS WebRtcTransport

---------

Co-authored-by: Iñaki Baz Castillo <[email protected]>
  • Loading branch information
jmillan and ibc authored Sep 13, 2023
1 parent 6f12821 commit 0f137a7
Show file tree
Hide file tree
Showing 37 changed files with 19,479 additions and 17,476 deletions.
3 changes: 2 additions & 1 deletion node/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { AudioLevelObserver, AudioLevelObserverOptions } from './AudioLevelObser
import { RtpCapabilities, RtpCodecCapability } from './RtpParameters';
import { NumSctpStreams } from './SctpParameters';
import { AppData, Either } from './types';
import { cryptoSuiteToFbs } from './SrtpParameters';
import * as FbsActiveSpeakerObserver from './fbs/active-speaker-observer';
import * as FbsAudioLevelObserver from './fbs/audio-level-observer';
import * as FbsRequest from './fbs/request';
Expand Down Expand Up @@ -710,7 +711,7 @@ export class Router<RouterAppData extends AppData = AppData>
rtcpMux,
comedia,
enableSrtp,
srtpCryptoSuite
cryptoSuiteToFbs(srtpCryptoSuite)
);

const requestOffset = new FbsRouter.CreatePlainTransportRequestT(
Expand Down
51 changes: 45 additions & 6 deletions node/src/SrtpParameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as flatbuffers from 'flatbuffers';
import * as FbsTransport from './fbs/transport';
import * as FbsSrtpParameters from './fbs/srtp-parameters';

/**
* SRTP parameters.
Expand All @@ -26,10 +26,50 @@ export type SrtpCryptoSuite =
| 'AES_CM_128_HMAC_SHA1_80'
| 'AES_CM_128_HMAC_SHA1_32';

export function parseSrtpParameters(binary: FbsTransport.SrtpParameters): SrtpParameters
export function cryptoSuiteFromFbs(binary: FbsSrtpParameters.SrtpCryptoSuite): SrtpCryptoSuite
{
switch (binary)
{
case FbsSrtpParameters.SrtpCryptoSuite.AEAD_AES_256_GCM:
return 'AEAD_AES_256_GCM';

case FbsSrtpParameters.SrtpCryptoSuite.AEAD_AES_128_GCM:
return 'AEAD_AES_128_GCM';

case FbsSrtpParameters.SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80:
return 'AES_CM_128_HMAC_SHA1_80';

case FbsSrtpParameters.SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32:
return 'AES_CM_128_HMAC_SHA1_32';
}
}

export function cryptoSuiteToFbs(cryptoSuite: SrtpCryptoSuite)
: FbsSrtpParameters.SrtpCryptoSuite
{
switch (cryptoSuite)
{
case 'AEAD_AES_256_GCM':
return FbsSrtpParameters.SrtpCryptoSuite.AEAD_AES_256_GCM;

case 'AEAD_AES_128_GCM':
return FbsSrtpParameters.SrtpCryptoSuite.AEAD_AES_128_GCM;

case 'AES_CM_128_HMAC_SHA1_80':
return FbsSrtpParameters.SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80;

case 'AES_CM_128_HMAC_SHA1_32':
return FbsSrtpParameters.SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_32;

default:
throw new TypeError(`invalid srtp crypto suite: ${cryptoSuite}`);
}
}

export function parseSrtpParameters(binary: FbsSrtpParameters.SrtpParameters): SrtpParameters
{
return {
cryptoSuite : binary.cryptoSuite()! as SrtpCryptoSuite,
cryptoSuite : cryptoSuiteFromFbs(binary.cryptoSuite()),
keyBase64 : binary.keyBase64()!
};
}
Expand All @@ -38,10 +78,9 @@ export function serializeSrtpParameters(
builder:flatbuffers.Builder, srtpParameters:SrtpParameters
): number
{
const cryptoSuiteOffset = builder.createString(srtpParameters.cryptoSuite);
const keyBase64Offset = builder.createString(srtpParameters.keyBase64);

return FbsTransport.SrtpParameters.createSrtpParameters(
builder, cryptoSuiteOffset, keyBase64Offset
return FbsSrtpParameters.SrtpParameters.createSrtpParameters(
builder, cryptoSuiteToFbs(srtpParameters.cryptoSuite), keyBase64Offset
);
}
2 changes: 1 addition & 1 deletion node/src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ export class Transport
{
type = 'sctp';
sctpStreamParameters =
utils.clone(dataProducer.sctpStreamParameters) as SctpStreamParameters;
(utils.clone(dataProducer.sctpStreamParameters) ?? {}) as SctpStreamParameters;

// Override if given.
if (ordered !== undefined)
Expand Down
Loading

0 comments on commit 0f137a7

Please sign in to comment.