From 7dd9e61dc8f365cfdf95cc7b0ae866aa87c71a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sat, 9 Nov 2024 01:21:43 +0100 Subject: [PATCH] Split `RtpStream.ts` into `rtpStreamStatsTypes.ts` and `rtpStreamStatsFbsUtils` Rename `scalabilityModes.ts` tp `scalabilityModesTypes.ts` --- node/src/Consumer.ts | 2 +- node/src/ConsumerTypes.ts | 2 +- node/src/Producer.ts | 2 +- node/src/ProducerTypes.ts | 2 +- node/src/fbsUtils.ts | 2 - node/src/index.ts | 12 ++--- node/src/ortc.ts | 2 +- ...RtpStream.ts => rtpStreamStatsFbsUtils.ts} | 45 +++---------------- node/src/rtpStreamStatsTypes.ts | 38 ++++++++++++++++ node/src/scalabilityModesTypes.ts | 5 +++ ...ilityModes.ts => scalabilityModesUtils.ts} | 12 +++-- node/src/types.ts | 3 +- 12 files changed, 67 insertions(+), 60 deletions(-) rename node/src/{RtpStream.ts => rtpStreamStatsFbsUtils.ts} (78%) create mode 100644 node/src/rtpStreamStatsTypes.ts create mode 100644 node/src/scalabilityModesTypes.ts rename node/src/{scalabilityModes.ts => scalabilityModesUtils.ts} (69%) diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index 02f331ad9b..fe8c2fa924 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -30,7 +30,7 @@ import { parseRtpEncodingParameters, parseRtpParameters, } from './rtpParametersFbsUtils'; -import { parseRtpStreamStats } from './RtpStream'; +import { parseRtpStreamStats } from './rtpStreamStatsFbsUtils'; import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; diff --git a/node/src/ConsumerTypes.ts b/node/src/ConsumerTypes.ts index 94c21db96c..2b1fbf7fd0 100644 --- a/node/src/ConsumerTypes.ts +++ b/node/src/ConsumerTypes.ts @@ -6,7 +6,7 @@ import type { RtpEncodingParameters, RtpParameters, } from './rtpParametersTypes'; -import type { RtpStreamSendStats } from './RtpStream'; +import type { RtpStreamSendStats } from './rtpStreamStatsTypes'; import type { AppData } from './types'; export type ConsumerOptions = { diff --git a/node/src/Producer.ts b/node/src/Producer.ts index f7e5770057..732fc47728 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -17,7 +17,7 @@ import { Channel } from './Channel'; import type { TransportInternal } from './Transport'; import type { MediaKind, RtpParameters } from './rtpParametersTypes'; import { parseRtpParameters } from './rtpParametersFbsUtils'; -import { parseRtpStreamRecvStats } from './RtpStream'; +import { parseRtpStreamRecvStats } from './rtpStreamStatsFbsUtils'; import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; diff --git a/node/src/ProducerTypes.ts b/node/src/ProducerTypes.ts index 8a49d3e14f..989acf72c0 100644 --- a/node/src/ProducerTypes.ts +++ b/node/src/ProducerTypes.ts @@ -1,6 +1,6 @@ import type { EnhancedEventEmitter } from './enhancedEvents'; import type { MediaKind, RtpParameters } from './rtpParametersTypes'; -import type { RtpStreamRecvStats } from './RtpStream'; +import type { RtpStreamRecvStats } from './rtpStreamStatsTypes'; import type { AppData } from './types'; export type ProducerOptions = { diff --git a/node/src/fbsUtils.ts b/node/src/fbsUtils.ts index 56e55c73c1..502a9bc2a3 100644 --- a/node/src/fbsUtils.ts +++ b/node/src/fbsUtils.ts @@ -1,5 +1,3 @@ -import type { Type as FbsRtpParametersType } from './fbs/rtp-parameters'; - /** * Parse flatbuffers vector into an array of the given T. */ diff --git a/node/src/index.ts b/node/src/index.ts index 3a82941f34..c366b0d357 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -2,10 +2,10 @@ import { Logger, LoggerEmitter } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import type { Worker, WorkerSettings } from './WorkerTypes'; import { WorkerImpl, workerBin } from './Worker'; -import * as utils from './utils'; import { supportedRtpCapabilities } from './supportedRtpCapabilities'; import type { RtpCapabilities } from './rtpParametersTypes'; import type * as types from './types'; +import * as utils from './utils'; /** * Expose all types. @@ -18,11 +18,6 @@ export { types }; // eslint-disable-next-line @typescript-eslint/no-require-imports export const version: string = require('../../package.json').version; -/** - * Expose parseScalabilityMode() function. - */ -export { parse as parseScalabilityMode } from './scalabilityModes'; - export type Observer = EnhancedEventEmitter; export type ObserverEvents = { @@ -146,3 +141,8 @@ export async function createWorker< export function getSupportedRtpCapabilities(): RtpCapabilities { return utils.clone(supportedRtpCapabilities); } + +/** + * Expose parseScalabilityMode() function. + */ +export { parseScalabilityMode } from './scalabilityModesUtils'; diff --git a/node/src/ortc.ts b/node/src/ortc.ts index 1a03faa30f..3fa66de16f 100644 --- a/node/src/ortc.ts +++ b/node/src/ortc.ts @@ -1,7 +1,7 @@ import * as h264 from 'h264-profile-level-id'; import * as flatbuffers from 'flatbuffers'; import { supportedRtpCapabilities } from './supportedRtpCapabilities'; -import { parse as parseScalabilityMode } from './scalabilityModes'; +import { parseScalabilityMode } from './scalabilityModesUtils'; import type { RtpCapabilities, MediaKind, diff --git a/node/src/RtpStream.ts b/node/src/rtpStreamStatsFbsUtils.ts similarity index 78% rename from node/src/RtpStream.ts rename to node/src/rtpStreamStatsFbsUtils.ts index 47acfd44a0..96d941e739 100644 --- a/node/src/RtpStream.ts +++ b/node/src/rtpStreamStatsFbsUtils.ts @@ -1,45 +1,12 @@ +import { + RtpStreamRecvStats, + RtpStreamSendStats, + BaseRtpStreamStats, + BitrateByLayer, +} from './rtpStreamStatsTypes'; import * as FbsRtpStream from './fbs/rtp-stream'; import * as FbsRtpParameters from './fbs/rtp-parameters'; -type BitrateByLayer = { [key: string]: number }; - -export type RtpStreamRecvStats = BaseRtpStreamStats & { - type: string; - jitter: number; - packetCount: number; - byteCount: number; - bitrate: number; - bitrateByLayer: BitrateByLayer; -}; - -export type RtpStreamSendStats = BaseRtpStreamStats & { - type: string; - packetCount: number; - byteCount: number; - bitrate: number; -}; - -type BaseRtpStreamStats = { - timestamp: number; - ssrc: number; - rtxSsrc?: number; - rid?: string; - kind: string; - mimeType: string; - packetsLost: number; - fractionLost: number; - packetsDiscarded: number; - packetsRetransmitted: number; - packetsRepaired: number; - nackCount: number; - nackPacketCount: number; - pliCount: number; - firCount: number; - score: number; - roundTripTime?: number; - rtxPacketsDiscarded?: number; -}; - export function parseRtpStreamStats( binary: FbsRtpStream.Stats ): RtpStreamRecvStats | RtpStreamSendStats { diff --git a/node/src/rtpStreamStatsTypes.ts b/node/src/rtpStreamStatsTypes.ts new file mode 100644 index 0000000000..aa806d6c7c --- /dev/null +++ b/node/src/rtpStreamStatsTypes.ts @@ -0,0 +1,38 @@ +export type RtpStreamRecvStats = BaseRtpStreamStats & { + type: string; + jitter: number; + packetCount: number; + byteCount: number; + bitrate: number; + bitrateByLayer: BitrateByLayer; +}; + +export type RtpStreamSendStats = BaseRtpStreamStats & { + type: string; + packetCount: number; + byteCount: number; + bitrate: number; +}; + +export type BaseRtpStreamStats = { + timestamp: number; + ssrc: number; + rtxSsrc?: number; + rid?: string; + kind: string; + mimeType: string; + packetsLost: number; + fractionLost: number; + packetsDiscarded: number; + packetsRetransmitted: number; + packetsRepaired: number; + nackCount: number; + nackPacketCount: number; + pliCount: number; + firCount: number; + score: number; + roundTripTime?: number; + rtxPacketsDiscarded?: number; +}; + +export type BitrateByLayer = { [key: string]: number }; diff --git a/node/src/scalabilityModesTypes.ts b/node/src/scalabilityModesTypes.ts new file mode 100644 index 0000000000..8d66dd8c0d --- /dev/null +++ b/node/src/scalabilityModesTypes.ts @@ -0,0 +1,5 @@ +export type ScalabilityMode = { + spatialLayers: number; + temporalLayers: number; + ksvc: boolean; +}; diff --git a/node/src/scalabilityModes.ts b/node/src/scalabilityModesUtils.ts similarity index 69% rename from node/src/scalabilityModes.ts rename to node/src/scalabilityModesUtils.ts index 291255092a..3cbb70ab3e 100644 --- a/node/src/scalabilityModes.ts +++ b/node/src/scalabilityModesUtils.ts @@ -1,14 +1,12 @@ +import { ScalabilityMode } from './scalabilityModesTypes'; + const ScalabilityModeRegex = new RegExp( '^[LS]([1-9]\\d{0,1})T([1-9]\\d{0,1})(_KEY)?' ); -export type ScalabilityMode = { - spatialLayers: number; - temporalLayers: number; - ksvc: boolean; -}; - -export function parse(scalabilityMode?: string): ScalabilityMode { +export function parseScalabilityMode( + scalabilityMode?: string +): ScalabilityMode { const match = ScalabilityModeRegex.exec(scalabilityMode ?? ''); if (match) { diff --git a/node/src/types.ts b/node/src/types.ts index 002adb8328..53fda44fc1 100644 --- a/node/src/types.ts +++ b/node/src/types.ts @@ -15,9 +15,10 @@ export type * from './RtpObserverTypes'; export type * from './ActiveSpeakerObserverTypes'; export type * from './AudioLevelObserverTypes'; export type * from './rtpParametersTypes'; +export type * from './rtpStreamStatsTypes'; export type * from './sctpParametersTypes'; export type * from './srtpParametersTypes'; -export type * from './scalabilityModes'; +export type * from './scalabilityModesTypes'; // TODO: Here we are exporting real classes rather than types. This should // be exported somehow else rather than in mediasoup.types namespace.