From 52eeb3659ed8c1da863102b56264a2373759ed24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 8 Nov 2024 15:12:33 +0100 Subject: [PATCH 01/14] Add TypeScript interfaces for all exported classes ## Details - `mediasoup.types` namespace no longer exports `Worker`, `Router`, `Producer`, etc classes in `types` but instead it exports `WorkerInterface`, `RouterInterface`, `ProducerInterface`, etc. - NOTE: This is a breaking change somehow, but just at TS level. - Use the new interfaces everywhere. - This makes it easier for applications to create mediasoup mocks. ## TODO - How to export as interface/types the functions and consts exposed by `index.ts` such as `createWorker()`, `setLogEventListeners()`, `getSupportedRtpCapabilities()`, `observer`, etc? - In the future we may want to move those interfaces/types to another separate package so a Node application that only depends on mediasoup types doesn't need to install mediaosup. Even if we don't do that, we should change things so `types.ts` doesn't export **anything** that depends on compiled FBS types. --- node/src/ActiveSpeakerObserver.ts | 58 +-- node/src/ActiveSpeakerObserverInterface.ts | 47 +++ node/src/AudioLevelObserver.ts | 85 ++--- node/src/AudioLevelObserverInterface.ts | 69 ++++ node/src/Consumer.ts | 330 +++------------- node/src/ConsumerInterface.ts | 318 ++++++++++++++++ node/src/DataConsumer.ts | 150 ++------ node/src/DataConsumerInterface.ts | 162 ++++++++ node/src/DataProducer.ts | 85 +---- node/src/DataProducerInterface.ts | 124 ++++++ node/src/DirectTransport.ts | 68 ++-- node/src/DirectTransportInterface.ts | 59 +++ node/src/PipeTransport.ts | 183 +++------ node/src/PipeTransportInterface.ts | 173 +++++++++ node/src/PlainTransport.ts | 164 ++------ node/src/PlainTransportInterface.ts | 180 +++++++++ node/src/Producer.ts | 176 ++------- node/src/ProducerInterface.ts | 202 ++++++++++ node/src/Router.ts | 346 ++++++----------- node/src/RouterInterface.ts | 258 +++++++++++++ node/src/RtpObserver.ts | 42 +-- node/src/RtpObserverInterface.ts | 56 +++ node/src/Transport.ts | 396 +++++--------------- node/src/TransportInterface.ts | 307 +++++++++++++++ node/src/WebRtcServer.ts | 84 +---- node/src/WebRtcServerInterface.ts | 98 +++++ node/src/WebRtcTransport.ts | 260 ++----------- node/src/WebRtcTransportInterface.ts | 277 ++++++++++++++ node/src/Worker.ts | 260 ++----------- node/src/WorkerInterface.ts | 255 +++++++++++++ node/src/index.ts | 11 +- node/src/test/test-ActiveSpeakerObserver.ts | 12 +- node/src/test/test-AudioLevelObserver.ts | 4 +- node/src/test/test-Consumer.ts | 19 +- node/src/test/test-DataConsumer.ts | 12 +- node/src/test/test-DataProducer.ts | 8 +- node/src/test/test-DirectTransport.ts | 7 +- node/src/test/test-PipeTransport.ts | 34 +- node/src/test/test-PlainTransport.ts | 4 +- node/src/test/test-Producer.ts | 15 +- node/src/test/test-Router.ts | 11 +- node/src/test/test-WebRtcServer.ts | 61 +-- node/src/test/test-WebRtcTransport.ts | 14 +- node/src/test/test-multiopus.ts | 6 +- node/src/test/test-node-sctp.ts | 10 +- node/src/types.ts | 38 +- node/src/utils.ts | 2 +- 47 files changed, 3308 insertions(+), 2232 deletions(-) create mode 100644 node/src/ActiveSpeakerObserverInterface.ts create mode 100644 node/src/AudioLevelObserverInterface.ts create mode 100644 node/src/ConsumerInterface.ts create mode 100644 node/src/DataConsumerInterface.ts create mode 100644 node/src/DataProducerInterface.ts create mode 100644 node/src/DirectTransportInterface.ts create mode 100644 node/src/PipeTransportInterface.ts create mode 100644 node/src/PlainTransportInterface.ts create mode 100644 node/src/ProducerInterface.ts create mode 100644 node/src/RouterInterface.ts create mode 100644 node/src/RtpObserverInterface.ts create mode 100644 node/src/TransportInterface.ts create mode 100644 node/src/WebRtcServerInterface.ts create mode 100644 node/src/WebRtcTransportInterface.ts create mode 100644 node/src/WorkerInterface.ts diff --git a/node/src/ActiveSpeakerObserver.ts b/node/src/ActiveSpeakerObserver.ts index 609e6581e5..10f6875057 100644 --- a/node/src/ActiveSpeakerObserver.ts +++ b/node/src/ActiveSpeakerObserver.ts @@ -1,57 +1,33 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - RtpObserver, - RtpObserverEvents, - RtpObserverObserverEvents, - RtpObserverConstructorOptions, -} from './RtpObserver'; -import { Producer } from './Producer'; + ActiveSpeakerObserverInterface, + ActiveSpeakerObserverDominantSpeaker, + ActiveSpeakerObserverEvents, + ActiveSpeakerObserverObserver, + ActiveSpeakerObserverObserverEvents, +} from './ActiveSpeakerObserverInterface'; +import { RtpObserverInterface } from './RtpObserverInterface'; +import { RtpObserver, RtpObserverConstructorOptions } from './RtpObserver'; import { AppData } from './types'; import { Event, Notification } from './fbs/notification'; import * as FbsActiveSpeakerObserver from './fbs/active-speaker-observer'; -export type ActiveSpeakerObserverOptions< - ActiveSpeakerObserverAppData extends AppData = AppData, -> = { - interval?: number; - - /** - * Custom application data. - */ - appData?: ActiveSpeakerObserverAppData; -}; - -export type ActiveSpeakerObserverDominantSpeaker = { - /** - * The audio Producer instance. - */ - producer: Producer; -}; - -export type ActiveSpeakerObserverEvents = RtpObserverEvents & { - dominantspeaker: [ActiveSpeakerObserverDominantSpeaker]; -}; - -export type ActiveSpeakerObserverObserver = - EnhancedEventEmitter; - -export type ActiveSpeakerObserverObserverEvents = RtpObserverObserverEvents & { - dominantspeaker: [ActiveSpeakerObserverDominantSpeaker]; -}; - type RtpObserverObserverConstructorOptions = RtpObserverConstructorOptions; const logger = new Logger('ActiveSpeakerObserver'); export class ActiveSpeakerObserver< - ActiveSpeakerObserverAppData extends AppData = AppData, -> extends RtpObserver< - ActiveSpeakerObserverAppData, - ActiveSpeakerObserverEvents, - ActiveSpeakerObserverObserver -> { + ActiveSpeakerObserverAppData extends AppData = AppData, + > + extends RtpObserver< + ActiveSpeakerObserverAppData, + ActiveSpeakerObserverEvents, + ActiveSpeakerObserverObserver + > + implements RtpObserverInterface, ActiveSpeakerObserverInterface +{ /** * @private */ diff --git a/node/src/ActiveSpeakerObserverInterface.ts b/node/src/ActiveSpeakerObserverInterface.ts new file mode 100644 index 0000000000..3e8bd0e3d9 --- /dev/null +++ b/node/src/ActiveSpeakerObserverInterface.ts @@ -0,0 +1,47 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + RtpObserverInterface, + RtpObserverEvents, + RtpObserverObserverEvents, +} from './RtpObserverInterface'; +import { ProducerInterface } from './ProducerInterface'; +import { AppData } from './types'; + +export type ActiveSpeakerObserverOptions< + ActiveSpeakerObserverAppData extends AppData = AppData, +> = { + interval?: number; + + /** + * Custom application data. + */ + appData?: ActiveSpeakerObserverAppData; +}; + +export type ActiveSpeakerObserverDominantSpeaker = { + /** + * The audio Producer instance. + */ + producer: ProducerInterface; +}; + +export type ActiveSpeakerObserverEvents = RtpObserverEvents & { + dominantspeaker: [ActiveSpeakerObserverDominantSpeaker]; +}; + +export type ActiveSpeakerObserverObserver = + EnhancedEventEmitter; + +export type ActiveSpeakerObserverObserverEvents = RtpObserverObserverEvents & { + dominantspeaker: [ActiveSpeakerObserverDominantSpeaker]; +}; + +export interface ActiveSpeakerObserverInterface< + ActiveSpeakerObserverAppData extends AppData = AppData, +> extends RtpObserverInterface< + ActiveSpeakerObserverAppData, + ActiveSpeakerObserverEvents, + ActiveSpeakerObserverObserver + > { + get observer(): ActiveSpeakerObserverObserver; +} diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index d429933954..bea9bb8a02 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -1,80 +1,35 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - RtpObserver, - RtpObserverEvents, - RtpObserverObserverEvents, - RtpObserverConstructorOptions, -} from './RtpObserver'; -import { Producer } from './Producer'; + AudioLevelObserverInterface, + AudioLevelObserverVolume, + AudioLevelObserverEvents, + AudioLevelObserverObserver, + AudioLevelObserverObserverEvents, +} from './AudioLevelObserverInterface'; +import { RtpObserverInterface } from './RtpObserverInterface'; +import { RtpObserver, RtpObserverConstructorOptions } from './RtpObserver'; +import { ProducerInterface } from './ProducerInterface'; import { AppData } from './types'; import * as utils from './utils'; import { Event, Notification } from './fbs/notification'; import * as FbsAudioLevelObserver from './fbs/audio-level-observer'; -export type AudioLevelObserverOptions< - AudioLevelObserverAppData extends AppData = AppData, -> = { - /** - * Maximum number of entries in the 'volumes”' event. Default 1. - */ - maxEntries?: number; - - /** - * Minimum average volume (in dBvo from -127 to 0) for entries in the - * 'volumes' event. Default -80. - */ - threshold?: number; - - /** - * Interval in ms for checking audio volumes. Default 1000. - */ - interval?: number; - - /** - * Custom application data. - */ - appData?: AudioLevelObserverAppData; -}; - -export type AudioLevelObserverVolume = { - /** - * The audio Producer instance. - */ - producer: Producer; - - /** - * The average volume (in dBvo from -127 to 0) of the audio Producer in the - * last interval. - */ - volume: number; -}; - -export type AudioLevelObserverEvents = RtpObserverEvents & { - volumes: [AudioLevelObserverVolume[]]; - silence: []; -}; - -export type AudioLevelObserverObserver = - EnhancedEventEmitter; - -export type AudioLevelObserverObserverEvents = RtpObserverObserverEvents & { - volumes: [AudioLevelObserverVolume[]]; - silence: []; -}; - type AudioLevelObserverConstructorOptions = RtpObserverConstructorOptions; const logger = new Logger('AudioLevelObserver'); export class AudioLevelObserver< - AudioLevelObserverAppData extends AppData = AppData, -> extends RtpObserver< - AudioLevelObserverAppData, - AudioLevelObserverEvents, - AudioLevelObserverObserver -> { + AudioLevelObserverAppData extends AppData = AppData, + > + extends RtpObserver< + AudioLevelObserverAppData, + AudioLevelObserverEvents, + AudioLevelObserverObserver + > + implements RtpObserverInterface, AudioLevelObserverInterface +{ /** * @private */ @@ -125,7 +80,9 @@ export class AudioLevelObserver< volume, }) ) - .filter(({ producer }: { producer: Producer }) => producer); + .filter( + ({ producer }: { producer: ProducerInterface }) => producer + ); if (volumes.length > 0) { this.safeEmit('volumes', volumes); diff --git a/node/src/AudioLevelObserverInterface.ts b/node/src/AudioLevelObserverInterface.ts new file mode 100644 index 0000000000..ce808b39b6 --- /dev/null +++ b/node/src/AudioLevelObserverInterface.ts @@ -0,0 +1,69 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + RtpObserverInterface, + RtpObserverEvents, + RtpObserverObserverEvents, +} from './RtpObserverInterface'; +import { ProducerInterface } from './ProducerInterface'; +import { AppData } from './types'; + +export type AudioLevelObserverOptions< + AudioLevelObserverAppData extends AppData = AppData, +> = { + /** + * Maximum number of entries in the 'volumes”' event. Default 1. + */ + maxEntries?: number; + + /** + * Minimum average volume (in dBvo from -127 to 0) for entries in the + * 'volumes' event. Default -80. + */ + threshold?: number; + + /** + * Interval in ms for checking audio volumes. Default 1000. + */ + interval?: number; + + /** + * Custom application data. + */ + appData?: AudioLevelObserverAppData; +}; + +export type AudioLevelObserverVolume = { + /** + * The audio Producer instance. + */ + producer: ProducerInterface; + + /** + * The average volume (in dBvo from -127 to 0) of the audio Producer in the + * last interval. + */ + volume: number; +}; + +export type AudioLevelObserverEvents = RtpObserverEvents & { + volumes: [AudioLevelObserverVolume[]]; + silence: []; +}; + +export type AudioLevelObserverObserver = + EnhancedEventEmitter; + +export type AudioLevelObserverObserverEvents = RtpObserverObserverEvents & { + volumes: [AudioLevelObserverVolume[]]; + silence: []; +}; + +export interface AudioLevelObserverInterface< + AudioLevelObserverAppData extends AppData = AppData, +> extends RtpObserverInterface< + AudioLevelObserverAppData, + AudioLevelObserverEvents, + AudioLevelObserverObserver + > { + get observer(): AudioLevelObserverObserver; +} diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index 5945f8993b..31bb0d0736 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -1,17 +1,37 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; +import { + ConsumerInterface, + ConsumerType, + ConsumerScore, + ConsumerLayers, + ConsumerDump, + SimpleConsumerDump, + SimulcastConsumerDump, + SvcConsumerDump, + PipeConsumerDump, + BaseConsumerDump, + RtpStreamDump, + RtpStreamParametersDump, + RtxStreamDump, + RtxStreamParameters, + ConsumerStat, + ConsumerTraceEventType, + ConsumerTraceEventData, + ConsumerEvents, + ConsumerObserver, + ConsumerObserverEvents, +} from './ConsumerInterface'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; -import { ProducerStat } from './Producer'; +import { ProducerStat } from './ProducerInterface'; import { MediaKind, - RtpCapabilities, - RtpEncodingParameters, RtpParameters, parseRtpEncodingParameters, parseRtpParameters, } from './RtpParameters'; -import { parseRtpStreamStats, RtpStreamSendStats } from './RtpStream'; +import { parseRtpStreamStats } from './RtpStream'; import { AppData } from './types'; import * as utils from './utils'; import { Event, Notification } from './fbs/notification'; @@ -25,200 +45,6 @@ import * as FbsRtxStream from './fbs/rtx-stream'; import { Type as FbsRtpParametersType } from './fbs/rtp-parameters'; import * as FbsRtpParameters from './fbs/rtp-parameters'; -export type ConsumerOptions = { - /** - * The id of the Producer to consume. - */ - producerId: string; - - /** - * RTP capabilities of the consuming endpoint. - */ - rtpCapabilities: RtpCapabilities; - - /** - * Whether the consumer must start in paused mode. Default false. - * - * When creating a video Consumer, it's recommended to set paused to true, - * then transmit the Consumer parameters to the consuming endpoint and, once - * the consuming endpoint has created its local side Consumer, unpause the - * server side Consumer using the resume() method. This is an optimization - * to make it possible for the consuming endpoint to render the video as far - * as possible. If the server side Consumer was created with paused: false, - * mediasoup will immediately request a key frame to the remote Producer and - * suych a key frame may reach the consuming endpoint even before it's ready - * to consume it, generating “black” video until the device requests a keyframe - * by itself. - */ - paused?: boolean; - - /** - * The MID for the Consumer. If not specified, a sequentially growing - * number will be assigned. - */ - mid?: string; - - /** - * Preferred spatial and temporal layer for simulcast or SVC media sources. - * If unset, the highest ones are selected. - */ - preferredLayers?: ConsumerLayers; - - /** - * Whether this Consumer should enable RTP retransmissions, storing sent RTP - * and processing the incoming RTCP NACK from the remote Consumer. If not set - * it's true by default for video codecs and false for audio codecs. If set - * to true, NACK will be enabled if both endpoints (mediasoup and the remote - * Consumer) support NACK for this codec. When it comes to audio codecs, just - * OPUS supports NACK. - */ - enableRtx?: boolean; - - /** - * Whether this Consumer should ignore DTX packets (only valid for Opus codec). - * If set, DTX packets are not forwarded to the remote Consumer. - */ - ignoreDtx?: boolean; - - /** - * Whether this Consumer should consume all RTP streams generated by the - * Producer. - */ - pipe?: boolean; - - /** - * Custom application data. - */ - appData?: ConsumerAppData; -}; - -/** - * Valid types for 'trace' event. - */ -export type ConsumerTraceEventType = - | 'rtp' - | 'keyframe' - | 'nack' - | 'pli' - | 'fir'; - -/** - * 'trace' event data. - */ -export type ConsumerTraceEventData = { - /** - * Trace type. - */ - type: ConsumerTraceEventType; - - /** - * Event timestamp. - */ - timestamp: number; - - /** - * Event direction. - */ - direction: 'in' | 'out'; - - /** - * Per type information. - */ - info: any; -}; - -export type ConsumerScore = { - /** - * The score of the RTP stream of the consumer. - */ - score: number; - - /** - * The score of the currently selected RTP stream of the producer. - */ - producerScore: number; - - /** - * The scores of all RTP streams in the producer ordered by encoding (just - * useful when the producer uses simulcast). - */ - producerScores: number[]; -}; - -export type ConsumerLayers = { - /** - * The spatial layer index (from 0 to N). - */ - spatialLayer: number; - - /** - * The temporal layer index (from 0 to N). - */ - temporalLayer?: number; -}; - -export type ConsumerStat = RtpStreamSendStats; - -/** - * Consumer type. - */ -export type ConsumerType = 'simple' | 'simulcast' | 'svc' | 'pipe'; - -export type ConsumerEvents = { - transportclose: []; - producerclose: []; - producerpause: []; - producerresume: []; - score: [ConsumerScore]; - layerschange: [ConsumerLayers?]; - trace: [ConsumerTraceEventData]; - rtp: [Buffer]; - listenererror: [string, Error]; - // Private events. - '@close': []; - '@producerclose': []; -}; - -export type ConsumerObserver = EnhancedEventEmitter; - -export type ConsumerObserverEvents = { - close: []; - pause: []; - resume: []; - score: [ConsumerScore]; - layerschange: [ConsumerLayers?]; - trace: [ConsumerTraceEventData]; -}; - -export type SimpleConsumerDump = BaseConsumerDump & { - type: string; - rtpStream: RtpStreamDump; -}; - -export type SimulcastConsumerDump = BaseConsumerDump & { - type: string; - rtpStream: RtpStreamDump; - preferredSpatialLayer: number; - targetSpatialLayer: number; - currentSpatialLayer: number; - preferredTemporalLayer: number; - targetTemporalLayer: number; - currentTemporalLayer: number; -}; - -export type SvcConsumerDump = SimulcastConsumerDump; - -export type PipeConsumerDump = BaseConsumerDump & { - type: string; - rtpStreams: RtpStreamDump[]; -}; - -export type ConsumerDump = - | SimpleConsumerDump - | SimulcastConsumerDump - | SvcConsumerDump - | PipeConsumerDump; - type ConsumerInternal = TransportInternal & { consumerId: string; }; @@ -230,62 +56,12 @@ type ConsumerData = { type: ConsumerType; }; -type BaseConsumerDump = { - id: string; - producerId: string; - kind: MediaKind; - rtpParameters: RtpParameters; - consumableRtpEncodings?: RtpEncodingParameters[]; - supportedCodecPayloadTypes: number[]; - traceEventTypes: string[]; - paused: boolean; - producerPaused: boolean; - priority: number; -}; - -type RtpStreamParameters = { - encodingIdx: number; - ssrc: number; - payloadType: number; - mimeType: string; - clockRate: number; - rid?: string; - cname: string; - rtxSsrc?: number; - rtxPayloadType?: number; - useNack: boolean; - usePli: boolean; - useFir: boolean; - useInBandFec: boolean; - useDtx: boolean; - spatialLayers: number; - temporalLayers: number; -}; - -type RtpStreamDump = { - params: RtpStreamParameters; - score: number; - rtxStream?: RtxStreamDump; -}; - -type RtxStreamParameters = { - ssrc: number; - payloadType: number; - mimeType: string; - clockRate: number; - rrid?: string; - cname: string; -}; - -type RtxStreamDump = { - params: RtxStreamParameters; -}; - const logger = new Logger('Consumer'); -export class Consumer< - ConsumerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export class Consumer + extends EnhancedEventEmitter + implements ConsumerInterface +{ // Internal data. readonly #internal: ConsumerInternal; @@ -1000,9 +776,25 @@ function parseConsumerLayers(data: FbsConsumer.ConsumerLayers): ConsumerLayers { }; } +function parseRtpStream(data: FbsRtpStream.Dump): RtpStreamDump { + const params = parseRtpStreamParameters(data.params()!); + + let rtxStream: RtxStreamDump | undefined; + + if (data.rtxStream()) { + rtxStream = parseRtxStream(data.rtxStream()!); + } + + return { + params, + score: data.score(), + rtxStream, + }; +} + function parseRtpStreamParameters( data: FbsRtpStream.Params -): RtpStreamParameters { +): RtpStreamParametersDump { return { encodingIdx: data.encodingIdx(), ssrc: data.ssrc(), @@ -1024,6 +816,14 @@ function parseRtpStreamParameters( }; } +function parseRtxStream(data: FbsRtxStream.RtxDump): RtxStreamDump { + const params = parseRtxStreamParameters(data.params()!); + + return { + params, + }; +} + function parseRtxStreamParameters( data: FbsRtxStream.Params ): RtxStreamParameters { @@ -1037,30 +837,6 @@ function parseRtxStreamParameters( }; } -function parseRtxStream(data: FbsRtxStream.RtxDump): RtxStreamDump { - const params = parseRtxStreamParameters(data.params()!); - - return { - params, - }; -} - -function parseRtpStream(data: FbsRtpStream.Dump): RtpStreamDump { - const params = parseRtpStreamParameters(data.params()!); - - let rtxStream: RtxStreamDump | undefined; - - if (data.rtxStream()) { - rtxStream = parseRtxStream(data.rtxStream()!); - } - - return { - params, - score: data.score(), - rtxStream, - }; -} - function parseBaseConsumerDump( data: FbsConsumer.BaseConsumerDump ): BaseConsumerDump { diff --git a/node/src/ConsumerInterface.ts b/node/src/ConsumerInterface.ts new file mode 100644 index 0000000000..2bd9ef9486 --- /dev/null +++ b/node/src/ConsumerInterface.ts @@ -0,0 +1,318 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { ProducerStat } from './ProducerInterface'; +import { + MediaKind, + RtpCapabilities, + RtpEncodingParameters, + RtpParameters, +} from './RtpParameters'; +import { RtpStreamSendStats } from './RtpStream'; +import { AppData } from './types'; + +export type ConsumerOptions = { + /** + * The id of the Producer to consume. + */ + producerId: string; + + /** + * RTP capabilities of the consuming endpoint. + */ + rtpCapabilities: RtpCapabilities; + + /** + * Whether the consumer must start in paused mode. Default false. + * + * When creating a video Consumer, it's recommended to set paused to true, + * then transmit the Consumer parameters to the consuming endpoint and, once + * the consuming endpoint has created its local side Consumer, unpause the + * server side Consumer using the resume() method. This is an optimization + * to make it possible for the consuming endpoint to render the video as far + * as possible. If the server side Consumer was created with paused: false, + * mediasoup will immediately request a key frame to the remote Producer and + * suych a key frame may reach the consuming endpoint even before it's ready + * to consume it, generating “black” video until the device requests a keyframe + * by itself. + */ + paused?: boolean; + + /** + * The MID for the Consumer. If not specified, a sequentially growing + * number will be assigned. + */ + mid?: string; + + /** + * Preferred spatial and temporal layer for simulcast or SVC media sources. + * If unset, the highest ones are selected. + */ + preferredLayers?: ConsumerLayers; + + /** + * Whether this Consumer should enable RTP retransmissions, storing sent RTP + * and processing the incoming RTCP NACK from the remote Consumer. If not set + * it's true by default for video codecs and false for audio codecs. If set + * to true, NACK will be enabled if both endpoints (mediasoup and the remote + * Consumer) support NACK for this codec. When it comes to audio codecs, just + * OPUS supports NACK. + */ + enableRtx?: boolean; + + /** + * Whether this Consumer should ignore DTX packets (only valid for Opus codec). + * If set, DTX packets are not forwarded to the remote Consumer. + */ + ignoreDtx?: boolean; + + /** + * Whether this Consumer should consume all RTP streams generated by the + * Producer. + */ + pipe?: boolean; + + /** + * Custom application data. + */ + appData?: ConsumerAppData; +}; + +/** + * Consumer type. + */ +export type ConsumerType = 'simple' | 'simulcast' | 'svc' | 'pipe'; + +export type ConsumerScore = { + /** + * The score of the RTP stream of the consumer. + */ + score: number; + + /** + * The score of the currently selected RTP stream of the producer. + */ + producerScore: number; + + /** + * The scores of all RTP streams in the producer ordered by encoding (just + * useful when the producer uses simulcast). + */ + producerScores: number[]; +}; + +export type ConsumerLayers = { + /** + * The spatial layer index (from 0 to N). + */ + spatialLayer: number; + + /** + * The temporal layer index (from 0 to N). + */ + temporalLayer?: number; +}; + +export type ConsumerDump = + | SimpleConsumerDump + | SimulcastConsumerDump + | SvcConsumerDump + | PipeConsumerDump; + +export type SimpleConsumerDump = BaseConsumerDump & { + type: string; + rtpStream: RtpStreamDump; +}; + +export type SimulcastConsumerDump = BaseConsumerDump & { + type: string; + rtpStream: RtpStreamDump; + preferredSpatialLayer: number; + targetSpatialLayer: number; + currentSpatialLayer: number; + preferredTemporalLayer: number; + targetTemporalLayer: number; + currentTemporalLayer: number; +}; + +export type SvcConsumerDump = SimulcastConsumerDump; + +export type PipeConsumerDump = BaseConsumerDump & { + type: string; + rtpStreams: RtpStreamDump[]; +}; + +export type BaseConsumerDump = { + id: string; + producerId: string; + kind: MediaKind; + rtpParameters: RtpParameters; + consumableRtpEncodings?: RtpEncodingParameters[]; + supportedCodecPayloadTypes: number[]; + traceEventTypes: string[]; + paused: boolean; + producerPaused: boolean; + priority: number; +}; + +export type RtpStreamDump = { + params: RtpStreamParametersDump; + score: number; + rtxStream?: RtxStreamDump; +}; + +export type RtpStreamParametersDump = { + encodingIdx: number; + ssrc: number; + payloadType: number; + mimeType: string; + clockRate: number; + rid?: string; + cname: string; + rtxSsrc?: number; + rtxPayloadType?: number; + useNack: boolean; + usePli: boolean; + useFir: boolean; + useInBandFec: boolean; + useDtx: boolean; + spatialLayers: number; + temporalLayers: number; +}; + +export type RtxStreamDump = { + params: RtxStreamParameters; +}; + +export type RtxStreamParameters = { + ssrc: number; + payloadType: number; + mimeType: string; + clockRate: number; + rrid?: string; + cname: string; +}; + +export type ConsumerStat = RtpStreamSendStats; + +/** + * Valid types for 'trace' event. + */ +export type ConsumerTraceEventType = + | 'rtp' + | 'keyframe' + | 'nack' + | 'pli' + | 'fir'; + +/** + * 'trace' event data. + */ +export type ConsumerTraceEventData = { + /** + * Trace type. + */ + type: ConsumerTraceEventType; + + /** + * Event timestamp. + */ + timestamp: number; + + /** + * Event direction. + */ + direction: 'in' | 'out'; + + /** + * Per type information. + */ + info: any; +}; + +export type ConsumerEvents = { + transportclose: []; + producerclose: []; + producerpause: []; + producerresume: []; + score: [ConsumerScore]; + layerschange: [ConsumerLayers?]; + trace: [ConsumerTraceEventData]; + rtp: [Buffer]; + listenererror: [string, Error]; + // Private events. + '@close': []; + '@producerclose': []; +}; + +export type ConsumerObserver = EnhancedEventEmitter; + +export type ConsumerObserverEvents = { + close: []; + pause: []; + resume: []; + score: [ConsumerScore]; + layerschange: [ConsumerLayers?]; + trace: [ConsumerTraceEventData]; +}; + +export interface ConsumerInterface + extends EnhancedEventEmitter { + get id(): string; + + get producerId(): string; + + get closed(): boolean; + + get kind(): MediaKind; + + get rtpParameters(): RtpParameters; + + get type(): ConsumerType; + + get paused(): boolean; + + get producerPaused(): boolean; + + get priority(): number; + + get score(): ConsumerScore; + + get preferredLayers(): ConsumerLayers | undefined; + + get currentLayers(): ConsumerLayers | undefined; + + get appData(): ConsumerAppData; + + set appData(appData: ConsumerAppData); + + get observer(): ConsumerObserver; + + close(): void; + + /** + * Transport was closed. + * + * @private + */ + transportClosed(): void; + + dump(): Promise; + + getStats(): Promise<(ConsumerStat | ProducerStat)[]>; + + pause(): Promise; + + resume(): Promise; + + setPreferredLayers({ + spatialLayer, + temporalLayer, + }: ConsumerLayers): Promise; + + setPriority(priority: number): Promise; + + unsetPriority(): Promise; + + requestKeyFrame(): Promise; + + enableTraceEvent(types?: ConsumerTraceEventType[]): Promise; +} diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index f05b998d17..256232b7e9 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -1,5 +1,14 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; +import { + DataConsumerInterface, + DataConsumerType, + DataConsumerDump, + DataConsumerStat, + DataConsumerEvents, + DataConsumerObserver, + DataConsumerObserverEvents, +} from './DataConsumerInterface'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; import { @@ -14,100 +23,6 @@ import * as FbsRequest from './fbs/request'; import * as FbsDataConsumer from './fbs/data-consumer'; import * as FbsDataProducer from './fbs/data-producer'; -export type DataConsumerOptions = - { - /** - * The id of the DataProducer to consume. - */ - dataProducerId: string; - - /** - * Just if consuming over SCTP. - * Whether data messages must be received in order. If true the messages will - * be sent reliably. Defaults to the value in the DataProducer if it has type - * 'sctp' or to true if it has type 'direct'. - */ - ordered?: boolean; - - /** - * Just if consuming over SCTP. - * When ordered is false indicates the time (in milliseconds) after which a - * SCTP packet will stop being retransmitted. Defaults to the value in the - * DataProducer if it has type 'sctp' or unset if it has type 'direct'. - */ - maxPacketLifeTime?: number; - - /** - * Just if consuming over SCTP. - * When ordered is false indicates the maximum number of times a packet will - * be retransmitted. Defaults to the value in the DataProducer if it has type - * 'sctp' or unset if it has type 'direct'. - */ - maxRetransmits?: number; - - /** - * Whether the data consumer must start in paused mode. Default false. - */ - paused?: boolean; - - /** - * Subchannels this data consumer initially subscribes to. - * Only used in case this data consumer receives messages from a local data - * producer that specifies subchannel(s) when calling send(). - */ - subchannels?: number[]; - - /** - * Custom application data. - */ - appData?: DataConsumerAppData; - }; - -export type DataConsumerStat = { - type: string; - timestamp: number; - label: string; - protocol: string; - messagesSent: number; - bytesSent: number; - bufferedAmount: number; -}; - -/** - * DataConsumer type. - */ -export type DataConsumerType = 'sctp' | 'direct'; - -export type DataConsumerEvents = { - transportclose: []; - dataproducerclose: []; - dataproducerpause: []; - dataproducerresume: []; - message: [Buffer, number]; - sctpsendbufferfull: []; - bufferedamountlow: [number]; - listenererror: [string, Error]; - // Private events. - '@close': []; - '@dataproducerclose': []; -}; - -export type DataConsumerObserver = - EnhancedEventEmitter; - -export type DataConsumerObserverEvents = { - close: []; - pause: []; - resume: []; -}; - -type DataConsumerDump = DataConsumerData & { - id: string; - paused: boolean; - dataProducerPaused: boolean; - subchannels: number[]; -}; - type DataConsumerInternal = TransportInternal & { dataConsumerId: string; }; @@ -123,9 +38,10 @@ type DataConsumerData = { const logger = new Logger('DataConsumer'); -export class DataConsumer< - DataConsumerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export class DataConsumer + extends EnhancedEventEmitter + implements DataConsumerInterface +{ // Internal data. readonly #internal: DataConsumerInternal; @@ -447,6 +363,26 @@ export class DataConsumer< ); } + /** + * Get buffered amount size. + */ + async getBufferedAmount(): Promise { + logger.debug('getBufferedAmount()'); + + const response = await this.#channel.request( + FbsRequest.Method.DATACONSUMER_GET_BUFFERED_AMOUNT, + undefined, + undefined, + this.#internal.dataConsumerId + ); + + const data = new FbsDataConsumer.GetBufferedAmountResponse(); + + response.body(data); + + return data.bufferedAmount(); + } + /** * Send data. */ @@ -513,26 +449,6 @@ export class DataConsumer< ); } - /** - * Get buffered amount size. - */ - async getBufferedAmount(): Promise { - logger.debug('getBufferedAmount()'); - - const response = await this.#channel.request( - FbsRequest.Method.DATACONSUMER_GET_BUFFERED_AMOUNT, - undefined, - undefined, - this.#internal.dataConsumerId - ); - - const data = new FbsDataConsumer.GetBufferedAmountResponse(); - - response.body(data); - - return data.bufferedAmount(); - } - /** * Set subchannels. */ diff --git a/node/src/DataConsumerInterface.ts b/node/src/DataConsumerInterface.ts new file mode 100644 index 0000000000..bc74283c51 --- /dev/null +++ b/node/src/DataConsumerInterface.ts @@ -0,0 +1,162 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { SctpStreamParameters } from './SctpParameters'; +import { AppData } from './types'; + +export type DataConsumerOptions = + { + /** + * The id of the DataProducer to consume. + */ + dataProducerId: string; + + /** + * Just if consuming over SCTP. + * Whether data messages must be received in order. If true the messages will + * be sent reliably. Defaults to the value in the DataProducer if it has type + * 'sctp' or to true if it has type 'direct'. + */ + ordered?: boolean; + + /** + * Just if consuming over SCTP. + * When ordered is false indicates the time (in milliseconds) after which a + * SCTP packet will stop being retransmitted. Defaults to the value in the + * DataProducer if it has type 'sctp' or unset if it has type 'direct'. + */ + maxPacketLifeTime?: number; + + /** + * Just if consuming over SCTP. + * When ordered is false indicates the maximum number of times a packet will + * be retransmitted. Defaults to the value in the DataProducer if it has type + * 'sctp' or unset if it has type 'direct'. + */ + maxRetransmits?: number; + + /** + * Whether the data consumer must start in paused mode. Default false. + */ + paused?: boolean; + + /** + * Subchannels this data consumer initially subscribes to. + * Only used in case this data consumer receives messages from a local data + * producer that specifies subchannel(s) when calling send(). + */ + subchannels?: number[]; + + /** + * Custom application data. + */ + appData?: DataConsumerAppData; + }; + +/** + * DataConsumer type. + */ +export type DataConsumerType = 'sctp' | 'direct'; + +export type DataConsumerDump = { + id: string; + paused: boolean; + dataProducerPaused: boolean; + subchannels: number[]; + dataProducerId: string; + type: DataConsumerType; + sctpStreamParameters?: SctpStreamParameters; + label: string; + protocol: string; + bufferedAmountLowThreshold: number; +}; + +export type DataConsumerStat = { + type: string; + timestamp: number; + label: string; + protocol: string; + messagesSent: number; + bytesSent: number; + bufferedAmount: number; +}; + +export type DataConsumerEvents = { + transportclose: []; + dataproducerclose: []; + dataproducerpause: []; + dataproducerresume: []; + message: [Buffer, number]; + sctpsendbufferfull: []; + bufferedamountlow: [number]; + listenererror: [string, Error]; + // Private events. + '@close': []; + '@dataproducerclose': []; +}; + +export type DataConsumerObserver = + EnhancedEventEmitter; + +export type DataConsumerObserverEvents = { + close: []; + pause: []; + resume: []; +}; + +export interface DataConsumerInterface< + DataConsumerAppData extends AppData = AppData, +> extends EnhancedEventEmitter { + get id(): string; + + get dataProducerId(): string; + + get closed(): boolean; + + get type(): DataConsumerType; + + get sctpStreamParameters(): SctpStreamParameters | undefined; + + get label(): string; + + get protocol(): string; + + get paused(): boolean; + + get dataProducerPaused(): boolean; + + get subchannels(): number[]; + + get appData(): DataConsumerAppData; + + set appData(appData: DataConsumerAppData); + + get observer(): DataConsumerObserver; + + close(): void; + + /** + * Transport was closed. + * + * @private + */ + transportClosed(): void; + + dump(): Promise; + + getStats(): Promise; + + pause(): Promise; + + resume(): Promise; + + setBufferedAmountLowThreshold(threshold: number): Promise; + + getBufferedAmount(): Promise; + + send(message: string | Buffer, ppid?: number): Promise; + + setSubchannels(subchannels: number[]): Promise; + + addSubchannel(subchannel: number): Promise; + + removeSubchannel(subchannel: number): Promise; +} diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index e4ac42884e..3a5df11969 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -1,5 +1,14 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; +import { + DataProducerInterface, + DataProducerType, + DataProducerDump, + DataProducerStat, + DataProducerEvents, + DataProducerObserver, + DataProducerObserverEvents, +} from './DataProducerInterface'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; import { @@ -12,75 +21,6 @@ import * as FbsNotification from './fbs/notification'; import * as FbsRequest from './fbs/request'; import * as FbsDataProducer from './fbs/data-producer'; -export type DataProducerOptions = - { - /** - * DataProducer id (just for Router.pipeToRouter() method). - */ - id?: string; - - /** - * SCTP parameters defining how the endpoint is sending the data. - * Just if messages are sent over SCTP. - */ - sctpStreamParameters?: SctpStreamParameters; - - /** - * A label which can be used to distinguish this DataChannel from others. - */ - label?: string; - - /** - * Name of the sub-protocol used by this DataChannel. - */ - protocol?: string; - - /** - * Whether the data producer must start in paused mode. Default false. - */ - paused?: boolean; - - /** - * Custom application data. - */ - appData?: DataProducerAppData; - }; - -export type DataProducerStat = { - type: string; - timestamp: number; - label: string; - protocol: string; - messagesReceived: number; - bytesReceived: number; -}; - -/** - * DataProducer type. - */ -export type DataProducerType = 'sctp' | 'direct'; - -export type DataProducerEvents = { - transportclose: []; - listenererror: [string, Error]; - // Private events. - '@close': []; -}; - -export type DataProducerObserver = - EnhancedEventEmitter; - -export type DataProducerObserverEvents = { - close: []; - pause: []; - resume: []; -}; - -type DataProducerDump = DataProducerData & { - id: string; - paused: boolean; -}; - type DataProducerInternal = TransportInternal & { dataProducerId: string; }; @@ -94,9 +34,10 @@ type DataProducerData = { const logger = new Logger('DataProducer'); -export class DataProducer< - DataProducerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export class DataProducer + extends EnhancedEventEmitter + implements DataProducerInterface +{ // Internal data. readonly #internal: DataProducerInternal; diff --git a/node/src/DataProducerInterface.ts b/node/src/DataProducerInterface.ts new file mode 100644 index 0000000000..e84650d892 --- /dev/null +++ b/node/src/DataProducerInterface.ts @@ -0,0 +1,124 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { SctpStreamParameters } from './SctpParameters'; +import { AppData } from './types'; + +export type DataProducerOptions = + { + /** + * DataProducer id (just for Router.pipeToRouter() method). + */ + id?: string; + + /** + * SCTP parameters defining how the endpoint is sending the data. + * Just if messages are sent over SCTP. + */ + sctpStreamParameters?: SctpStreamParameters; + + /** + * A label which can be used to distinguish this DataChannel from others. + */ + label?: string; + + /** + * Name of the sub-protocol used by this DataChannel. + */ + protocol?: string; + + /** + * Whether the data producer must start in paused mode. Default false. + */ + paused?: boolean; + + /** + * Custom application data. + */ + appData?: DataProducerAppData; + }; + +/** + * DataProducer type. + */ +export type DataProducerType = 'sctp' | 'direct'; + +export type DataProducerDump = { + id: string; + paused: boolean; + type: DataProducerType; + sctpStreamParameters?: SctpStreamParameters; + label: string; + protocol: string; +}; + +export type DataProducerStat = { + type: string; + timestamp: number; + label: string; + protocol: string; + messagesReceived: number; + bytesReceived: number; +}; + +export type DataProducerEvents = { + transportclose: []; + listenererror: [string, Error]; + // Private events. + '@close': []; +}; + +export type DataProducerObserver = + EnhancedEventEmitter; + +export type DataProducerObserverEvents = { + close: []; + pause: []; + resume: []; +}; + +export interface DataProducerInterface< + DataProducerAppData extends AppData = AppData, +> extends EnhancedEventEmitter { + get id(): string; + + get closed(): boolean; + + get type(): DataProducerType; + + get sctpStreamParameters(): SctpStreamParameters | undefined; + + get label(): string; + + get protocol(): string; + + get paused(): boolean; + + get appData(): DataProducerAppData; + + set appData(appData: DataProducerAppData); + + get observer(): DataProducerObserver; + + close(): void; + + /** + * Transport was closed. + * + * @private + */ + transportClosed(): void; + + dump(): Promise; + + getStats(): Promise; + + pause(): Promise; + + resume(): Promise; + + send( + message: string | Buffer, + ppid?: number, + subchannels?: number[], + requiredSubchannel?: number + ): void; +} diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index 044dd2d443..db4616bf48 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -1,57 +1,30 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { UnsupportedError } from './errors'; import { - BaseTransportDump, - BaseTransportStats, + DirectTransportInterface, + DirectTransportDump, + DirectTransportStat, + DirectTransportEvents, + DirectTransportObserver, + DirectTransportObserverEvents, +} from './DirectTransportInterface'; +import { TransportInterface, BaseTransportDump } from './TransportInterface'; +import { + Transport, + TransportConstructorOptions, parseBaseTransportDump, parseBaseTransportStats, parseTransportTraceEventData, - Transport, - TransportEvents, - TransportObserverEvents, - TransportConstructorOptions, } from './Transport'; import { SctpParameters } from './SctpParameters'; import { AppData } from './types'; +import { UnsupportedError } from './errors'; import { Event, Notification } from './fbs/notification'; import * as FbsDirectTransport from './fbs/direct-transport'; import * as FbsTransport from './fbs/transport'; import * as FbsNotification from './fbs/notification'; import * as FbsRequest from './fbs/request'; -export type DirectTransportOptions< - DirectTransportAppData extends AppData = AppData, -> = { - /** - * Maximum allowed size for direct messages sent from DataProducers. - * Default 262144. - */ - maxMessageSize: number; - - /** - * Custom application data. - */ - appData?: DirectTransportAppData; -}; - -export type DirectTransportDump = BaseTransportDump; - -export type DirectTransportStat = BaseTransportStats & { - type: string; -}; - -export type DirectTransportEvents = TransportEvents & { - rtcp: [Buffer]; -}; - -export type DirectTransportObserver = - EnhancedEventEmitter; - -export type DirectTransportObserverEvents = TransportObserverEvents & { - rtcp: [Buffer]; -}; - type DirectTransportConstructorOptions = TransportConstructorOptions & { data: DirectTransportData; @@ -63,13 +36,14 @@ export type DirectTransportData = { const logger = new Logger('DirectTransport'); -export class DirectTransport< - DirectTransportAppData extends AppData = AppData, -> extends Transport< - DirectTransportAppData, - DirectTransportEvents, - DirectTransportObserver -> { +export class DirectTransport + extends Transport< + DirectTransportAppData, + DirectTransportEvents, + DirectTransportObserver + > + implements TransportInterface, DirectTransportInterface +{ // DirectTransport data. // eslint-disable-next-line no-unused-private-class-members readonly #data: DirectTransportData; @@ -131,7 +105,7 @@ export class DirectTransport< } /** - * Dump Transport. + * Dump DirectTransport. */ async dump(): Promise { logger.debug('dump()'); diff --git a/node/src/DirectTransportInterface.ts b/node/src/DirectTransportInterface.ts new file mode 100644 index 0000000000..8bfcb29153 --- /dev/null +++ b/node/src/DirectTransportInterface.ts @@ -0,0 +1,59 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + TransportInterface, + BaseTransportDump, + BaseTransportStats, + TransportEvents, + TransportObserverEvents, +} from './TransportInterface'; +import { AppData } from './types'; + +export type DirectTransportOptions< + DirectTransportAppData extends AppData = AppData, +> = { + /** + * Maximum allowed size for direct messages sent from DataProducers. + * Default 262144. + */ + maxMessageSize: number; + + /** + * Custom application data. + */ + appData?: DirectTransportAppData; +}; + +export type DirectTransportDump = BaseTransportDump; + +export type DirectTransportStat = BaseTransportStats & { + type: string; +}; + +export type DirectTransportEvents = TransportEvents & { + rtcp: [Buffer]; +}; + +export type DirectTransportObserver = + EnhancedEventEmitter; + +export type DirectTransportObserverEvents = TransportObserverEvents & { + rtcp: [Buffer]; +}; + +export interface DirectTransportInterface< + DirectTransportAppData extends AppData = AppData, +> extends TransportInterface< + DirectTransportAppData, + DirectTransportEvents, + DirectTransportObserver + > { + get observer(): DirectTransportObserver; + + dump(): Promise; + + getStats(): Promise; + + connect(): Promise; + + sendRtcp(rtcpPacket: Buffer): void; +} diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index d15dd5025a..2a0526c5b7 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -3,36 +3,43 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; import { - BaseTransportDump, - BaseTransportStats, + PipeTransportInterface, + PipeConsumerOptions, + PipeTransportDump, + PipeTransportStat, + PipeTransportEvents, + PipeTransportObserver, + PipeTransportObserverEvents, +} from './PipeTransportInterface'; +import { + TransportInterface, + TransportTuple, + SctpState, +} from './TransportInterface'; +import { + Transport, + TransportConstructorOptions, parseBaseTransportDump, parseBaseTransportStats, parseSctpState, parseTuple, parseTransportTraceEventData, - Transport, - TransportListenInfo, - TransportListenIp, - TransportTuple, - TransportEvents, - TransportObserverEvents, - TransportConstructorOptions, - SctpState, } from './Transport'; -import { Consumer, ConsumerType } from './Consumer'; -import { Producer } from './Producer'; +import { ProducerInterface } from './ProducerInterface'; +import { ConsumerInterface, ConsumerType } from './ConsumerInterface'; +import { Consumer } from './Consumer'; import { RtpParameters, serializeRtpEncodingParameters, serializeRtpParameters, } from './RtpParameters'; -import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { SctpParameters } from './SctpParameters'; import { parseSrtpParameters, serializeSrtpParameters, SrtpParameters, } from './SrtpParameters'; -import { AppData, Either } from './types'; +import { AppData } from './types'; import { generateUUIDv4 } from './utils'; import { MediaKind as FbsMediaKind } from './fbs/rtp-parameters/media-kind'; import * as FbsRtpParameters from './fbs/rtp-parameters'; @@ -41,104 +48,6 @@ import * as FbsRequest from './fbs/request'; import * as FbsTransport from './fbs/transport'; import * as FbsPipeTransport from './fbs/pipe-transport'; -type PipeTransportListenInfo = { - /** - * Listening info. - */ - listenInfo: TransportListenInfo; -}; - -type PipeTransportListenIp = { - /** - * Listening IP address. - */ - listenIp: TransportListenIp | string; - - /** - * Fixed port to listen on instead of selecting automatically from Worker's port - * range. - */ - port?: number; -}; - -type PipeTransportListen = Either< - PipeTransportListenInfo, - PipeTransportListenIp ->; - -export type PipeTransportOptions< - PipeTransportAppData extends AppData = AppData, -> = { - /** - * Create a SCTP association. Default false. - */ - enableSctp?: boolean; - - /** - * SCTP streams number. - */ - numSctpStreams?: NumSctpStreams; - - /** - * Maximum allowed size for SCTP messages sent by DataProducers. - * Default 268435456. - */ - maxSctpMessageSize?: number; - - /** - * Maximum SCTP send buffer used by DataConsumers. - * Default 268435456. - */ - sctpSendBufferSize?: number; - - /** - * Enable RTX and NACK for RTP retransmission. Useful if both Routers are - * located in different hosts and there is packet lost in the link. For this - * to work, both PipeTransports must enable this setting. Default false. - */ - enableRtx?: boolean; - - /** - * Enable SRTP. Useful to protect the RTP and RTCP traffic if both Routers - * are located in different hosts. For this to work, connect() must be called - * with remote SRTP parameters. Default false. - */ - enableSrtp?: boolean; - - /** - * Custom application data. - */ - appData?: PipeTransportAppData; -} & PipeTransportListen; - -export type PipeTransportStat = BaseTransportStats & { - type: string; - tuple: TransportTuple; -}; - -export type PipeConsumerOptions = { - /** - * The id of the Producer to consume. - */ - producerId: string; - - /** - * Custom application data. - */ - appData?: ConsumerAppData; -}; - -export type PipeTransportEvents = TransportEvents & { - sctpstatechange: [SctpState]; -}; - -export type PipeTransportObserver = - EnhancedEventEmitter; - -export type PipeTransportObserverEvents = TransportObserverEvents & { - sctpstatechange: [SctpState]; -}; - type PipeTransportConstructorOptions = TransportConstructorOptions & { data: PipeTransportData; @@ -152,21 +61,16 @@ export type PipeTransportData = { srtpParameters?: SrtpParameters; }; -export type PipeTransportDump = BaseTransportDump & { - tuple: TransportTuple; - rtx: boolean; - srtpParameters?: SrtpParameters; -}; - const logger = new Logger('PipeTransport'); -export class PipeTransport< - PipeTransportAppData extends AppData = AppData, -> extends Transport< - PipeTransportAppData, - PipeTransportEvents, - PipeTransportObserver -> { +export class PipeTransport + extends Transport< + PipeTransportAppData, + PipeTransportEvents, + PipeTransportObserver + > + implements TransportInterface, PipeTransportInterface +{ // PipeTransport data. readonly #data: PipeTransportData; @@ -289,6 +193,27 @@ export class PipeTransport< return [parseGetStatsResponse(data)]; } + /** + * Dump PipeTransport. + */ + async dump(): Promise { + logger.debug('dump()'); + + const response = await this.channel.request( + FbsRequest.Method.TRANSPORT_DUMP, + undefined, + undefined, + this.internal.transportId + ); + + /* Decode Response. */ + const data = new FbsPipeTransport.DumpResponse(); + + response.body(data); + + return parsePipeTransportDumpResponse(data); + } + /** * Provide the PipeTransport remote parameters. * @@ -339,7 +264,9 @@ export class PipeTransport< async consume({ producerId, appData, - }: PipeConsumerOptions): Promise> { + }: PipeConsumerOptions): Promise< + ConsumerInterface + > { logger.debug('consume()'); if (!producerId || typeof producerId !== 'string') { @@ -390,7 +317,7 @@ export class PipeTransport< type: 'pipe' as ConsumerType, }; - const consumer: Consumer = new Consumer({ + const consumer: ConsumerInterface = new Consumer({ internal: { ...this.internal, consumerId, @@ -505,7 +432,7 @@ function createConsumeRequest({ }: { builder: flatbuffers.Builder; consumerId: string; - producer: Producer; + producer: ProducerInterface; rtpParameters: RtpParameters; }): number { // Build the request. diff --git a/node/src/PipeTransportInterface.ts b/node/src/PipeTransportInterface.ts new file mode 100644 index 0000000000..c690ecae6e --- /dev/null +++ b/node/src/PipeTransportInterface.ts @@ -0,0 +1,173 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + TransportInterface, + TransportListenInfo, + TransportListenIp, + TransportTuple, + SctpState, + BaseTransportDump, + BaseTransportStats, + TransportEvents, + TransportObserverEvents, +} from './TransportInterface'; +import { ConsumerInterface } from './ConsumerInterface'; +import { SrtpParameters } from './SrtpParameters'; +import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { Either, AppData } from './types'; + +export type PipeTransportOptions< + PipeTransportAppData extends AppData = AppData, +> = { + /** + * Create a SCTP association. Default false. + */ + enableSctp?: boolean; + + /** + * SCTP streams number. + */ + numSctpStreams?: NumSctpStreams; + + /** + * Maximum allowed size for SCTP messages sent by DataProducers. + * Default 268435456. + */ + maxSctpMessageSize?: number; + + /** + * Maximum SCTP send buffer used by DataConsumers. + * Default 268435456. + */ + sctpSendBufferSize?: number; + + /** + * Enable RTX and NACK for RTP retransmission. Useful if both Routers are + * located in different hosts and there is packet lost in the link. For this + * to work, both PipeTransports must enable this setting. Default false. + */ + enableRtx?: boolean; + + /** + * Enable SRTP. Useful to protect the RTP and RTCP traffic if both Routers + * are located in different hosts. For this to work, connect() must be called + * with remote SRTP parameters. Default false. + */ + enableSrtp?: boolean; + + /** + * Custom application data. + */ + appData?: PipeTransportAppData; +} & PipeTransportListen; + +type PipeTransportListen = Either< + PipeTransportListenInfo, + PipeTransportListenIp +>; + +type PipeTransportListenInfo = { + /** + * Listening info. + */ + listenInfo: TransportListenInfo; +}; + +type PipeTransportListenIp = { + /** + * Listening IP address. + */ + listenIp: TransportListenIp | string; + + /** + * Fixed port to listen on instead of selecting automatically from Worker's port + * range. + */ + port?: number; +}; + +export type PipeConsumerOptions = { + /** + * The id of the Producer to consume. + */ + producerId: string; + + /** + * Custom application data. + */ + appData?: ConsumerAppData; +}; + +export type PipeTransportDump = BaseTransportDump & { + tuple: TransportTuple; + rtx: boolean; + srtpParameters?: SrtpParameters; +}; + +export type PipeTransportStat = BaseTransportStats & { + type: string; + tuple: TransportTuple; +}; + +export type PipeTransportEvents = TransportEvents & { + sctpstatechange: [SctpState]; +}; + +export type PipeTransportObserver = + EnhancedEventEmitter; + +export type PipeTransportObserverEvents = TransportObserverEvents & { + sctpstatechange: [SctpState]; +}; + +export interface PipeTransportInterface< + PipeTransportAppData extends AppData = AppData, +> extends TransportInterface< + PipeTransportAppData, + PipeTransportEvents, + PipeTransportObserver + > { + get observer(): PipeTransportObserver; + + get tuple(): TransportTuple; + + /** + * SCTP parameters. + */ + get sctpParameters(): SctpParameters | undefined; + + /** + * SCTP state. + */ + get sctpState(): SctpState | undefined; + + /** + * SRTP parameters. + */ + get srtpParameters(): SrtpParameters | undefined; + + dump(): Promise; + + getStats(): Promise; + + connect({ + ip, + port, + srtpParameters, + }: { + ip: string; + port: number; + srtpParameters?: SrtpParameters; + }): Promise; + + /** + * Create a pipe Consumer. + * + * @override + */ + consume({ + producerId, + appData, + }: PipeConsumerOptions): Promise< + ConsumerInterface + >; +} diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index e1eabcac62..8776132f24 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -2,144 +2,39 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { + PlainTransportInterface, + PlainTransportDump, + PlainTransportStat, + PlainTransportEvents, + PlainTransportObserver, + PlainTransportObserverEvents, +} from './PlainTransportInterface'; +import { + TransportInterface, + TransportTuple, + SctpState, +} from './TransportInterface'; +import { + Transport, + TransportConstructorOptions, parseSctpState, - BaseTransportDump, - BaseTransportStats, parseTuple, parseBaseTransportDump, parseBaseTransportStats, parseTransportTraceEventData, - Transport, - TransportListenInfo, - TransportListenIp, - TransportTuple, - TransportEvents, - TransportObserverEvents, - TransportConstructorOptions, - SctpState, } from './Transport'; -import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { SctpParameters } from './SctpParameters'; import { parseSrtpParameters, serializeSrtpParameters, SrtpParameters, - SrtpCryptoSuite, } from './SrtpParameters'; -import { AppData, Either } from './types'; +import { AppData } from './types'; import { Event, Notification } from './fbs/notification'; import * as FbsRequest from './fbs/request'; import * as FbsTransport from './fbs/transport'; import * as FbsPlainTransport from './fbs/plain-transport'; -type PlainTransportListenInfo = { - /** - * Listening info. - */ - listenInfo: TransportListenInfo; - - /** - * Optional listening info for RTCP. - */ - rtcpListenInfo?: TransportListenInfo; -}; - -type PlainTransportListenIp = { - /** - * Listening IP address. - */ - listenIp: TransportListenIp | string; - - /** - * Fixed port to listen on instead of selecting automatically from Worker's port - * range. - */ - port?: number; -}; - -type PlainTransportListen = Either< - PlainTransportListenInfo, - PlainTransportListenIp ->; - -export type PlainTransportOptions< - PlainTransportAppData extends AppData = AppData, -> = { - /** - * Use RTCP-mux (RTP and RTCP in the same port). Default true. - */ - rtcpMux?: boolean; - - /** - * Whether remote IP:port should be auto-detected based on first RTP/RTCP - * packet received. If enabled, connect() method must not be called unless - * SRTP is enabled. If so, it must be called with just remote SRTP parameters. - * Default false. - */ - comedia?: boolean; - - /** - * Create a SCTP association. Default false. - */ - enableSctp?: boolean; - - /** - * SCTP streams number. - */ - numSctpStreams?: NumSctpStreams; - - /** - * Maximum allowed size for SCTP messages sent by DataProducers. - * Default 262144. - */ - maxSctpMessageSize?: number; - - /** - * Maximum SCTP send buffer used by DataConsumers. - * Default 262144. - */ - sctpSendBufferSize?: number; - - /** - * Enable SRTP. For this to work, connect() must be called - * with remote SRTP parameters. Default false. - */ - enableSrtp?: boolean; - - /** - * The SRTP crypto suite to be used if enableSrtp is set. Default - * 'AES_CM_128_HMAC_SHA1_80'. - */ - srtpCryptoSuite?: SrtpCryptoSuite; - - /** - * Custom application data. - */ - appData?: PlainTransportAppData; -} & PlainTransportListen; - -export type PlainTransportStat = BaseTransportStats & { - type: string; - rtcpMux: boolean; - comedia: boolean; - tuple: TransportTuple; - rtcpTuple?: TransportTuple; -}; - -export type PlainTransportEvents = TransportEvents & { - tuple: [TransportTuple]; - rtcptuple: [TransportTuple]; - sctpstatechange: [SctpState]; -}; - -export type PlainTransportObserver = - EnhancedEventEmitter; - -export type PlainTransportObserverEvents = TransportObserverEvents & { - tuple: [TransportTuple]; - rtcptuple: [TransportTuple]; - sctpstatechange: [SctpState]; -}; - type PlainTransportConstructorOptions = TransportConstructorOptions & { data: PlainTransportData; @@ -155,23 +50,16 @@ export type PlainTransportData = { srtpParameters?: SrtpParameters; }; -type PlainTransportDump = BaseTransportDump & { - rtcpMux: boolean; - comedia: boolean; - tuple: TransportTuple; - rtcpTuple?: TransportTuple; - srtpParameters?: SrtpParameters; -}; - const logger = new Logger('PlainTransport'); -export class PlainTransport< - PlainTransportAppData extends AppData = AppData, -> extends Transport< - PlainTransportAppData, - PlainTransportEvents, - PlainTransportObserver -> { +export class PlainTransport + extends Transport< + PlainTransportAppData, + PlainTransportEvents, + PlainTransportObserver + > + implements TransportInterface, PlainTransportInterface +{ // PlainTransport data. readonly #data: PlainTransportData; @@ -283,7 +171,7 @@ export class PlainTransport< } /** - * Dump Transport. + * Dump PlainTransport. */ async dump(): Promise { logger.debug('dump()'); diff --git a/node/src/PlainTransportInterface.ts b/node/src/PlainTransportInterface.ts new file mode 100644 index 0000000000..595930debf --- /dev/null +++ b/node/src/PlainTransportInterface.ts @@ -0,0 +1,180 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + TransportInterface, + TransportListenInfo, + TransportListenIp, + TransportTuple, + SctpState, + BaseTransportDump, + BaseTransportStats, + TransportEvents, + TransportObserverEvents, +} from './TransportInterface'; +import { SrtpParameters, SrtpCryptoSuite } from './SrtpParameters'; +import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { Either, AppData } from './types'; + +export type PlainTransportOptions< + PlainTransportAppData extends AppData = AppData, +> = { + /** + * Use RTCP-mux (RTP and RTCP in the same port). Default true. + */ + rtcpMux?: boolean; + + /** + * Whether remote IP:port should be auto-detected based on first RTP/RTCP + * packet received. If enabled, connect() method must not be called unless + * SRTP is enabled. If so, it must be called with just remote SRTP parameters. + * Default false. + */ + comedia?: boolean; + + /** + * Create a SCTP association. Default false. + */ + enableSctp?: boolean; + + /** + * SCTP streams number. + */ + numSctpStreams?: NumSctpStreams; + + /** + * Maximum allowed size for SCTP messages sent by DataProducers. + * Default 262144. + */ + maxSctpMessageSize?: number; + + /** + * Maximum SCTP send buffer used by DataConsumers. + * Default 262144. + */ + sctpSendBufferSize?: number; + + /** + * Enable SRTP. For this to work, connect() must be called + * with remote SRTP parameters. Default false. + */ + enableSrtp?: boolean; + + /** + * The SRTP crypto suite to be used if enableSrtp is set. Default + * 'AES_CM_128_HMAC_SHA1_80'. + */ + srtpCryptoSuite?: SrtpCryptoSuite; + + /** + * Custom application data. + */ + appData?: PlainTransportAppData; +} & PlainTransportListen; + +type PlainTransportListen = Either< + PlainTransportListenInfo, + PlainTransportListenIp +>; + +type PlainTransportListenInfo = { + /** + * Listening info. + */ + listenInfo: TransportListenInfo; + + /** + * Optional listening info for RTCP. + */ + rtcpListenInfo?: TransportListenInfo; +}; + +type PlainTransportListenIp = { + /** + * Listening IP address. + */ + listenIp: TransportListenIp | string; + + /** + * Fixed port to listen on instead of selecting automatically from Worker's port + * range. + */ + port?: number; +}; + +export type PlainTransportDump = BaseTransportDump & { + rtcpMux: boolean; + comedia: boolean; + tuple: TransportTuple; + rtcpTuple?: TransportTuple; + srtpParameters?: SrtpParameters; +}; + +export type PlainTransportStat = BaseTransportStats & { + type: string; + rtcpMux: boolean; + comedia: boolean; + tuple: TransportTuple; + rtcpTuple?: TransportTuple; +}; + +export type PlainTransportEvents = TransportEvents & { + tuple: [TransportTuple]; + rtcptuple: [TransportTuple]; + sctpstatechange: [SctpState]; +}; + +export type PlainTransportObserver = + EnhancedEventEmitter; + +export type PlainTransportObserverEvents = TransportObserverEvents & { + tuple: [TransportTuple]; + rtcptuple: [TransportTuple]; + sctpstatechange: [SctpState]; +}; + +export interface PlainTransportInterface< + PlainTransportAppData extends AppData = AppData, +> extends TransportInterface< + PlainTransportAppData, + PlainTransportEvents, + PlainTransportObserver + > { + get observer(): PlainTransportObserver; + + get tuple(): TransportTuple; + + /** + * Transport RTCP tuple. + */ + get rtcpTuple(): TransportTuple | undefined; + + /** + * SCTP parameters. + */ + get sctpParameters(): SctpParameters | undefined; + + /** + * SCTP state. + */ + get sctpState(): SctpState | undefined; + + /** + * SRTP parameters. + */ + get srtpParameters(): SrtpParameters | undefined; + + dump(): Promise; + + getStats(): Promise; + + connect({ + ip, + port, + rtcpPort, + srtpParameters, + }: { + ip?: string; + port?: number; + rtcpPort?: number; + srtpParameters?: SrtpParameters; + }): Promise; +} diff --git a/node/src/Producer.ts b/node/src/Producer.ts index 42e2d2b1ee..673cd32c43 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -1,10 +1,23 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; +import { + ProducerInterface, + ProducerType, + ProducerScore, + ProducerVideoOrientation, + ProducerDump, + ProducerStat, + ProducerTraceEventType, + ProducerTraceEventData, + ProducerEvents, + ProducerObserver, + ProducerObserverEvents, +} from './ProducerInterface'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; import { MediaKind, RtpParameters, parseRtpParameters } from './RtpParameters'; import { Event, Notification } from './fbs/notification'; -import { parseRtpStreamRecvStats, RtpStreamRecvStats } from './RtpStream'; +import { parseRtpStreamRecvStats } from './RtpStream'; import { AppData } from './types'; import * as utils from './utils'; import { TraceDirection as FbsTraceDirection } from './fbs/common'; @@ -15,157 +28,12 @@ import * as FbsProducer from './fbs/producer'; import * as FbsProducerTraceInfo from './fbs/producer/trace-info'; import * as FbsRtpParameters from './fbs/rtp-parameters'; -export type ProducerOptions = { - /** - * Producer id (just for Router.pipeToRouter() method). - */ - id?: string; - - /** - * Media kind ('audio' or 'video'). - */ - kind: MediaKind; - - /** - * RTP parameters defining what the endpoint is sending. - */ - rtpParameters: RtpParameters; - - /** - * Whether the producer must start in paused mode. Default false. - */ - paused?: boolean; - - /** - * Just for video. Time (in ms) before asking the sender for a new key frame - * after having asked a previous one. Default 0. - */ - keyFrameRequestDelay?: number; - - /** - * Custom application data. - */ - appData?: ProducerAppData; -}; - -/** - * Valid types for 'trace' event. - */ -export type ProducerTraceEventType = - | 'rtp' - | 'keyframe' - | 'nack' - | 'pli' - | 'fir' - | 'sr'; - -/** - * 'trace' event data. - */ -export type ProducerTraceEventData = { - /** - * Trace type. - */ - type: ProducerTraceEventType; - - /** - * Event timestamp. - */ - timestamp: number; - - /** - * Event direction. - */ - direction: 'in' | 'out'; - - /** - * Per type information. - */ - info: any; -}; - -export type ProducerScore = { - /** - * Index of the RTP stream in the rtpParameters.encodings array. - */ - encodingIdx: number; - - /** - * SSRC of the RTP stream. - */ - ssrc: number; - - /** - * RID of the RTP stream. - */ - rid?: string; - - /** - * The score of the RTP stream. - */ - score: number; -}; - -export type ProducerVideoOrientation = { - /** - * Whether the source is a video camera. - */ - camera: boolean; - - /** - * Whether the video source is flipped. - */ - flip: boolean; - - /** - * Rotation degrees (0, 90, 180 or 270). - */ - rotation: number; -}; - -export type ProducerStat = RtpStreamRecvStats; - -/** - * Producer type. - */ -export type ProducerType = 'simple' | 'simulcast' | 'svc'; - -export type ProducerEvents = { - transportclose: []; - score: [ProducerScore[]]; - videoorientationchange: [ProducerVideoOrientation]; - trace: [ProducerTraceEventData]; - listenererror: [string, Error]; - // Private events. - '@close': []; -}; - -export type ProducerObserver = EnhancedEventEmitter; - -export type ProducerObserverEvents = { - close: []; - pause: []; - resume: []; - score: [ProducerScore[]]; - videoorientationchange: [ProducerVideoOrientation]; - trace: [ProducerTraceEventData]; -}; - -type ProducerDump = { - id: string; - kind: string; - type: ProducerType; - rtpParameters: RtpParameters; - rtpMapping: any; - rtpStreams: any; - traceEventTypes: string[]; - paused: boolean; -}; - type ProducerInternal = TransportInternal & { producerId: string; }; +const logger = new Logger('Producer'); + type ProducerData = { kind: MediaKind; rtpParameters: RtpParameters; @@ -173,11 +41,10 @@ type ProducerData = { consumableRtpParameters: RtpParameters; }; -const logger = new Logger('Producer'); - -export class Producer< - ProducerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export class Producer + extends EnhancedEventEmitter + implements ProducerInterface +{ // Internal data. readonly #internal: ProducerInternal; @@ -312,8 +179,9 @@ export class Producer< } /** - * @private * Just for testing purposes. + * + * @private */ get channelForTesting(): Channel { return this.#channel; diff --git a/node/src/ProducerInterface.ts b/node/src/ProducerInterface.ts new file mode 100644 index 0000000000..d4786cd340 --- /dev/null +++ b/node/src/ProducerInterface.ts @@ -0,0 +1,202 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { MediaKind, RtpParameters } from './RtpParameters'; +import { RtpStreamRecvStats } from './RtpStream'; +import { AppData } from './types'; + +export type ProducerOptions = { + /** + * Producer id (just for Router.pipeToRouter() method). + */ + id?: string; + + /** + * Media kind ('audio' or 'video'). + */ + kind: MediaKind; + + /** + * RTP parameters defining what the endpoint is sending. + */ + rtpParameters: RtpParameters; + + /** + * Whether the producer must start in paused mode. Default false. + */ + paused?: boolean; + + /** + * Just for video. Time (in ms) before asking the sender for a new key frame + * after having asked a previous one. Default 0. + */ + keyFrameRequestDelay?: number; + + /** + * Custom application data. + */ + appData?: ProducerAppData; +}; + +/** + * Producer type. + */ +export type ProducerType = 'simple' | 'simulcast' | 'svc'; + +export type ProducerScore = { + /** + * Index of the RTP stream in the rtpParameters.encodings array. + */ + encodingIdx: number; + + /** + * SSRC of the RTP stream. + */ + ssrc: number; + + /** + * RID of the RTP stream. + */ + rid?: string; + + /** + * The score of the RTP stream. + */ + score: number; +}; + +export type ProducerVideoOrientation = { + /** + * Whether the source is a video camera. + */ + camera: boolean; + + /** + * Whether the video source is flipped. + */ + flip: boolean; + + /** + * Rotation degrees (0, 90, 180 or 270). + */ + rotation: number; +}; + +export type ProducerDump = { + id: string; + kind: string; + type: ProducerType; + rtpParameters: RtpParameters; + rtpMapping: any; + rtpStreams: any; + traceEventTypes: string[]; + paused: boolean; +}; + +export type ProducerStat = RtpStreamRecvStats; + +/** + * Valid types for 'trace' event. + */ +export type ProducerTraceEventType = + | 'rtp' + | 'keyframe' + | 'nack' + | 'pli' + | 'fir' + | 'sr'; + +/** + * 'trace' event data. + */ +export type ProducerTraceEventData = { + /** + * Trace type. + */ + type: ProducerTraceEventType; + + /** + * Event timestamp. + */ + timestamp: number; + + /** + * Event direction. + */ + direction: 'in' | 'out'; + + /** + * Per type information. + */ + info: any; +}; + +export type ProducerEvents = { + transportclose: []; + score: [ProducerScore[]]; + videoorientationchange: [ProducerVideoOrientation]; + trace: [ProducerTraceEventData]; + listenererror: [string, Error]; + // Private events. + '@close': []; +}; + +export type ProducerObserver = EnhancedEventEmitter; + +export type ProducerObserverEvents = { + close: []; + pause: []; + resume: []; + score: [ProducerScore[]]; + videoorientationchange: [ProducerVideoOrientation]; + trace: [ProducerTraceEventData]; +}; + +export interface ProducerInterface + extends EnhancedEventEmitter { + get id(): string; + + get closed(): boolean; + + get kind(): MediaKind; + + get rtpParameters(): RtpParameters; + + get type(): ProducerType; + + /** + * Consumable RTP parameters. + * + * @private + */ + get consumableRtpParameters(): RtpParameters; + + get paused(): boolean; + + get score(): ProducerScore[]; + + get appData(): ProducerAppData; + + set appData(appData: ProducerAppData); + + get observer(): ProducerObserver; + + close(): void; + + /** + * Transport was closed. + * + * @private + */ + transportClosed(): void; + + dump(): Promise; + + getStats(): Promise; + + pause(): Promise; + + resume(): Promise; + + enableTraceEvent(types?: ProducerTraceEventType[]): Promise; + + send(rtpPacket: Buffer): void; +} diff --git a/node/src/Router.ts b/node/src/Router.ts index 755d579f72..ce3bab5239 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -4,50 +4,68 @@ import * as ortc from './ortc'; import { InvalidStateError } from './errors'; import { Channel } from './Channel'; import { - Transport, - TransportListenInfo, + RouterInterface, + PipeToRouterOptions, + PipeToRouterResult, + PipeTransportPair, + RouterDump, + RouterEvents, + RouterObserver, + RouterObserverEvents, +} from './RouterInterface'; +import { + TransportInterface, TransportListenIp, TransportProtocol, - portRangeToFbs, - socketFlagsToFbs, -} from './Transport'; +} from './TransportInterface'; +import { portRangeToFbs, socketFlagsToFbs } from './Transport'; import { - WebRtcTransport, + WebRtcTransportInterface, WebRtcTransportOptions, +} from './WebRtcTransportInterface'; +import { + WebRtcTransport, parseWebRtcTransportDumpResponse, } from './WebRtcTransport'; import { - PlainTransport, + PlainTransportInterface, PlainTransportOptions, +} from './PlainTransportInterface'; +import { + PlainTransport, parsePlainTransportDumpResponse, } from './PlainTransport'; import { - PipeTransport, + PipeTransportInterface, PipeTransportOptions, - parsePipeTransportDumpResponse, -} from './PipeTransport'; +} from './PipeTransportInterface'; +import { PipeTransport, parsePipeTransportDumpResponse } from './PipeTransport'; import { - DirectTransport, + DirectTransportInterface, DirectTransportOptions, +} from './DirectTransportInterface'; +import { + DirectTransport, parseDirectTransportDumpResponse, } from './DirectTransport'; -import { Producer } from './Producer'; -import { Consumer } from './Consumer'; -import { DataProducer } from './DataProducer'; -import { DataConsumer } from './DataConsumer'; -import { RtpObserver } from './RtpObserver'; +import { ProducerInterface } from './ProducerInterface'; +import { ConsumerInterface } from './ConsumerInterface'; +import { DataProducerInterface } from './DataProducerInterface'; +import { DataConsumerInterface } from './DataConsumerInterface'; +import { RtpObserverInterface } from './RtpObserverInterface'; import { - ActiveSpeakerObserver, + ActiveSpeakerObserverInterface, ActiveSpeakerObserverOptions, -} from './ActiveSpeakerObserver'; +} from './ActiveSpeakerObserverInterface'; +import { ActiveSpeakerObserver } from './ActiveSpeakerObserver'; import { - AudioLevelObserver, + AudioLevelObserverInterface, AudioLevelObserverOptions, -} from './AudioLevelObserver'; -import { RtpCapabilities, RtpCodecCapability } from './RtpParameters'; +} from './AudioLevelObserverInterface'; +import { AudioLevelObserver } from './AudioLevelObserver'; +import { RtpCapabilities } from './RtpParameters'; import { cryptoSuiteToFbs } from './SrtpParameters'; -import { NumSctpStreams } from './SctpParameters'; -import { AppData, Either } from './types'; +import { AppData } from './types'; import { clone, generateUUIDv4, @@ -68,144 +86,6 @@ import * as FbsPipeTransport from './fbs/pipe-transport'; import * as FbsDirectTransport from './fbs/direct-transport'; import * as FbsSctpParameters from './fbs/sctp-parameters'; -export type RouterOptions = { - /** - * Router media codecs. - */ - mediaCodecs?: RtpCodecCapability[]; - - /** - * Custom application data. - */ - appData?: RouterAppData; -}; - -type PipeToRouterListenInfo = { - listenInfo: TransportListenInfo; -}; - -type PipeToRouterListenIp = { - /** - * IP used in the PipeTransport pair. Default '127.0.0.1'. - */ - listenIp?: TransportListenIp | string; -}; - -type PipeToRouterListen = Either; - -export type PipeToRouterOptions = { - /** - * The id of the Producer to consume. - */ - producerId?: string; - - /** - * The id of the DataProducer to consume. - */ - dataProducerId?: string; - - /** - * Target Router instance. - */ - router: Router; - - /** - * Create a SCTP association. Default true. - */ - enableSctp?: boolean; - - /** - * SCTP streams number. - */ - numSctpStreams?: NumSctpStreams; - - /** - * Enable RTX and NACK for RTP retransmission. - */ - enableRtx?: boolean; - - /** - * Enable SRTP. - */ - enableSrtp?: boolean; -} & PipeToRouterListen; - -export type PipeToRouterResult = { - /** - * The Consumer created in the current Router. - */ - pipeConsumer?: Consumer; - - /** - * The Producer created in the target Router. - */ - pipeProducer?: Producer; - - /** - * The DataConsumer created in the current Router. - */ - pipeDataConsumer?: DataConsumer; - - /** - * The DataProducer created in the target Router. - */ - pipeDataProducer?: DataProducer; -}; - -export type RouterDump = { - /** - * The Router id. - */ - id: string; - /** - * Id of Transports. - */ - transportIds: string[]; - /** - * Id of RtpObservers. - */ - rtpObserverIds: string[]; - /** - * Array of Producer id and its respective Consumer ids. - */ - mapProducerIdConsumerIds: { key: string; values: string[] }[]; - /** - * Array of Consumer id and its Producer id. - */ - mapConsumerIdProducerId: { key: string; value: string }[]; - /** - * Array of Producer id and its respective Observer ids. - */ - mapProducerIdObserverIds: { key: string; values: string[] }[]; - /** - * Array of Producer id and its respective DataConsumer ids. - */ - mapDataProducerIdDataConsumerIds: { key: string; values: string[] }[]; - /** - * Array of DataConsumer id and its DataProducer id. - */ - mapDataConsumerIdDataProducerId: { key: string; value: string }[]; -}; - -type PipeTransportPair = { - [key: string]: PipeTransport; -}; - -export type RouterEvents = { - workerclose: []; - listenererror: [string, Error]; - // Private events. - '@close': []; -}; - -export type RouterObserver = EnhancedEventEmitter; - -export type RouterObserverEvents = { - close: []; - newtransport: [Transport]; - newrtpobserver: [RtpObserver]; -}; - export type RouterInternal = { routerId: string; }; @@ -216,9 +96,10 @@ type RouterData = { const logger = new Logger('Router'); -export class Router< - RouterAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export class Router + extends EnhancedEventEmitter + implements RouterInterface +{ // Internal data. readonly #internal: RouterInternal; @@ -235,16 +116,16 @@ export class Router< #appData: RouterAppData; // Transports map. - readonly #transports: Map = new Map(); + readonly #transports: Map = new Map(); // Producers map. - readonly #producers: Map = new Map(); + readonly #producers: Map = new Map(); // RtpObservers map. - readonly #rtpObservers: Map = new Map(); + readonly #rtpObservers: Map = new Map(); // DataProducers map. - readonly #dataProducers: Map = new Map(); + readonly #dataProducers: Map = new Map(); // Map of PipeTransport pair Promises indexed by the id of the Router in // which pipeToRouter() was called. @@ -327,7 +208,7 @@ export class Router< * @private * Just for testing purposes. */ - get transportsForTesting(): Map { + get transportsForTesting(): Map { return this.#transports; } @@ -461,7 +342,7 @@ export class Router< iceConsentTimeout = 30, appData, }: WebRtcTransportOptions): Promise< - WebRtcTransport + WebRtcTransportInterface > { logger.debug('createWebRtcTransport()'); @@ -627,7 +508,7 @@ export class Router< const webRtcTransportData = parseWebRtcTransportDumpResponse(data); - const transport: WebRtcTransport = + const transport: WebRtcTransportInterface = new WebRtcTransport({ internal: { ...this.#internal, @@ -638,11 +519,12 @@ export class Router< appData, getRouterRtpCapabilities: (): RtpCapabilities => this.#data.rtpCapabilities, - getProducerById: (producerId: string): Producer | undefined => + getProducerById: (producerId: string): ProducerInterface | undefined => this.#producers.get(producerId), getDataProducerById: ( dataProducerId: string - ): DataProducer | undefined => this.#dataProducers.get(dataProducerId), + ): DataProducerInterface | undefined => + this.#dataProducers.get(dataProducerId), }); this.#transports.set(transport.id, transport); @@ -650,16 +532,16 @@ export class Router< transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: Producer) => + transport.on('@newproducer', (producer: ProducerInterface) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: Producer) => + transport.on('@producerclose', (producer: ProducerInterface) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducer) => + transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducer) => + transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => this.#dataProducers.delete(dataProducer.id) ); @@ -691,7 +573,7 @@ export class Router< srtpCryptoSuite = 'AES_CM_128_HMAC_SHA1_80', appData, }: PlainTransportOptions): Promise< - PlainTransport + PlainTransportInterface > { logger.debug('createPlainTransport()'); @@ -799,8 +681,8 @@ export class Router< const plainTransportData = parsePlainTransportDumpResponse(data); - const transport: PlainTransport = new PlainTransport( - { + const transport: PlainTransportInterface = + new PlainTransport({ internal: { ...this.#internal, transportId: transportId, @@ -810,29 +692,29 @@ export class Router< appData, getRouterRtpCapabilities: (): RtpCapabilities => this.#data.rtpCapabilities, - getProducerById: (producerId: string): Producer | undefined => + getProducerById: (producerId: string): ProducerInterface | undefined => this.#producers.get(producerId), getDataProducerById: ( dataProducerId: string - ): DataProducer | undefined => this.#dataProducers.get(dataProducerId), - } - ); + ): DataProducerInterface | undefined => + this.#dataProducers.get(dataProducerId), + }); this.#transports.set(transport.id, transport); transport.on('@close', () => this.#transports.delete(transport.id)); transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: Producer) => + transport.on('@newproducer', (producer: ProducerInterface) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: Producer) => + transport.on('@producerclose', (producer: ProducerInterface) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducer) => + transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducer) => + transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => this.#dataProducers.delete(dataProducer.id) ); @@ -857,7 +739,7 @@ export class Router< enableSrtp = false, appData, }: PipeTransportOptions): Promise< - PipeTransport + PipeTransportInterface > { logger.debug('createPipeTransport()'); @@ -940,37 +822,40 @@ export class Router< const plainTransportData = parsePipeTransportDumpResponse(data); - const transport: PipeTransport = new PipeTransport({ - internal: { - ...this.#internal, - transportId, - }, - data: plainTransportData, - channel: this.#channel, - appData, - getRouterRtpCapabilities: (): RtpCapabilities => - this.#data.rtpCapabilities, - getProducerById: (producerId: string): Producer | undefined => - this.#producers.get(producerId), - getDataProducerById: (dataProducerId: string): DataProducer | undefined => - this.#dataProducers.get(dataProducerId), - }); + const transport: PipeTransportInterface = + new PipeTransport({ + internal: { + ...this.#internal, + transportId, + }, + data: plainTransportData, + channel: this.#channel, + appData, + getRouterRtpCapabilities: (): RtpCapabilities => + this.#data.rtpCapabilities, + getProducerById: (producerId: string): ProducerInterface | undefined => + this.#producers.get(producerId), + getDataProducerById: ( + dataProducerId: string + ): DataProducerInterface | undefined => + this.#dataProducers.get(dataProducerId), + }); this.#transports.set(transport.id, transport); transport.on('@close', () => this.#transports.delete(transport.id)); transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: Producer) => + transport.on('@newproducer', (producer: ProducerInterface) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: Producer) => + transport.on('@producerclose', (producer: ProducerInterface) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducer) => + transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducer) => + transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => this.#dataProducers.delete(dataProducer.id) ); @@ -990,7 +875,7 @@ export class Router< }: DirectTransportOptions = { maxMessageSize: 262144, } - ): Promise> { + ): Promise> { logger.debug('createDirectTransport()'); if (typeof maxMessageSize !== 'number' || maxMessageSize < 0) { @@ -1035,7 +920,7 @@ export class Router< const directTransportData = parseDirectTransportDumpResponse(data); - const transport: DirectTransport = + const transport: DirectTransportInterface = new DirectTransport({ internal: { ...this.#internal, @@ -1046,11 +931,12 @@ export class Router< appData, getRouterRtpCapabilities: (): RtpCapabilities => this.#data.rtpCapabilities, - getProducerById: (producerId: string): Producer | undefined => + getProducerById: (producerId: string): ProducerInterface | undefined => this.#producers.get(producerId), getDataProducerById: ( dataProducerId: string - ): DataProducer | undefined => this.#dataProducers.get(dataProducerId), + ): DataProducerInterface | undefined => + this.#dataProducers.get(dataProducerId), }); this.#transports.set(transport.id, transport); @@ -1058,16 +944,16 @@ export class Router< transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: Producer) => + transport.on('@newproducer', (producer: ProducerInterface) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: Producer) => + transport.on('@producerclose', (producer: ProducerInterface) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducer) => + transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducer) => + transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => this.#dataProducers.delete(dataProducer.id) ); @@ -1126,8 +1012,8 @@ export class Router< }; } - let producer: Producer | undefined; - let dataProducer: DataProducer | undefined; + let producer: ProducerInterface | undefined; + let dataProducer: DataProducerInterface | undefined; if (producerId) { producer = this.#producers.get(producerId); @@ -1147,8 +1033,8 @@ export class Router< let pipeTransportPairPromise = this.#mapRouterPairPipeTransportPairPromise.get(pipeTransportPairKey); let pipeTransportPair: PipeTransportPair; - let localPipeTransport: PipeTransport; - let remotePipeTransport: PipeTransport; + let localPipeTransport: PipeTransportInterface; + let remotePipeTransport: PipeTransportInterface; if (pipeTransportPairPromise) { pipeTransportPair = await pipeTransportPairPromise; @@ -1239,8 +1125,8 @@ export class Router< } if (producer) { - let pipeConsumer: Consumer | undefined; - let pipeProducer: Producer | undefined; + let pipeConsumer: ConsumerInterface | undefined; + let pipeProducer: ProducerInterface | undefined; try { pipeConsumer = await localPipeTransport!.consume({ @@ -1296,8 +1182,8 @@ export class Router< throw error; } } else if (dataProducer) { - let pipeDataConsumer: DataConsumer | undefined; - let pipeDataProducer: DataProducer | undefined; + let pipeDataConsumer: DataConsumerInterface | undefined; + let pipeDataProducer: DataProducerInterface | undefined; try { pipeDataConsumer = await localPipeTransport!.consumeData({ @@ -1386,7 +1272,7 @@ export class Router< interval = 300, appData, }: ActiveSpeakerObserverOptions = {}): Promise< - ActiveSpeakerObserver + ActiveSpeakerObserverInterface > { logger.debug('createActiveSpeakerObserver()'); @@ -1414,7 +1300,7 @@ export class Router< this.#internal.routerId ); - const activeSpeakerObserver: ActiveSpeakerObserver = + const activeSpeakerObserver: ActiveSpeakerObserverInterface = new ActiveSpeakerObserver({ internal: { ...this.#internal, @@ -1422,7 +1308,7 @@ export class Router< }, channel: this.#channel, appData, - getProducerById: (producerId: string): Producer | undefined => + getProducerById: (producerId: string): ProducerInterface | undefined => this.#producers.get(producerId), }); @@ -1448,7 +1334,7 @@ export class Router< interval = 1000, appData, }: AudioLevelObserverOptions = {}): Promise< - AudioLevelObserver + AudioLevelObserverInterface > { logger.debug('createAudioLevelObserver()'); @@ -1490,7 +1376,7 @@ export class Router< this.#internal.routerId ); - const audioLevelObserver: AudioLevelObserver = + const audioLevelObserver: AudioLevelObserverInterface = new AudioLevelObserver({ internal: { ...this.#internal, @@ -1498,7 +1384,7 @@ export class Router< }, channel: this.#channel, appData, - getProducerById: (producerId: string): Producer | undefined => + getProducerById: (producerId: string): ProducerInterface | undefined => this.#producers.get(producerId), }); diff --git a/node/src/RouterInterface.ts b/node/src/RouterInterface.ts new file mode 100644 index 0000000000..a3e2a10498 --- /dev/null +++ b/node/src/RouterInterface.ts @@ -0,0 +1,258 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + TransportInterface, + TransportListenInfo, + TransportListenIp, +} from './TransportInterface'; +import { + WebRtcTransportInterface, + WebRtcTransportOptions, +} from './WebRtcTransportInterface'; +import { + PlainTransportInterface, + PlainTransportOptions, +} from './PlainTransportInterface'; +import { + PipeTransportInterface, + PipeTransportOptions, +} from './PipeTransportInterface'; +import { + DirectTransportInterface, + DirectTransportOptions, +} from './DirectTransportInterface'; +import { ProducerInterface } from './ProducerInterface'; +import { ConsumerInterface } from './ConsumerInterface'; +import { DataProducerInterface } from './DataProducerInterface'; +import { DataConsumerInterface } from './DataConsumerInterface'; +import { RtpObserverInterface } from './RtpObserverInterface'; +import { + ActiveSpeakerObserverInterface, + ActiveSpeakerObserverOptions, +} from './ActiveSpeakerObserverInterface'; +import { + AudioLevelObserverInterface, + AudioLevelObserverOptions, +} from './AudioLevelObserverInterface'; +import { RtpCapabilities, RtpCodecCapability } from './RtpParameters'; +import { NumSctpStreams } from './SctpParameters'; +import { Either, AppData } from './types'; + +export type RouterOptions = { + /** + * Router media codecs. + */ + mediaCodecs?: RtpCodecCapability[]; + + /** + * Custom application data. + */ + appData?: RouterAppData; +}; + +export type PipeToRouterOptions = { + /** + * The id of the Producer to consume. + */ + producerId?: string; + + /** + * The id of the DataProducer to consume. + */ + dataProducerId?: string; + + /** + * Target Router instance. + */ + router: RouterInterface; + + /** + * Create a SCTP association. Default true. + */ + enableSctp?: boolean; + + /** + * SCTP streams number. + */ + numSctpStreams?: NumSctpStreams; + + /** + * Enable RTX and NACK for RTP retransmission. + */ + enableRtx?: boolean; + + /** + * Enable SRTP. + */ + enableSrtp?: boolean; +} & PipeToRouterListen; + +type PipeToRouterListen = Either; + +type PipeToRouterListenInfo = { + listenInfo: TransportListenInfo; +}; + +type PipeToRouterListenIp = { + /** + * IP used in the PipeTransport pair. Default '127.0.0.1'. + */ + listenIp?: TransportListenIp | string; +}; + +export type PipeToRouterResult = { + /** + * The Consumer created in the current Router. + */ + pipeConsumer?: ConsumerInterface; + + /** + * The Producer created in the target Router. + */ + pipeProducer?: ProducerInterface; + + /** + * The DataConsumer created in the current Router. + */ + pipeDataConsumer?: DataConsumerInterface; + + /** + * The DataProducer created in the target Router. + */ + pipeDataProducer?: DataProducerInterface; +}; + +export type PipeTransportPair = { + [key: string]: PipeTransportInterface; +}; + +export type RouterDump = { + /** + * The Router id. + */ + id: string; + /** + * Id of Transports. + */ + transportIds: string[]; + /** + * Id of RtpObservers. + */ + rtpObserverIds: string[]; + /** + * Array of Producer id and its respective Consumer ids. + */ + mapProducerIdConsumerIds: { key: string; values: string[] }[]; + /** + * Array of Consumer id and its Producer id. + */ + mapConsumerIdProducerId: { key: string; value: string }[]; + /** + * Array of Producer id and its respective Observer ids. + */ + mapProducerIdObserverIds: { key: string; values: string[] }[]; + /** + * Array of Producer id and its respective DataConsumer ids. + */ + mapDataProducerIdDataConsumerIds: { key: string; values: string[] }[]; + /** + * Array of DataConsumer id and its DataProducer id. + */ + mapDataConsumerIdDataProducerId: { key: string; value: string }[]; +}; + +export type RouterEvents = { + workerclose: []; + listenererror: [string, Error]; + // Private events. + '@close': []; +}; + +export type RouterObserver = EnhancedEventEmitter; + +export type RouterObserverEvents = { + close: []; + newtransport: [TransportInterface]; + newrtpobserver: [RtpObserverInterface]; +}; + +export interface RouterInterface + extends EnhancedEventEmitter { + get id(): string; + + get closed(): boolean; + + /** + * RTP capabilities of the Router. + */ + get rtpCapabilities(): RtpCapabilities; + + /** + * App custom data. + */ + get appData(): RouterAppData; + + /** + * App custom data setter. + */ + set appData(appData: RouterAppData); + + /** + * Observer. + */ + get observer(): RouterObserver; + + close(): void; + + /** + * Worker was closed. + * + * @private + */ + workerClosed(): void; + + dump(): Promise; + + createWebRtcTransport( + options: WebRtcTransportOptions + ): Promise>; + + createPlainTransport( + options: PlainTransportOptions + ): Promise>; + + createPipeTransport( + options: PipeTransportOptions + ): Promise>; + + createDirectTransport( + options?: DirectTransportOptions + ): Promise>; + + pipeToRouter(options: PipeToRouterOptions): Promise; + + /** + * @private + */ + addPipeTransportPair( + pipeTransportPairKey: string, + pipeTransportPairPromise: Promise + ): void; + + createActiveSpeakerObserver< + ActiveSpeakerObserverAppData extends AppData = AppData, + >( + options?: ActiveSpeakerObserverOptions + ): Promise>; + + createAudioLevelObserver( + options?: AudioLevelObserverOptions + ): Promise>; + + canConsume({ + producerId, + rtpCapabilities, + }: { + producerId: string; + rtpCapabilities: RtpCapabilities; + }): boolean; +} diff --git a/node/src/RtpObserver.ts b/node/src/RtpObserver.ts index a64abc3747..ba07f2af3d 100644 --- a/node/src/RtpObserver.ts +++ b/node/src/RtpObserver.ts @@ -1,51 +1,27 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; +import { RtpObserverEvents, RtpObserverObserver } from './RtpObserverInterface'; import { Channel } from './Channel'; import { RouterInternal } from './Router'; -import { Producer } from './Producer'; +import { ProducerInterface } from './ProducerInterface'; import { AppData } from './types'; import * as FbsRequest from './fbs/request'; import * as FbsRouter from './fbs/router'; import * as FbsRtpObserver from './fbs/rtp-observer'; -export type RtpObserverEvents = { - routerclose: []; - listenererror: [string, Error]; - // Private events. - '@close': []; -}; - -export type RtpObserverObserver = - EnhancedEventEmitter; - -export type RtpObserverObserverEvents = { - close: []; - pause: []; - resume: []; - addproducer: [Producer]; - removeproducer: [Producer]; -}; - export type RtpObserverConstructorOptions = { internal: RtpObserverObserverInternal; channel: Channel; appData?: RtpObserverAppData; - getProducerById: (producerId: string) => Producer | undefined; + getProducerById: (producerId: string) => ProducerInterface | undefined; }; -export type RtpObserverObserverInternal = RouterInternal & { +type RtpObserverObserverInternal = RouterInternal & { rtpObserverId: string; }; const logger = new Logger('RtpObserver'); -export type RtpObserverAddRemoveProducerOptions = { - /** - * The id of the Producer to be added or removed. - */ - producerId: string; -}; - export abstract class RtpObserver< RtpObserverAppData extends AppData = AppData, Events extends RtpObserverEvents = RtpObserverEvents, @@ -69,7 +45,7 @@ export abstract class RtpObserver< // Method to retrieve a Producer. protected readonly getProducerById: ( producerId: string - ) => Producer | undefined; + ) => ProducerInterface | undefined; // Observer instance. readonly #observer: Observer; @@ -247,9 +223,7 @@ export abstract class RtpObserver< /** * Add a Producer to the RtpObserver. */ - async addProducer({ - producerId, - }: RtpObserverAddRemoveProducerOptions): Promise { + async addProducer({ producerId }: { producerId: string }): Promise { logger.debug('addProducer()'); const producer = this.getProducerById(producerId); @@ -276,9 +250,7 @@ export abstract class RtpObserver< /** * Remove a Producer from the RtpObserver. */ - async removeProducer({ - producerId, - }: RtpObserverAddRemoveProducerOptions): Promise { + async removeProducer({ producerId }: { producerId: string }): Promise { logger.debug('removeProducer()'); const producer = this.getProducerById(producerId); diff --git a/node/src/RtpObserverInterface.ts b/node/src/RtpObserverInterface.ts new file mode 100644 index 0000000000..8f047bcf1c --- /dev/null +++ b/node/src/RtpObserverInterface.ts @@ -0,0 +1,56 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { ProducerInterface } from './ProducerInterface'; +import { AppData } from './types'; + +export type RtpObserverEvents = { + routerclose: []; + listenererror: [string, Error]; + // Private events. + '@close': []; +}; + +export type RtpObserverObserver = + EnhancedEventEmitter; + +export type RtpObserverObserverEvents = { + close: []; + pause: []; + resume: []; + addproducer: [ProducerInterface]; + removeproducer: [ProducerInterface]; +}; + +export interface RtpObserverInterface< + RtpObserverAppData extends AppData = AppData, + Events extends RtpObserverEvents = RtpObserverEvents, + Observer extends RtpObserverObserver = RtpObserverObserver, +> extends EnhancedEventEmitter { + get id(): string; + + get closed(): boolean; + + get paused(): boolean; + + get appData(): RtpObserverAppData; + + set appData(appData: RtpObserverAppData); + + get observer(): Observer; + + close(): void; + + /** + * Router was closed. + * + * @private + */ + routerClosed(): void; + + pause(): Promise; + + resume(): Promise; + + addProducer({ producerId }: { producerId: string }): Promise; + + removeProducer({ producerId }: { producerId: string }): Promise; +} diff --git a/node/src/Transport.ts b/node/src/Transport.ts index 7448e8a438..2794ad6665 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -2,35 +2,55 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; +import { + TransportInterface, + TransportProtocol, + TransportPortRange, + TransportSocketFlags, + TransportTuple, + SctpState, + RtpListenerDump, + SctpListenerDump, + RecvRtpHeaderExtensions, + BaseTransportDump, + BaseTransportStats, + TransportTraceEventType, + TransportTraceEventData, + TransportEvents, + TransportObserver, +} from './TransportInterface'; import { Channel } from './Channel'; import { RouterInternal } from './Router'; import { WebRtcTransportData } from './WebRtcTransport'; import { PlainTransportData } from './PlainTransport'; import { PipeTransportData } from './PipeTransport'; import { DirectTransportData } from './DirectTransport'; +import { ProducerInterface, ProducerOptions } from './ProducerInterface'; +import { Producer, producerTypeFromFbs, producerTypeToFbs } from './Producer'; import { - Producer, - ProducerOptions, - producerTypeFromFbs, - producerTypeToFbs, -} from './Producer'; -import { - Consumer, + ConsumerInterface, ConsumerOptions, ConsumerType, ConsumerLayers, -} from './Consumer'; +} from './ConsumerInterface'; +import { Consumer } from './Consumer'; import { - DataProducer, + DataProducerInterface, DataProducerOptions, DataProducerType, +} from './DataProducerInterface'; +import { + DataProducer, dataProducerTypeToFbs, parseDataProducerDumpResponse, } from './DataProducer'; import { - DataConsumer, + DataConsumerInterface, DataConsumerOptions, DataConsumerType, +} from './DataConsumerInterface'; +import { + DataConsumer, dataConsumerTypeToFbs, parseDataConsumerDumpResponse, } from './DataConsumer'; @@ -60,270 +80,38 @@ import * as FbsRouter from './fbs/router'; import * as FbsRtpParameters from './fbs/rtp-parameters'; import { SctpState as FbsSctpState } from './fbs/sctp-association/sctp-state'; -export type TransportListenInfo = { - /** - * Network protocol. - */ - protocol: TransportProtocol; - - /** - * Listening IPv4 or IPv6. - */ - ip: string; - - /** - * @deprecated Use |announcedAddress| instead. - * - * Announced IPv4, IPv6 or hostname (useful when running mediasoup behind NAT - * with private IP). - */ - announcedIp?: string; - - /** - * Announced IPv4, IPv6 or hostname (useful when running mediasoup behind NAT - * with private IP). - */ - announcedAddress?: string; - - /** - * Listening port. - */ - port?: number; - - /** - * Listening port range. If given then |port| will be ignored. - */ - portRange?: TransportPortRange; - - /** - * Socket flags. - */ - flags?: TransportSocketFlags; - - /** - * Send buffer size (bytes). - */ - sendBufferSize?: number; - - /** - * Recv buffer size (bytes). - */ - recvBufferSize?: number; -}; - -/** - * Use TransportListenInfo instead. - * @deprecated - */ -export type TransportListenIp = { - /** - * Listening IPv4 or IPv6. - */ - ip: string; - - /** - * Announced IPv4, IPv6 or hostname (useful when running mediasoup behind NAT - * with private IP). - */ - announcedIp?: string; -}; - -/** - * Transport protocol. - */ -export type TransportProtocol = 'udp' | 'tcp'; - -/** - * Port range.. - */ -export type TransportPortRange = { - /** - * Lowest port in the range. - */ - min: number; - /** - * Highest port in the range. - */ - max: number; -}; - -/** - * UDP/TCP socket flags. - */ -export type TransportSocketFlags = { - /** - * Disable dual-stack support so only IPv6 is used (only if |ip| is IPv6). - */ - ipv6Only?: boolean; - /** - * Make different transports bind to the same IP and port (only for UDP). - * Useful for multicast scenarios with plain transport. Use with caution. - */ - udpReusePort?: boolean; -}; - -export type TransportTuple = { - // @deprecated Use localAddress instead. - localIp: string; - localAddress: string; - localPort: number; - remoteIp?: string; - remotePort?: number; - protocol: TransportProtocol; -}; - -/** - * Valid types for 'trace' event. - */ -export type TransportTraceEventType = 'probation' | 'bwe'; - -/** - * 'trace' event data. - */ -export type TransportTraceEventData = { - /** - * Trace type. - */ - type: TransportTraceEventType; - - /** - * Event timestamp. - */ - timestamp: number; - - /** - * Event direction. - */ - direction: 'in' | 'out'; - - /** - * Per type information. - */ - info: any; -}; - -export type SctpState = - | 'new' - | 'connecting' - | 'connected' - | 'failed' - | 'closed'; - -export type TransportEvents = { - routerclose: []; - listenserverclose: []; - trace: [TransportTraceEventData]; - listenererror: [string, Error]; - // Private events. - '@close': []; - '@newproducer': [Producer]; - '@producerclose': [Producer]; - '@newdataproducer': [DataProducer]; - '@dataproducerclose': [DataProducer]; - '@listenserverclose': []; -}; - -export type TransportObserver = EnhancedEventEmitter; - -export type TransportObserverEvents = { - close: []; - newproducer: [Producer]; - newconsumer: [Consumer]; - newdataproducer: [DataProducer]; - newdataconsumer: [DataConsumer]; - trace: [TransportTraceEventData]; -}; - export type TransportConstructorOptions = { internal: TransportInternal; data: TransportData; channel: Channel; appData?: TransportAppData; getRouterRtpCapabilities: () => RtpCapabilities; - getProducerById: (producerId: string) => Producer | undefined; - getDataProducerById: (dataProducerId: string) => DataProducer | undefined; + getProducerById: (producerId: string) => ProducerInterface | undefined; + getDataProducerById: ( + dataProducerId: string + ) => DataProducerInterface | undefined; }; export type TransportInternal = RouterInternal & { transportId: string; }; -export type BaseTransportDump = { - id: string; - direct: boolean; - producerIds: string[]; - consumerIds: string[]; - mapSsrcConsumerId: { key: number; value: string }[]; - mapRtxSsrcConsumerId: { key: number; value: string }[]; - recvRtpHeaderExtensions: RecvRtpHeaderExtensions; - rtpListener: RtpListenerDump; - maxMessageSize: number; - dataProducerIds: string[]; - dataConsumerIds: string[]; - sctpParameters?: SctpParameters; - sctpState?: SctpState; - sctpListener?: SctpListenerDump; - traceEventTypes?: string[]; -}; - -export type BaseTransportStats = { - transportId: string; - timestamp: number; - sctpState?: SctpState; - bytesReceived: number; - recvBitrate: number; - bytesSent: number; - sendBitrate: number; - rtpBytesReceived: number; - rtpRecvBitrate: number; - rtpBytesSent: number; - rtpSendBitrate: number; - rtxBytesReceived: number; - rtxRecvBitrate: number; - rtxBytesSent: number; - rtxSendBitrate: number; - probationBytesSent: number; - probationSendBitrate: number; - availableOutgoingBitrate?: number; - availableIncomingBitrate?: number; - maxIncomingBitrate?: number; - maxOutgoingBitrate?: number; - minOutgoingBitrate?: number; - rtpPacketLossReceived?: number; - rtpPacketLossSent?: number; -}; - type TransportData = | WebRtcTransportData | PlainTransportData | PipeTransportData | DirectTransportData; -type RtpListenerDump = { - ssrcTable: { key: number; value: string }[]; - midTable: { key: number; value: string }[]; - ridTable: { key: number; value: string }[]; -}; - -type SctpListenerDump = { - streamIdTable: { key: number; value: string }[]; -}; - -type RecvRtpHeaderExtensions = { - mid?: number; - rid?: number; - rrid?: number; - absSendTime?: number; - transportWideCc01?: number; -}; - const logger = new Logger('Transport'); export abstract class Transport< - TransportAppData extends AppData = AppData, - Events extends TransportEvents = TransportEvents, - Observer extends TransportObserver = TransportObserver, -> extends EnhancedEventEmitter { + TransportAppData extends AppData = AppData, + Events extends TransportEvents = TransportEvents, + Observer extends TransportObserver = TransportObserver, + > + extends EnhancedEventEmitter + implements TransportInterface +{ // Internal data. protected readonly internal: TransportInternal; @@ -345,24 +133,26 @@ export abstract class Transport< // Method to retrieve a Producer. protected readonly getProducerById: ( producerId: string - ) => Producer | undefined; + ) => ProducerInterface | undefined; // Method to retrieve a DataProducer. protected readonly getDataProducerById: ( dataProducerId: string - ) => DataProducer | undefined; + ) => DataProducerInterface | undefined; // Producers map. - readonly #producers: Map = new Map(); + readonly #producers: Map = new Map(); // Consumers map. - protected readonly consumers: Map = new Map(); + protected readonly consumers: Map = new Map(); // DataProducers map. - protected readonly dataProducers: Map = new Map(); + protected readonly dataProducers: Map = + new Map(); // DataConsumers map. - protected readonly dataConsumers: Map = new Map(); + protected readonly dataConsumers: Map = + new Map(); // RTCP CNAME for Producers. #cnameForProducers?: string; @@ -732,7 +522,9 @@ export abstract class Transport< paused = false, keyFrameRequestDelay, appData, - }: ProducerOptions): Promise> { + }: ProducerOptions): Promise< + ProducerInterface + > { logger.debug('produce()'); if (id && this.#producers.has(id)) { @@ -825,7 +617,7 @@ export abstract class Transport< consumableRtpParameters, }; - const producer: Producer = new Producer({ + const producer: ProducerInterface = new Producer({ internal: { ...this.internal, producerId, @@ -865,7 +657,9 @@ export abstract class Transport< enableRtx, pipe = false, appData, - }: ConsumerOptions): Promise> { + }: ConsumerOptions): Promise< + ConsumerInterface + > { logger.debug('consume()'); if (!producerId || typeof producerId !== 'string') { @@ -952,7 +746,7 @@ export abstract class Transport< type: pipe ? 'pipe' : (producer.type as ConsumerType), }; - const consumer: Consumer = new Consumer({ + const consumer: ConsumerInterface = new Consumer({ internal: { ...this.internal, consumerId, @@ -992,7 +786,7 @@ export abstract class Transport< paused = false, appData, }: DataProducerOptions = {}): Promise< - DataProducer + DataProducerInterface > { logger.debug('produceData()'); @@ -1054,21 +848,22 @@ export abstract class Transport< const dump = parseDataProducerDumpResponse(produceDataResponse); - const dataProducer: DataProducer = new DataProducer({ - internal: { - ...this.internal, - dataProducerId, - }, - data: { - type: dump.type, - sctpStreamParameters: dump.sctpStreamParameters, - label: dump.label, - protocol: dump.protocol, - }, - channel: this.channel, - paused, - appData, - }); + const dataProducer: DataProducerInterface = + new DataProducer({ + internal: { + ...this.internal, + dataProducerId, + }, + data: { + type: dump.type, + sctpStreamParameters: dump.sctpStreamParameters, + label: dump.label, + protocol: dump.protocol, + }, + channel: this.channel, + paused, + appData, + }); this.dataProducers.set(dataProducer.id, dataProducer); dataProducer.on('@close', () => { @@ -1096,7 +891,7 @@ export abstract class Transport< subchannels, appData, }: DataConsumerOptions): Promise< - DataConsumer + DataConsumerInterface > { logger.debug('consumeData()'); @@ -1189,25 +984,26 @@ export abstract class Transport< const dump = parseDataConsumerDumpResponse(consumeDataResponse); - const dataConsumer: DataConsumer = new DataConsumer({ - internal: { - ...this.internal, - dataConsumerId, - }, - data: { - dataProducerId: dump.dataProducerId, - type: dump.type, - sctpStreamParameters: dump.sctpStreamParameters, - label: dump.label, - protocol: dump.protocol, - bufferedAmountLowThreshold: dump.bufferedAmountLowThreshold, - }, - channel: this.channel, - paused: dump.paused, - subchannels: dump.subchannels, - dataProducerPaused: dump.dataProducerPaused, - appData, - }); + const dataConsumer: DataConsumerInterface = + new DataConsumer({ + internal: { + ...this.internal, + dataConsumerId, + }, + data: { + dataProducerId: dump.dataProducerId, + type: dump.type, + sctpStreamParameters: dump.sctpStreamParameters, + label: dump.label, + protocol: dump.protocol, + bufferedAmountLowThreshold: dump.bufferedAmountLowThreshold, + }, + channel: this.channel, + paused: dump.paused, + subchannels: dump.subchannels, + dataProducerPaused: dump.dataProducerPaused, + appData, + }); this.dataConsumers.set(dataConsumer.id, dataConsumer); dataConsumer.on('@close', () => { @@ -1617,7 +1413,7 @@ function createConsumeRequest({ pipe, }: { builder: flatbuffers.Builder; - producer: Producer; + producer: ProducerInterface; consumerId: string; rtpParameters: RtpParameters; paused: boolean; diff --git a/node/src/TransportInterface.ts b/node/src/TransportInterface.ts new file mode 100644 index 0000000000..65cb0b1616 --- /dev/null +++ b/node/src/TransportInterface.ts @@ -0,0 +1,307 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { ProducerInterface, ProducerOptions } from './ProducerInterface'; +import { ConsumerInterface, ConsumerOptions } from './ConsumerInterface'; +import { + DataProducerInterface, + DataProducerOptions, +} from './DataProducerInterface'; +import { + DataConsumerInterface, + DataConsumerOptions, +} from './DataConsumerInterface'; +import { SctpParameters } from './SctpParameters'; +import { AppData } from './types'; + +export type TransportListenInfo = { + /** + * Network protocol. + */ + protocol: TransportProtocol; + + /** + * Listening IPv4 or IPv6. + */ + ip: string; + + /** + * @deprecated Use |announcedAddress| instead. + * + * Announced IPv4, IPv6 or hostname (useful when running mediasoup behind NAT + * with private IP). + */ + announcedIp?: string; + + /** + * Announced IPv4, IPv6 or hostname (useful when running mediasoup behind NAT + * with private IP). + */ + announcedAddress?: string; + + /** + * Listening port. + */ + port?: number; + + /** + * Listening port range. If given then |port| will be ignored. + */ + portRange?: TransportPortRange; + + /** + * Socket flags. + */ + flags?: TransportSocketFlags; + + /** + * Send buffer size (bytes). + */ + sendBufferSize?: number; + + /** + * Recv buffer size (bytes). + */ + recvBufferSize?: number; +}; + +/** + * Use TransportListenInfo instead. + * @deprecated + */ +export type TransportListenIp = { + /** + * Listening IPv4 or IPv6. + */ + ip: string; + + /** + * Announced IPv4, IPv6 or hostname (useful when running mediasoup behind NAT + * with private IP). + */ + announcedIp?: string; +}; + +/** + * Transport protocol. + */ +export type TransportProtocol = 'udp' | 'tcp'; + +/** + * Port range.. + */ +export type TransportPortRange = { + /** + * Lowest port in the range. + */ + min: number; + /** + * Highest port in the range. + */ + max: number; +}; + +/** + * UDP/TCP socket flags. + */ +export type TransportSocketFlags = { + /** + * Disable dual-stack support so only IPv6 is used (only if |ip| is IPv6). + */ + ipv6Only?: boolean; + /** + * Make different transports bind to the same IP and port (only for UDP). + * Useful for multicast scenarios with plain transport. Use with caution. + */ + udpReusePort?: boolean; +}; + +export type TransportTuple = { + // @deprecated Use localAddress instead. + localIp: string; + localAddress: string; + localPort: number; + remoteIp?: string; + remotePort?: number; + protocol: TransportProtocol; +}; + +export type SctpState = + | 'new' + | 'connecting' + | 'connected' + | 'failed' + | 'closed'; + +export type RtpListenerDump = { + ssrcTable: { key: number; value: string }[]; + midTable: { key: number; value: string }[]; + ridTable: { key: number; value: string }[]; +}; + +export type SctpListenerDump = { + streamIdTable: { key: number; value: string }[]; +}; + +export type RecvRtpHeaderExtensions = { + mid?: number; + rid?: number; + rrid?: number; + absSendTime?: number; + transportWideCc01?: number; +}; + +export type BaseTransportDump = { + id: string; + direct: boolean; + producerIds: string[]; + consumerIds: string[]; + mapSsrcConsumerId: { key: number; value: string }[]; + mapRtxSsrcConsumerId: { key: number; value: string }[]; + recvRtpHeaderExtensions: RecvRtpHeaderExtensions; + rtpListener: RtpListenerDump; + maxMessageSize: number; + dataProducerIds: string[]; + dataConsumerIds: string[]; + sctpParameters?: SctpParameters; + sctpState?: SctpState; + sctpListener?: SctpListenerDump; + traceEventTypes?: string[]; +}; + +export type BaseTransportStats = { + transportId: string; + timestamp: number; + sctpState?: SctpState; + bytesReceived: number; + recvBitrate: number; + bytesSent: number; + sendBitrate: number; + rtpBytesReceived: number; + rtpRecvBitrate: number; + rtpBytesSent: number; + rtpSendBitrate: number; + rtxBytesReceived: number; + rtxRecvBitrate: number; + rtxBytesSent: number; + rtxSendBitrate: number; + probationBytesSent: number; + probationSendBitrate: number; + availableOutgoingBitrate?: number; + availableIncomingBitrate?: number; + maxIncomingBitrate?: number; + maxOutgoingBitrate?: number; + minOutgoingBitrate?: number; + rtpPacketLossReceived?: number; + rtpPacketLossSent?: number; +}; + +/** + * Valid types for 'trace' event. + */ +export type TransportTraceEventType = 'probation' | 'bwe'; + +/** + * 'trace' event data. + */ +export type TransportTraceEventData = { + /** + * Trace type. + */ + type: TransportTraceEventType; + + /** + * Event timestamp. + */ + timestamp: number; + + /** + * Event direction. + */ + direction: 'in' | 'out'; + + /** + * Per type information. + */ + info: any; +}; + +export type TransportEvents = { + routerclose: []; + listenserverclose: []; + trace: [TransportTraceEventData]; + listenererror: [string, Error]; + // Private events. + '@close': []; + '@newproducer': [ProducerInterface]; + '@producerclose': [ProducerInterface]; + '@newdataproducer': [DataProducerInterface]; + '@dataproducerclose': [DataProducerInterface]; + '@listenserverclose': []; +}; + +export type TransportObserver = EnhancedEventEmitter; + +export type TransportObserverEvents = { + close: []; + newproducer: [ProducerInterface]; + newconsumer: [ConsumerInterface]; + newdataproducer: [DataProducerInterface]; + newdataconsumer: [DataConsumerInterface]; + trace: [TransportTraceEventData]; +}; + +export interface TransportInterface< + TransportAppData extends AppData = AppData, + Events extends TransportEvents = TransportEvents, + Observer extends TransportObserver = TransportObserver, +> extends EnhancedEventEmitter { + get id(): string; + + get closed(): boolean; + + get appData(): TransportAppData; + + set appData(appData: TransportAppData); + + get observer(): Observer; + + close(): void; + + /** + * Router was closed. + * + * @private + */ + routerClosed(): void; + + /** + * Listen server was closed (this just happens in WebRtcTransports when their + * associated WebRtcServer is closed). + * + * @private + */ + listenServerClosed(): void; + + setMaxIncomingBitrate(bitrate: number): Promise; + + setMaxOutgoingBitrate(bitrate: number): Promise; + + setMinOutgoingBitrate(bitrate: number): Promise; + + produce( + options: ProducerOptions + ): Promise>; + + consume( + options: ConsumerOptions + ): Promise>; + + produceData( + options?: DataProducerOptions + ): Promise>; + + consumeData( + options: DataConsumerOptions + ): Promise>; + + enableTraceEvent(types?: TransportTraceEventType[]): Promise; +} diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index 385a49e638..1822492171 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -1,81 +1,33 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { Channel } from './Channel'; -import { TransportListenInfo } from './Transport'; -import { WebRtcTransport } from './WebRtcTransport'; +import { + WebRtcServerInterface, + IpPort, + IceUserNameFragment, + TupleHash, + WebRtcServerDump, + WebRtcServerEvents, + WebRtcServerObserver, + WebRtcServerObserverEvents, +} from './WebRtcServerInterface'; +import { WebRtcTransportInterface } from './WebRtcTransportInterface'; import { AppData } from './types'; import * as utils from './utils'; import { Body as RequestBody, Method } from './fbs/request'; import * as FbsWorker from './fbs/worker'; import * as FbsWebRtcServer from './fbs/web-rtc-server'; -export type WebRtcServerOptions = - { - /** - * Listen infos. - */ - listenInfos: TransportListenInfo[]; - - /** - * Custom application data. - */ - appData?: WebRtcServerAppData; - }; - -/** - * @deprecated Use TransportListenInfo instead. - */ -export type WebRtcServerListenInfo = TransportListenInfo; - -export type WebRtcServerEvents = { - workerclose: []; - listenererror: [string, Error]; - // Private events. - '@close': []; -}; - -export type WebRtcServerObserver = - EnhancedEventEmitter; - -export type WebRtcServerObserverEvents = { - close: []; - webrtctransporthandled: [WebRtcTransport]; - webrtctransportunhandled: [WebRtcTransport]; -}; - -export type WebRtcServerDump = { - id: string; - udpSockets: IpPort[]; - tcpServers: IpPort[]; - webRtcTransportIds: string[]; - localIceUsernameFragments: IceUserNameFragment[]; - tupleHashes: TupleHash[]; -}; - -type IpPort = { - ip: string; - port: number; -}; - -type IceUserNameFragment = { - localIceUsernameFragment: string; - webRtcTransportId: string; -}; - -type TupleHash = { - tupleHash: number; - webRtcTransportId: string; -}; - type WebRtcServerInternal = { webRtcServerId: string; }; const logger = new Logger('WebRtcServer'); -export class WebRtcServer< - WebRtcServerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export class WebRtcServer + extends EnhancedEventEmitter + implements WebRtcServerInterface +{ // Internal data. readonly #internal: WebRtcServerInternal; @@ -89,7 +41,7 @@ export class WebRtcServer< #appData: WebRtcServerAppData; // Transports map. - readonly #webRtcTransports: Map = new Map(); + readonly #webRtcTransports: Map = new Map(); // Observer instance. readonly #observer: WebRtcServerObserver = @@ -155,7 +107,7 @@ export class WebRtcServer< * @private * Just for testing purposes. */ - get webRtcTransportsForTesting(): Map { + get webRtcTransportsForTesting(): Map { return this.#webRtcTransports; } @@ -247,7 +199,7 @@ export class WebRtcServer< /** * @private */ - handleWebRtcTransport(webRtcTransport: WebRtcTransport): void { + handleWebRtcTransport(webRtcTransport: WebRtcTransportInterface): void { this.#webRtcTransports.set(webRtcTransport.id, webRtcTransport); // Emit observer event. diff --git a/node/src/WebRtcServerInterface.ts b/node/src/WebRtcServerInterface.ts new file mode 100644 index 0000000000..fc3b527b27 --- /dev/null +++ b/node/src/WebRtcServerInterface.ts @@ -0,0 +1,98 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { TransportListenInfo } from './TransportInterface'; +import { WebRtcTransportInterface } from './WebRtcTransportInterface'; +import { AppData } from './types'; + +export type WebRtcServerOptions = + { + /** + * Listen infos. + */ + listenInfos: TransportListenInfo[]; + + /** + * Custom application data. + */ + appData?: WebRtcServerAppData; + }; + +/** + * @deprecated Use TransportListenInfo instead. + */ +export type WebRtcServerListenInfo = TransportListenInfo; + +export type IpPort = { + ip: string; + port: number; +}; + +export type IceUserNameFragment = { + localIceUsernameFragment: string; + webRtcTransportId: string; +}; + +export type TupleHash = { + tupleHash: number; + webRtcTransportId: string; +}; + +export type WebRtcServerDump = { + id: string; + udpSockets: IpPort[]; + tcpServers: IpPort[]; + webRtcTransportIds: string[]; + localIceUsernameFragments: IceUserNameFragment[]; + tupleHashes: TupleHash[]; +}; + +export type WebRtcServerEvents = { + workerclose: []; + listenererror: [string, Error]; + // Private events. + '@close': []; +}; + +export type WebRtcServerObserver = + EnhancedEventEmitter; + +export type WebRtcServerObserverEvents = { + close: []; + webrtctransporthandled: [WebRtcTransportInterface]; + webrtctransportunhandled: [WebRtcTransportInterface]; +}; + +export interface WebRtcServerInterface< + WebRtcServerAppData extends AppData = AppData, +> extends EnhancedEventEmitter { + get id(): string; + + get closed(): boolean; + + get appData(): WebRtcServerAppData; + + /** + * App custom data setter. + */ + set appData(appData: WebRtcServerAppData); + + /** + * Observer. + */ + get observer(): WebRtcServerObserver; + + close(): void; + + /** + * Worker was closed. + * + * @private + */ + workerClosed(): void; + + dump(): Promise; + + /** + * @private + */ + handleWebRtcTransport(webRtcTransport: WebRtcTransportInterface): void; +} diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index 9f908ec19c..14a4fde516 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -2,27 +2,41 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { + WebRtcTransportInterface, + IceParameters, + IceCandidate, + DtlsParameters, + FingerprintAlgorithm, + DtlsFingerprint, + IceRole, + IceState, + IceCandidateType, + IceCandidateTcpType, + DtlsRole, + DtlsState, + WebRtcTransportDump, + WebRtcTransportStat, + WebRtcTransportEvents, + WebRtcTransportObserver, + WebRtcTransportObserverEvents, +} from './WebRtcTransportInterface'; +import { + TransportInterface, + TransportTuple, + SctpState, +} from './TransportInterface'; +import { + Transport, + TransportConstructorOptions, parseSctpState, parseBaseTransportDump, parseBaseTransportStats, parseProtocol, parseTransportTraceEventData, parseTuple, - BaseTransportDump, - BaseTransportStats, - Transport, - TransportListenInfo, - TransportListenIp, - TransportProtocol, - TransportTuple, - TransportEvents, - TransportObserverEvents, - TransportConstructorOptions, - SctpState, } from './Transport'; -import { WebRtcServer } from './WebRtcServer'; -import { SctpParameters, NumSctpStreams } from './SctpParameters'; -import { AppData, Either } from './types'; +import { SctpParameters } from './SctpParameters'; +import { AppData } from './types'; import { parseVector } from './utils'; import { Event, Notification } from './fbs/notification'; import * as FbsRequest from './fbs/request'; @@ -36,196 +50,6 @@ import { IceRole as FbsIceRole } from './fbs/web-rtc-transport/ice-role'; import { IceCandidateType as FbsIceCandidateType } from './fbs/web-rtc-transport/ice-candidate-type'; import { IceCandidateTcpType as FbsIceCandidateTcpType } from './fbs/web-rtc-transport/ice-candidate-tcp-type'; -export type WebRtcTransportOptions< - WebRtcTransportAppData extends AppData = AppData, -> = WebRtcTransportOptionsBase & WebRtcTransportListen; - -type WebRtcTransportListenIndividualListenInfo = { - /** - * Listening info. - */ - listenInfos: TransportListenInfo[]; -}; - -type WebRtcTransportListenIndividualListenIp = { - /** - * Listening IP address or addresses in order of preference (first one is the - * preferred one). - */ - listenIps: (TransportListenIp | string)[]; - - /** - * Fixed port to listen on instead of selecting automatically from Worker's port - * range. - */ - port?: number; -}; - -type WebRtcTransportListenServer = { - /** - * Instance of WebRtcServer. - */ - webRtcServer: WebRtcServer; -}; - -type WebRtcTransportListen = Either< - Either< - WebRtcTransportListenIndividualListenInfo, - WebRtcTransportListenIndividualListenIp - >, - WebRtcTransportListenServer ->; - -export type WebRtcTransportOptionsBase = { - /** - * Listen in UDP. Default true. - */ - enableUdp?: boolean; - - /** - * Listen in TCP. Default true if webrtcServer is given, false otherwise. - */ - enableTcp?: boolean; - - /** - * Prefer UDP. Default false. - */ - preferUdp?: boolean; - - /** - * Prefer TCP. Default false. - */ - preferTcp?: boolean; - - /** - * ICE consent timeout (in seconds). If 0 it is disabled. Default 30. - */ - iceConsentTimeout?: number; - - /** - * Initial available outgoing bitrate (in bps). Default 600000. - */ - initialAvailableOutgoingBitrate?: number; - - /** - * Create a SCTP association. Default false. - */ - enableSctp?: boolean; - - /** - * SCTP streams number. - */ - numSctpStreams?: NumSctpStreams; - - /** - * Maximum allowed size for SCTP messages sent by DataProducers. - * Default 262144. - */ - maxSctpMessageSize?: number; - - /** - * Maximum SCTP send buffer used by DataConsumers. - * Default 262144. - */ - sctpSendBufferSize?: number; - - /** - * Custom application data. - */ - appData?: WebRtcTransportAppData; -}; - -export type IceParameters = { - usernameFragment: string; - password: string; - iceLite?: boolean; -}; - -export type IceCandidate = { - foundation: string; - priority: number; - // @deprecated Use |address| instead. - ip: string; - address: string; - protocol: TransportProtocol; - port: number; - type: IceCandidateType; - tcpType?: IceCandidateTcpType; -}; - -export type DtlsParameters = { - role?: DtlsRole; - fingerprints: DtlsFingerprint[]; -}; - -/** - * The hash function algorithm (as defined in the "Hash function Textual Names" - * registry initially specified in RFC 4572 Section 8). - */ -export type FingerprintAlgorithm = - | 'sha-1' - | 'sha-224' - | 'sha-256' - | 'sha-384' - | 'sha-512'; - -/** - * The hash function algorithm and its corresponding certificate fingerprint - * value (in lowercase hex string as expressed utilizing the syntax of - * "fingerprint" in RFC 4572 Section 5). - */ -export type DtlsFingerprint = { - algorithm: FingerprintAlgorithm; - value: string; -}; - -export type IceRole = 'controlled' | 'controlling'; - -export type IceState = - | 'new' - | 'connected' - | 'completed' - | 'disconnected' - | 'closed'; - -export type IceCandidateType = 'host'; - -export type IceCandidateTcpType = 'passive'; - -export type DtlsRole = 'auto' | 'client' | 'server'; - -export type DtlsState = - | 'new' - | 'connecting' - | 'connected' - | 'failed' - | 'closed'; - -export type WebRtcTransportStat = BaseTransportStats & { - type: string; - iceRole: string; - iceState: IceState; - iceSelectedTuple?: TransportTuple; - dtlsState: DtlsState; -}; - -export type WebRtcTransportEvents = TransportEvents & { - icestatechange: [IceState]; - iceselectedtuplechange: [TransportTuple]; - dtlsstatechange: [DtlsState]; - sctpstatechange: [SctpState]; -}; - -export type WebRtcTransportObserver = - EnhancedEventEmitter; - -export type WebRtcTransportObserverEvents = TransportObserverEvents & { - icestatechange: [IceState]; - iceselectedtuplechange: [TransportTuple]; - dtlsstatechange: [DtlsState]; - sctpstatechange: [SctpState]; -}; - type WebRtcTransportConstructorOptions = TransportConstructorOptions & { data: WebRtcTransportData; @@ -244,26 +68,16 @@ export type WebRtcTransportData = { sctpState?: SctpState; }; -type WebRtcTransportDump = BaseTransportDump & { - iceRole: 'controlled'; - iceParameters: IceParameters; - iceCandidates: IceCandidate[]; - iceState: IceState; - iceSelectedTuple?: TransportTuple; - dtlsParameters: DtlsParameters; - dtlsState: DtlsState; - dtlsRemoteCert?: string; -}; - const logger = new Logger('WebRtcTransport'); -export class WebRtcTransport< - WebRtcTransportAppData extends AppData = AppData, -> extends Transport< - WebRtcTransportAppData, - WebRtcTransportEvents, - WebRtcTransportObserver -> { +export class WebRtcTransport + extends Transport< + WebRtcTransportAppData, + WebRtcTransportEvents, + WebRtcTransportObserver + > + implements TransportInterface, WebRtcTransportInterface +{ // WebRtcTransport data. readonly #data: WebRtcTransportData; @@ -442,7 +256,7 @@ export class WebRtcTransport< } /** - * Dump Transport. + * Dump WebRtcTransport. */ async dump(): Promise { logger.debug('dump()'); diff --git a/node/src/WebRtcTransportInterface.ts b/node/src/WebRtcTransportInterface.ts new file mode 100644 index 0000000000..1b95cd68cc --- /dev/null +++ b/node/src/WebRtcTransportInterface.ts @@ -0,0 +1,277 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + TransportInterface, + TransportListenInfo, + TransportListenIp, + TransportProtocol, + TransportTuple, + SctpState, + BaseTransportDump, + BaseTransportStats, + TransportEvents, + TransportObserverEvents, +} from './TransportInterface'; +import { WebRtcServerInterface } from './WebRtcServerInterface'; +import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { Either, AppData } from './types'; + +export type WebRtcTransportOptions< + WebRtcTransportAppData extends AppData = AppData, +> = WebRtcTransportOptionsBase & WebRtcTransportListen; + +type WebRtcTransportOptionsBase = { + /** + * Listen in UDP. Default true. + */ + enableUdp?: boolean; + + /** + * Listen in TCP. Default true if webrtcServer is given, false otherwise. + */ + enableTcp?: boolean; + + /** + * Prefer UDP. Default false. + */ + preferUdp?: boolean; + + /** + * Prefer TCP. Default false. + */ + preferTcp?: boolean; + + /** + * ICE consent timeout (in seconds). If 0 it is disabled. Default 30. + */ + iceConsentTimeout?: number; + + /** + * Initial available outgoing bitrate (in bps). Default 600000. + */ + initialAvailableOutgoingBitrate?: number; + + /** + * Create a SCTP association. Default false. + */ + enableSctp?: boolean; + + /** + * SCTP streams number. + */ + numSctpStreams?: NumSctpStreams; + + /** + * Maximum allowed size for SCTP messages sent by DataProducers. + * Default 262144. + */ + maxSctpMessageSize?: number; + + /** + * Maximum SCTP send buffer used by DataConsumers. + * Default 262144. + */ + sctpSendBufferSize?: number; + + /** + * Custom application data. + */ + appData?: WebRtcTransportAppData; +}; + +type WebRtcTransportListen = Either< + Either< + WebRtcTransportListenIndividualListenInfo, + WebRtcTransportListenIndividualListenIp + >, + WebRtcTransportListenServer +>; + +type WebRtcTransportListenIndividualListenInfo = { + /** + * Listening info. + */ + listenInfos: TransportListenInfo[]; +}; + +type WebRtcTransportListenIndividualListenIp = { + /** + * Listening IP address or addresses in order of preference (first one is the + * preferred one). + */ + listenIps: (TransportListenIp | string)[]; + + /** + * Fixed port to listen on instead of selecting automatically from Worker's port + * range. + */ + port?: number; +}; + +type WebRtcTransportListenServer = { + /** + * Instance of WebRtcServer. + */ + webRtcServer: WebRtcServerInterface; +}; + +export type IceParameters = { + usernameFragment: string; + password: string; + iceLite?: boolean; +}; + +export type IceCandidate = { + foundation: string; + priority: number; + // @deprecated Use |address| instead. + ip: string; + address: string; + protocol: TransportProtocol; + port: number; + type: IceCandidateType; + tcpType?: IceCandidateTcpType; +}; + +export type DtlsParameters = { + role?: DtlsRole; + fingerprints: DtlsFingerprint[]; +}; + +/** + * The hash function algorithm (as defined in the "Hash function Textual Names" + * registry initially specified in RFC 4572 Section 8). + */ +export type FingerprintAlgorithm = + | 'sha-1' + | 'sha-224' + | 'sha-256' + | 'sha-384' + | 'sha-512'; + +/** + * The hash function algorithm and its corresponding certificate fingerprint + * value (in lowercase hex string as expressed utilizing the syntax of + * "fingerprint" in RFC 4572 Section 5). + */ +export type DtlsFingerprint = { + algorithm: FingerprintAlgorithm; + value: string; +}; + +export type IceRole = 'controlled' | 'controlling'; + +export type IceState = + | 'new' + | 'connected' + | 'completed' + | 'disconnected' + | 'closed'; + +export type IceCandidateType = 'host'; + +export type IceCandidateTcpType = 'passive'; + +export type DtlsRole = 'auto' | 'client' | 'server'; + +export type DtlsState = + | 'new' + | 'connecting' + | 'connected' + | 'failed' + | 'closed'; + +export type WebRtcTransportDump = BaseTransportDump & { + iceRole: 'controlled'; + iceParameters: IceParameters; + iceCandidates: IceCandidate[]; + iceState: IceState; + iceSelectedTuple?: TransportTuple; + dtlsParameters: DtlsParameters; + dtlsState: DtlsState; + dtlsRemoteCert?: string; +}; + +export type WebRtcTransportStat = BaseTransportStats & { + type: string; + iceRole: string; + iceState: IceState; + iceSelectedTuple?: TransportTuple; + dtlsState: DtlsState; +}; + +export type WebRtcTransportEvents = TransportEvents & { + icestatechange: [IceState]; + iceselectedtuplechange: [TransportTuple]; + dtlsstatechange: [DtlsState]; + sctpstatechange: [SctpState]; +}; + +export type WebRtcTransportObserver = + EnhancedEventEmitter; + +export type WebRtcTransportObserverEvents = TransportObserverEvents & { + icestatechange: [IceState]; + iceselectedtuplechange: [TransportTuple]; + dtlsstatechange: [DtlsState]; + sctpstatechange: [SctpState]; +}; + +export interface WebRtcTransportInterface< + WebRtcTransportAppData extends AppData = AppData, +> extends TransportInterface< + WebRtcTransportAppData, + WebRtcTransportEvents, + WebRtcTransportObserver + > { + get observer(): WebRtcTransportObserver; + + get iceRole(): 'controlled'; + + get iceParameters(): IceParameters; + + get iceCandidates(): IceCandidate[]; + + get iceState(): IceState; + + /** + * ICE selected tuple. + */ + get iceSelectedTuple(): TransportTuple | undefined; + + /** + * DTLS parameters. + */ + get dtlsParameters(): DtlsParameters; + + /** + * DTLS state. + */ + get dtlsState(): DtlsState; + + /** + * Remote certificate in PEM format. + */ + get dtlsRemoteCert(): string | undefined; + + /** + * SCTP parameters. + */ + get sctpParameters(): SctpParameters | undefined; + + /** + * SCTP state. + */ + get sctpState(): SctpState | undefined; + + dump(): Promise; + + getStats(): Promise; + + connect({ + dtlsParameters, + }: { + dtlsParameters: DtlsParameters; + }): Promise; + + restartIce(): Promise; +} diff --git a/node/src/Worker.ts b/node/src/Worker.ts index c1d2e20f7c..08fda4bd2a 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -5,9 +5,24 @@ import { version } from './'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; +import { + WorkerInterface, + WorkerSettings, + WorkerUpdateableSettings, + WorkerResourceUsage, + WorkerDump, + WorkerEvents, + WorkerObserver, + WorkerObserverEvents, +} from './WorkerInterface'; import { Channel } from './Channel'; -import { Router, RouterOptions } from './Router'; -import { WebRtcServer, WebRtcServerOptions } from './WebRtcServer'; +import { + WebRtcServerInterface, + WebRtcServerOptions, +} from './WebRtcServerInterface'; +import { WebRtcServer } from './WebRtcServer'; +import { RouterInterface, RouterOptions } from './RouterInterface'; +import { Router } from './Router'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; import { RtpCodecCapability } from './RtpParameters'; import { AppData } from './types'; @@ -18,207 +33,6 @@ import * as FbsWorker from './fbs/worker'; import * as FbsTransport from './fbs/transport'; import { Protocol as FbsTransportProtocol } from './fbs/transport/protocol'; -export type WorkerLogLevel = 'debug' | 'warn' | 'error' | 'none'; - -export type WorkerLogTag = - | 'info' - | 'ice' - | 'dtls' - | 'rtp' - | 'srtp' - | 'rtcp' - | 'rtx' - | 'bwe' - | 'score' - | 'simulcast' - | 'svc' - | 'sctp' - | 'message'; - -export type WorkerSettings = { - /** - * Logging level for logs generated by the media worker subprocesses (check - * the Debugging documentation). Valid values are 'debug', 'warn', 'error' and - * 'none'. Default 'error'. - */ - logLevel?: WorkerLogLevel; - - /** - * Log tags for debugging. Check the meaning of each available tag in the - * Debugging documentation. - */ - logTags?: WorkerLogTag[]; - - /** - * Minimun RTC port for ICE, DTLS, RTP, etc. Default 10000. - * @deprecated Use |portRange| in TransportListenInfo object instead. - */ - rtcMinPort?: number; - - /** - * Maximum RTC port for ICE, DTLS, RTP, etc. Default 59999. - * @deprecated Use |portRange| in TransportListenInfo object instead. - */ - rtcMaxPort?: number; - - /** - * Path to the DTLS public certificate file in PEM format. If unset, a - * certificate is dynamically created. - */ - dtlsCertificateFile?: string; - - /** - * Path to the DTLS certificate private key file in PEM format. If unset, a - * certificate is dynamically created. - */ - dtlsPrivateKeyFile?: string; - - /** - * Field trials for libwebrtc. - * @private - * - * NOTE: For advanced users only. An invalid value will make the worker crash. - * Default value is - * "WebRTC-Bwe-AlrLimitedBackoff/Enabled/". - */ - libwebrtcFieldTrials?: string; - - /** - * Disable liburing (io_uring) despite it's supported in current host. - */ - disableLiburing?: boolean; - - /** - * Custom application data. - */ - appData?: WorkerAppData; -}; - -export type WorkerUpdateableSettings = Pick< - WorkerSettings, - 'logLevel' | 'logTags' ->; - -/** - * An object with the fields of the uv_rusage_t struct. - * - * - http://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t - * - https://linux.die.net/man/2/getrusage - */ -export type WorkerResourceUsage = { - /** - * User CPU time used (in ms). - */ - ru_utime: number; - - /** - * System CPU time used (in ms). - */ - ru_stime: number; - - /** - * Maximum resident set size. - */ - ru_maxrss: number; - - /** - * Integral shared memory size. - */ - ru_ixrss: number; - - /** - * Integral unshared data size. - */ - ru_idrss: number; - - /** - * Integral unshared stack size. - */ - ru_isrss: number; - - /** - * Page reclaims (soft page faults). - */ - ru_minflt: number; - - /** - * Page faults (hard page faults). - */ - ru_majflt: number; - - /** - * Swaps. - */ - ru_nswap: number; - - /** - * Block input operations. - */ - ru_inblock: number; - - /** - * Block output operations. - */ - ru_oublock: number; - - /** - * IPC messages sent. - */ - ru_msgsnd: number; - - /** - * IPC messages received. - */ - ru_msgrcv: number; - - /** - * Signals received. - */ - ru_nsignals: number; - - /** - * Voluntary context switches. - */ - ru_nvcsw: number; - - /** - * Involuntary context switches. - */ - ru_nivcsw: number; -}; - -export type WorkerDump = { - pid: number; - webRtcServerIds: string[]; - routerIds: string[]; - channelMessageHandlers: { - channelRequestHandlers: string[]; - channelNotificationHandlers: string[]; - }; - liburing?: { - sqeProcessCount: number; - sqeMissCount: number; - userDataMissCount: number; - }; -}; - -export type WorkerEvents = { - died: [Error]; - subprocessclose: []; - listenererror: [string, Error]; - // Private events. - '@success': []; - '@failure': [Error]; -}; - -export type WorkerObserver = EnhancedEventEmitter; - -export type WorkerObserverEvents = { - close: []; - newwebrtcserver: [WebRtcServer]; - newrouter: [Router]; -}; - // If env MEDIASOUP_WORKER_BIN is given, use it as worker binary. // Otherwise if env MEDIASOUP_BUILDTYPE is 'Debug' use the Debug binary. // Otherwise use the Release binary. @@ -247,9 +61,10 @@ export const workerBin = process.env.MEDIASOUP_WORKER_BIN const logger = new Logger('Worker'); const workerLogger = new Logger('Worker'); -export class Worker< - WorkerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export class Worker + extends EnhancedEventEmitter + implements WorkerInterface +{ // mediasoup-worker child process. #child: ChildProcess; @@ -272,10 +87,10 @@ export class Worker< #appData: WorkerAppData; // WebRtcServers set. - readonly #webRtcServers: Set = new Set(); + readonly #webRtcServers: Set = new Set(); // Routers set. - readonly #routers: Set = new Set(); + readonly #routers: Set = new Set(); // Observer instance. readonly #observer: WorkerObserver = @@ -541,18 +356,20 @@ export class Worker< } /** - * @private * Just for testing purposes. + * + * @private */ - get webRtcServersForTesting(): Set { + get webRtcServersForTesting(): Set { return this.#webRtcServers; } /** - * @private * Just for testing purposes. + * + * @private */ - get routersForTesting(): Set { + get routersForTesting(): Set { return this.#routers; } @@ -673,7 +490,7 @@ export class Worker< listenInfos, appData, }: WebRtcServerOptions): Promise< - WebRtcServer + WebRtcServerInterface > { logger.debug('createWebRtcServer()'); @@ -715,11 +532,12 @@ export class Worker< createWebRtcServerRequestOffset ); - const webRtcServer: WebRtcServer = new WebRtcServer({ - internal: { webRtcServerId }, - channel: this.#channel, - appData, - }); + const webRtcServer: WebRtcServerInterface = + new WebRtcServer({ + internal: { webRtcServerId }, + channel: this.#channel, + appData, + }); this.#webRtcServers.add(webRtcServer); webRtcServer.on('@close', () => this.#webRtcServers.delete(webRtcServer)); @@ -736,7 +554,9 @@ export class Worker< async createRouter({ mediaCodecs, appData, - }: RouterOptions = {}): Promise> { + }: RouterOptions = {}): Promise< + RouterInterface + > { logger.debug('createRouter()'); if (appData && typeof appData !== 'object') { @@ -766,7 +586,7 @@ export class Worker< ); const data = { rtpCapabilities }; - const router: Router = new Router({ + const router: RouterInterface = new Router({ internal: { routerId, }, diff --git a/node/src/WorkerInterface.ts b/node/src/WorkerInterface.ts new file mode 100644 index 0000000000..30b3696546 --- /dev/null +++ b/node/src/WorkerInterface.ts @@ -0,0 +1,255 @@ +import { EnhancedEventEmitter } from './enhancedEvents'; +import { + WebRtcServerInterface, + WebRtcServerOptions, +} from './WebRtcServerInterface'; +import { RouterInterface, RouterOptions } from './RouterInterface'; +import { AppData } from './types'; + +export type WorkerLogLevel = 'debug' | 'warn' | 'error' | 'none'; + +export type WorkerLogTag = + | 'info' + | 'ice' + | 'dtls' + | 'rtp' + | 'srtp' + | 'rtcp' + | 'rtx' + | 'bwe' + | 'score' + | 'simulcast' + | 'svc' + | 'sctp' + | 'message'; + +export type WorkerSettings = { + /** + * Logging level for logs generated by the media worker subprocesses (check + * the Debugging documentation). Valid values are 'debug', 'warn', 'error' and + * 'none'. Default 'error'. + */ + logLevel?: WorkerLogLevel; + + /** + * Log tags for debugging. Check the meaning of each available tag in the + * Debugging documentation. + */ + logTags?: WorkerLogTag[]; + + /** + * Minimun RTC port for ICE, DTLS, RTP, etc. Default 10000. + * @deprecated Use |portRange| in TransportListenInfo object instead. + */ + rtcMinPort?: number; + + /** + * Maximum RTC port for ICE, DTLS, RTP, etc. Default 59999. + * @deprecated Use |portRange| in TransportListenInfo object instead. + */ + rtcMaxPort?: number; + + /** + * Path to the DTLS public certificate file in PEM format. If unset, a + * certificate is dynamically created. + */ + dtlsCertificateFile?: string; + + /** + * Path to the DTLS certificate private key file in PEM format. If unset, a + * certificate is dynamically created. + */ + dtlsPrivateKeyFile?: string; + + /** + * Field trials for libwebrtc. + * @private + * + * NOTE: For advanced users only. An invalid value will make the worker crash. + * Default value is + * "WebRTC-Bwe-AlrLimitedBackoff/Enabled/". + */ + libwebrtcFieldTrials?: string; + + /** + * Disable liburing (io_uring) despite it's supported in current host. + */ + disableLiburing?: boolean; + + /** + * Custom application data. + */ + appData?: WorkerAppData; +}; + +export type WorkerUpdateableSettings = Pick< + WorkerSettings, + 'logLevel' | 'logTags' +>; + +/** + * An object with the fields of the uv_rusage_t struct. + * + * - http://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t + * - https://linux.die.net/man/2/getrusage + */ +export type WorkerResourceUsage = { + /** + * User CPU time used (in ms). + */ + ru_utime: number; + + /** + * System CPU time used (in ms). + */ + ru_stime: number; + + /** + * Maximum resident set size. + */ + ru_maxrss: number; + + /** + * Integral shared memory size. + */ + ru_ixrss: number; + + /** + * Integral unshared data size. + */ + ru_idrss: number; + + /** + * Integral unshared stack size. + */ + ru_isrss: number; + + /** + * Page reclaims (soft page faults). + */ + ru_minflt: number; + + /** + * Page faults (hard page faults). + */ + ru_majflt: number; + + /** + * Swaps. + */ + ru_nswap: number; + + /** + * Block input operations. + */ + ru_inblock: number; + + /** + * Block output operations. + */ + ru_oublock: number; + + /** + * IPC messages sent. + */ + ru_msgsnd: number; + + /** + * IPC messages received. + */ + ru_msgrcv: number; + + /** + * Signals received. + */ + ru_nsignals: number; + + /** + * Voluntary context switches. + */ + ru_nvcsw: number; + + /** + * Involuntary context switches. + */ + ru_nivcsw: number; +}; + +export type WorkerDump = { + pid: number; + webRtcServerIds: string[]; + routerIds: string[]; + channelMessageHandlers: { + channelRequestHandlers: string[]; + channelNotificationHandlers: string[]; + }; + liburing?: { + sqeProcessCount: number; + sqeMissCount: number; + userDataMissCount: number; + }; +}; + +export type WorkerEvents = { + died: [Error]; + subprocessclose: []; + listenererror: [string, Error]; + // Private events. + '@success': []; + '@failure': [Error]; +}; + +export type WorkerObserver = EnhancedEventEmitter; + +export type WorkerObserverEvents = { + close: []; + newwebrtcserver: [WebRtcServerInterface]; + newrouter: [RouterInterface]; +}; + +export interface WorkerInterface + extends EnhancedEventEmitter { + get pid(): number; + + get closed(): boolean; + + get died(): boolean; + + /** + * Whether the Worker subprocess is closed. + */ + get subprocessClosed(): boolean; + + /** + * App custom data. + */ + get appData(): WorkerAppData; + + /** + * App custom data setter. + */ + set appData(appData: WorkerAppData); + + /** + * Observer. + */ + get observer(): WorkerObserver; + + close(): void; + + dump(): Promise; + + getResourceUsage(): Promise; + + updateSettings( + options?: WorkerUpdateableSettings + ): Promise; + + createWebRtcServer( + options: WebRtcServerOptions + ): Promise>; + + createRouter( + options?: RouterOptions + ): Promise>; +} diff --git a/node/src/index.ts b/node/src/index.ts index 9239dc77ac..a781d44ddb 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -1,6 +1,7 @@ import { Logger, LoggerEmitter } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { workerBin, Worker, WorkerSettings } from './Worker'; +import { WorkerInterface, WorkerSettings } from './WorkerInterface'; +import { Worker, workerBin } from './Worker'; import * as utils from './utils'; import { supportedRtpCapabilities } from './supportedRtpCapabilities'; import { RtpCapabilities } from './RtpParameters'; @@ -26,7 +27,7 @@ export { parse as parseScalabilityMode } from './scalabilityModes'; export type Observer = EnhancedEventEmitter; export type ObserverEvents = { - newworker: [Worker]; + newworker: [WorkerInterface]; }; const observer: Observer = new EnhancedEventEmitter(); @@ -116,14 +117,16 @@ export async function createWorker< libwebrtcFieldTrials, disableLiburing, appData, -}: WorkerSettings = {}): Promise> { +}: WorkerSettings = {}): Promise< + WorkerInterface +> { logger.debug('createWorker()'); if (appData && typeof appData !== 'object') { throw new TypeError('if given, appData must be an object'); } - const worker: Worker = new Worker({ + const worker: WorkerInterface = new Worker({ logLevel, logTags, rtcMinPort, diff --git a/node/src/test/test-ActiveSpeakerObserver.ts b/node/src/test/test-ActiveSpeakerObserver.ts index aaa922390d..f0d6c04d48 100644 --- a/node/src/test/test-ActiveSpeakerObserver.ts +++ b/node/src/test/test-ActiveSpeakerObserver.ts @@ -5,8 +5,8 @@ import * as utils from '../utils'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; }; const ctx: TestContext = { @@ -85,8 +85,8 @@ test('activeSpeakerObserver.pause() and resume() succeed', async () => { }, 2000); test('activeSpeakerObserver.close() succeeds', async () => { - const activeSpeakerObserver = await ctx.router!.createAudioLevelObserver({ - maxEntries: 8, + const activeSpeakerObserver = await ctx.router!.createActiveSpeakerObserver({ + interval: 500, }); let dump = await ctx.router!.dump(); @@ -103,7 +103,7 @@ test('activeSpeakerObserver.close() succeeds', async () => { }, 2000); test('ActiveSpeakerObserver emits "routerclose" if Router is closed', async () => { - const activeSpeakerObserver = await ctx.router!.createAudioLevelObserver(); + const activeSpeakerObserver = await ctx.router!.createActiveSpeakerObserver(); const promise = enhancedOnce( activeSpeakerObserver, @@ -117,7 +117,7 @@ test('ActiveSpeakerObserver emits "routerclose" if Router is closed', async () = }, 2000); test('ActiveSpeakerObserver emits "routerclose" if Worker is closed', async () => { - const activeSpeakerObserver = await ctx.router!.createAudioLevelObserver(); + const activeSpeakerObserver = await ctx.router!.createActiveSpeakerObserver(); const promise = enhancedOnce( activeSpeakerObserver, diff --git a/node/src/test/test-AudioLevelObserver.ts b/node/src/test/test-AudioLevelObserver.ts index f1a1a5fb17..4f3f716c0c 100644 --- a/node/src/test/test-AudioLevelObserver.ts +++ b/node/src/test/test-AudioLevelObserver.ts @@ -5,8 +5,8 @@ import * as utils from '../utils'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; }; const ctx: TestContext = { diff --git a/node/src/test/test-Consumer.ts b/node/src/test/test-Consumer.ts index aad102f089..f190163f92 100644 --- a/node/src/test/test-Consumer.ts +++ b/node/src/test/test-Consumer.ts @@ -2,6 +2,7 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents, ConsumerEvents } from '../types'; +import { Consumer } from '../Consumer'; import { UnsupportedError } from '../errors'; import * as utils from '../utils'; import { @@ -16,12 +17,12 @@ type TestContext = { audioProducerOptions: mediasoup.types.ProducerOptions; videoProducerOptions: mediasoup.types.ProducerOptions; consumerDeviceCapabilities: mediasoup.types.RtpCapabilities; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; - webRtcTransport1?: mediasoup.types.WebRtcTransport; - webRtcTransport2?: mediasoup.types.WebRtcTransport; - audioProducer?: mediasoup.types.Producer; - videoProducer?: mediasoup.types.Producer; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; + webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; + webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; + audioProducer?: mediasoup.types.ProducerInterface; + videoProducer?: mediasoup.types.ProducerInterface; }; const ctx: TestContext = { @@ -975,7 +976,7 @@ test('consumer.enableTraceEvent() succeed', async () => { expect(dump1.traceEventTypes).toEqual(expect.arrayContaining(['rtp', 'pli'])); - await audioConsumer.enableTraceEvent([]); + await audioConsumer.enableTraceEvent(); const dump2 = await audioConsumer.dump(); @@ -1052,8 +1053,8 @@ test('Consumer emits "score"', async () => { rtpCapabilities: ctx.consumerDeviceCapabilities, }); - // Private API. - const channel = audioConsumer.channelForTesting; + // API not exposed in the interface. + const channel = (audioConsumer as Consumer).channelForTesting; const onScore = jest.fn(); audioConsumer.on('score', onScore); diff --git a/node/src/test/test-DataConsumer.ts b/node/src/test/test-DataConsumer.ts index f61bb8291c..7b3c91a2d0 100644 --- a/node/src/test/test-DataConsumer.ts +++ b/node/src/test/test-DataConsumer.ts @@ -5,12 +5,12 @@ import * as utils from '../utils'; type TestContext = { dataProducerOptions: mediasoup.types.DataProducerOptions; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; - webRtcTransport1?: mediasoup.types.WebRtcTransport; - webRtcTransport2?: mediasoup.types.WebRtcTransport; - directTransport?: mediasoup.types.DirectTransport; - dataProducer?: mediasoup.types.DataProducer; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; + webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; + webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; + directTransport?: mediasoup.types.DirectTransportInterface; + dataProducer?: mediasoup.types.DataProducerInterface; }; const ctx: TestContext = { diff --git a/node/src/test/test-DataProducer.ts b/node/src/test/test-DataProducer.ts index 4f490792ce..61d6394768 100644 --- a/node/src/test/test-DataProducer.ts +++ b/node/src/test/test-DataProducer.ts @@ -6,10 +6,10 @@ import * as utils from '../utils'; type TestContext = { dataProducerOptions1: mediasoup.types.DataProducerOptions; dataProducerOptions2: mediasoup.types.DataProducerOptions; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; - webRtcTransport1?: mediasoup.types.WebRtcTransport; - webRtcTransport2?: mediasoup.types.WebRtcTransport; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; + webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; + webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; }; const ctx: TestContext = { diff --git a/node/src/test/test-DirectTransport.ts b/node/src/test/test-DirectTransport.ts index e8812257b4..cb8784f3bb 100644 --- a/node/src/test/test-DirectTransport.ts +++ b/node/src/test/test-DirectTransport.ts @@ -1,10 +1,11 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, DirectTransportEvents } from '../types'; +import { DirectTransportEvents } from '../DirectTransportInterface'; +import { WorkerEvents } from '../types'; type TestContext = { - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; }; const ctx: TestContext = {}; diff --git a/node/src/test/test-PipeTransport.ts b/node/src/test/test-PipeTransport.ts index 854636ffa4..86603da30f 100644 --- a/node/src/test/test-PipeTransport.ts +++ b/node/src/test/test-PipeTransport.ts @@ -15,17 +15,17 @@ type TestContext = { videoProducerOptions: mediasoup.types.ProducerOptions; dataProducerOptions: mediasoup.types.DataProducerOptions; consumerDeviceCapabilities: mediasoup.types.RtpCapabilities; - worker1?: mediasoup.types.Worker; - worker2?: mediasoup.types.Worker; - router1?: mediasoup.types.Router; - router2?: mediasoup.types.Router; - webRtcTransport1?: mediasoup.types.WebRtcTransport; - webRtcTransport2?: mediasoup.types.WebRtcTransport; - audioProducer?: mediasoup.types.Producer; - videoProducer?: mediasoup.types.Producer; - videoConsumer?: mediasoup.types.Consumer; - dataProducer?: mediasoup.types.DataProducer; - dataConsumer?: mediasoup.types.DataConsumer; + worker1?: mediasoup.types.WorkerInterface; + worker2?: mediasoup.types.WorkerInterface; + router1?: mediasoup.types.RouterInterface; + router2?: mediasoup.types.RouterInterface; + webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; + webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; + audioProducer?: mediasoup.types.ProducerInterface; + videoProducer?: mediasoup.types.ProducerInterface; + videoConsumer?: mediasoup.types.ConsumerInterface; + dataProducer?: mediasoup.types.DataProducerInterface; + dataConsumer?: mediasoup.types.DataConsumerInterface; }; const ctx: TestContext = { @@ -221,8 +221,8 @@ test('router.pipeToRouter() succeeds with audio', async () => { producerId: ctx.audioProducer!.id, router: ctx.router2!, })) as { - pipeConsumer: mediasoup.types.Consumer; - pipeProducer: mediasoup.types.Producer; + pipeConsumer: mediasoup.types.ConsumerInterface; + pipeProducer: mediasoup.types.ProducerInterface; }; const dump1 = await ctx.router1!.dump(); @@ -336,8 +336,8 @@ test('router.pipeToRouter() succeeds with video', async () => { producerId: ctx.videoProducer!.id, router: ctx.router2!, })) as { - pipeConsumer: mediasoup.types.Consumer; - pipeProducer: mediasoup.types.Producer; + pipeConsumer: mediasoup.types.ConsumerInterface; + pipeProducer: mediasoup.types.ProducerInterface; }; const dump1 = await ctx.router1!.dump(); @@ -937,8 +937,8 @@ test('router.pipeToRouter() succeeds with data', async () => { dataProducerId: ctx.dataProducer!.id, router: ctx.router2!, })) as { - pipeDataConsumer: mediasoup.types.DataConsumer; - pipeDataProducer: mediasoup.types.DataProducer; + pipeDataConsumer: mediasoup.types.DataConsumerInterface; + pipeDataProducer: mediasoup.types.DataProducerInterface; }; const dump1 = await ctx.router1!.dump(); diff --git a/node/src/test/test-PlainTransport.ts b/node/src/test/test-PlainTransport.ts index abd7c326b9..c3c91b3b57 100644 --- a/node/src/test/test-PlainTransport.ts +++ b/node/src/test/test-PlainTransport.ts @@ -9,8 +9,8 @@ const IS_WINDOWS = os.platform() === 'win32'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; }; const ctx: TestContext = { diff --git a/node/src/test/test-Producer.ts b/node/src/test/test-Producer.ts index 661c60faf1..6587ae781c 100644 --- a/node/src/test/test-Producer.ts +++ b/node/src/test/test-Producer.ts @@ -2,6 +2,7 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents, ProducerEvents } from '../types'; +import { Producer } from '../Producer'; import { UnsupportedError } from '../errors'; import * as utils from '../utils'; import { @@ -15,10 +16,10 @@ type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; audioProducerOptions: mediasoup.types.ProducerOptions; videoProducerOptions: mediasoup.types.ProducerOptions; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; - webRtcTransport1?: mediasoup.types.WebRtcTransport; - webRtcTransport2?: mediasoup.types.WebRtcTransport; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; + webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; + webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; }; const ctx: TestContext = { @@ -680,7 +681,7 @@ test('producer.enableTraceEvent() succeed', async () => { expect(dump1.traceEventTypes).toEqual(expect.arrayContaining(['rtp', 'pli'])); - await audioProducer.enableTraceEvent([]); + await audioProducer.enableTraceEvent(); const dump2 = await audioProducer.dump(); @@ -726,8 +727,8 @@ test('Producer emits "score"', async () => { ctx.videoProducerOptions ); - // Private API. - const channel = videoProducer.channelForTesting; + // API not exposed in the interface. + const channel = (videoProducer as Producer).channelForTesting; const onScore = jest.fn(); videoProducer.on('score', onScore); diff --git a/node/src/test/test-Router.ts b/node/src/test/test-Router.ts index 615ff4176c..81804755cd 100644 --- a/node/src/test/test-Router.ts +++ b/node/src/test/test-Router.ts @@ -1,12 +1,13 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; +import { Worker } from '../Worker'; import { WorkerEvents, RouterEvents } from '../types'; import { InvalidStateError } from '../errors'; import * as utils from '../utils'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.Worker; + worker?: mediasoup.types.WorkerInterface; }; const ctx: TestContext = { @@ -94,15 +95,15 @@ test('worker.createRouter() succeeds', async () => { mapDataConsumerIdDataProducerId: {}, }); - // Private API. - expect(ctx.worker!.routersForTesting.size).toBe(1); + // API not exposed in the interface. + expect((ctx.worker! as Worker).routersForTesting.size).toBe(1); ctx.worker!.close(); expect(router.closed).toBe(true); - // Private API. - expect(ctx.worker!.routersForTesting.size).toBe(0); + // API not exposed in the interface. + expect((ctx.worker! as Worker).routersForTesting.size).toBe(0); }, 2000); test('worker.createRouter() with wrong arguments rejects with TypeError', async () => { diff --git a/node/src/test/test-WebRtcServer.ts b/node/src/test/test-WebRtcServer.ts index a6c5e8bec0..9dff5aa1df 100644 --- a/node/src/test/test-WebRtcServer.ts +++ b/node/src/test/test-WebRtcServer.ts @@ -1,11 +1,14 @@ import { pickPort } from 'pick-port'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; +import { Worker } from '../Worker'; import { WorkerEvents, WebRtcServerEvents } from '../types'; +import { WebRtcServer } from '../WebRtcServer'; +import { Router } from '../Router'; import { InvalidStateError } from '../errors'; type TestContext = { - worker?: mediasoup.types.Worker; + worker?: mediasoup.types.WorkerInterface; }; const ctx: TestContext = {}; @@ -80,15 +83,15 @@ test('worker.createWebRtcServer() succeeds', async () => { tupleHashes: [], }); - // Private API. - expect(ctx.worker!.webRtcServersForTesting.size).toBe(1); + // API not exposed in the interface. + expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(1); ctx.worker!.close(); expect(webRtcServer.closed).toBe(true); - // Private API. - expect(ctx.worker!.webRtcServersForTesting.size).toBe(0); + // API not exposed in the interface. + expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(0); }, 2000); test('worker.createWebRtcServer() with portRange succeeds', async () => { @@ -149,15 +152,15 @@ test('worker.createWebRtcServer() with portRange succeeds', async () => { tupleHashes: [], }); - // Private API. - expect(ctx.worker!.webRtcServersForTesting.size).toBe(1); + // API not exposed in the interface. + expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(1); ctx.worker!.close(); expect(webRtcServer.closed).toBe(true); - // Private API. - expect(ctx.worker!.webRtcServersForTesting.size).toBe(0); + // API not exposed in the interface. + expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(0); }, 2000); test('worker.createWebRtcServer() without specifying port/portRange succeeds', async () => { @@ -205,15 +208,15 @@ test('worker.createWebRtcServer() without specifying port/portRange succeeds', a tupleHashes: [], }); - // Private API. - expect(ctx.worker!.webRtcServersForTesting.size).toBe(1); + // API not exposed in the interface. + expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(1); ctx.worker!.close(); expect(webRtcServer.closed).toBe(true); - // Private API. - expect(ctx.worker!.webRtcServersForTesting.size).toBe(0); + // API not exposed in the interface. + expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(0); }, 2000); test('worker.createWebRtcServer() with wrong arguments rejects with TypeError', async () => { @@ -435,8 +438,12 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is expect(transport.iceState).toBe('new'); expect(transport.iceSelectedTuple).toBeUndefined(); - expect(webRtcServer.webRtcTransportsForTesting.size).toBe(1); - expect(router.transportsForTesting.size).toBe(1); + // API not exposed in the interface. + expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( + 1 + ); + // API not exposed in the interface. + expect((router as Router).transportsForTesting.size).toBe(1); await expect(webRtcServer.dump()).resolves.toMatchObject({ id: webRtcServer.id, @@ -454,8 +461,12 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is expect(transport.closed).toBe(true); expect(onObserverWebRtcTransportUnhandled).toHaveBeenCalledTimes(1); expect(onObserverWebRtcTransportUnhandled).toHaveBeenCalledWith(transport); - expect(webRtcServer.webRtcTransportsForTesting.size).toBe(0); - expect(router.transportsForTesting.size).toBe(0); + // API not exposed in the interface. + expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( + 0 + ); + // API not exposed in the interface. + expect((router as Router).transportsForTesting.size).toBe(0); await expect(webRtcServer.dump()).resolves.toMatchObject({ id: webRtcServer.id, @@ -531,8 +542,12 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and webRtcServer expect(transport.iceState).toBe('new'); expect(transport.iceSelectedTuple).toBeUndefined(); - expect(webRtcServer.webRtcTransportsForTesting.size).toBe(1); - expect(router.transportsForTesting.size).toBe(1); + // API not exposed in the interface. + expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( + 1 + ); + // API not exposed in the interface. + expect((router as Router).transportsForTesting.size).toBe(1); await expect(webRtcServer.dump()).resolves.toMatchObject({ id: webRtcServer.id, @@ -581,8 +596,12 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and webRtcServer expect(transport.iceSelectedTuple).toBe(undefined); expect(transport.dtlsState).toBe('closed'); expect(transport.sctpState).toBe(undefined); - expect(webRtcServer.webRtcTransportsForTesting.size).toBe(0); - expect(router.transportsForTesting.size).toBe(0); + // API not exposed in the interface. + expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( + 0 + ); + // API not exposed in the interface. + expect((router as Router).transportsForTesting.size).toBe(0); await expect(ctx.worker!.dump()).resolves.toMatchObject({ pid: ctx.worker!.pid, diff --git a/node/src/test/test-WebRtcTransport.ts b/node/src/test/test-WebRtcTransport.ts index 400f25c11e..f43849f8a8 100644 --- a/node/src/test/test-WebRtcTransport.ts +++ b/node/src/test/test-WebRtcTransport.ts @@ -3,8 +3,10 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents, WebRtcTransportEvents } from '../types'; +import { WebRtcTransport } from '../WebRtcTransport'; +import { TransportTuple } from '../TransportInterface'; +import { serializeProtocol } from '../Transport'; import * as utils from '../utils'; -import { serializeProtocol, TransportTuple } from '../Transport'; import { Notification, Body as NotificationBody, @@ -15,8 +17,8 @@ import * as FbsWebRtcTransport from '../fbs/web-rtc-transport'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; }; const ctx: TestContext = { @@ -620,7 +622,7 @@ test('transport.enableTraceEvent() succeed', async () => { traceEventTypes: ['probation'], }); - await webRtcTransport.enableTraceEvent([]); + await webRtcTransport.enableTraceEvent(); await expect(webRtcTransport.dump()).resolves.toMatchObject({ traceEventTypes: [], }); @@ -667,8 +669,8 @@ test('WebRtcTransport events succeed', async () => { ], }); - // Private API. - const channel = webRtcTransport.channelForTesting; + // API not exposed in the interface. + const channel = (webRtcTransport as WebRtcTransport).channelForTesting; const onIceStateChange = jest.fn(); webRtcTransport.on('icestatechange', onIceStateChange); diff --git a/node/src/test/test-multiopus.ts b/node/src/test/test-multiopus.ts index 4b8ab50450..22b9484cc0 100644 --- a/node/src/test/test-multiopus.ts +++ b/node/src/test/test-multiopus.ts @@ -8,9 +8,9 @@ type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; audioProducerOptions: mediasoup.types.ProducerOptions; consumerDeviceCapabilities: mediasoup.types.RtpCapabilities; - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; - webRtcTransport?: mediasoup.types.WebRtcTransport; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; + webRtcTransport?: mediasoup.types.WebRtcTransportInterface; }; const ctx: TestContext = { diff --git a/node/src/test/test-node-sctp.ts b/node/src/test/test-node-sctp.ts index e344c1a484..cb4fb14f64 100644 --- a/node/src/test/test-node-sctp.ts +++ b/node/src/test/test-node-sctp.ts @@ -6,11 +6,11 @@ import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents } from '../types'; type TestContext = { - worker?: mediasoup.types.Worker; - router?: mediasoup.types.Router; - plainTransport?: mediasoup.types.PlainTransport; - dataProducer?: mediasoup.types.DataProducer; - dataConsumer?: mediasoup.types.DataConsumer; + worker?: mediasoup.types.WorkerInterface; + router?: mediasoup.types.RouterInterface; + plainTransport?: mediasoup.types.PlainTransportInterface; + dataProducer?: mediasoup.types.DataProducerInterface; + dataConsumer?: mediasoup.types.DataConsumerInterface; udpSocket?: dgram.Socket; sctpSocket?: any; sctpSendStreamId?: number; diff --git a/node/src/types.ts b/node/src/types.ts index 14c9e4a0c1..cfe07698fb 100644 --- a/node/src/types.ts +++ b/node/src/types.ts @@ -4,27 +4,23 @@ export type * from './SctpParameters'; export type * from './SrtpParameters'; export type * from './scalabilityModes'; -export * from './Worker'; -export * from './WebRtcServer'; -export * from './Router'; -export * from './Transport'; -export * from './WebRtcTransport'; -export * from './PlainTransport'; -export * from './PipeTransport'; -export * from './DirectTransport'; -export * from './Producer'; -export * from './Consumer'; -export * from './DataProducer'; -export * from './DataConsumer'; -export * from './RtpObserver'; -export * from './ActiveSpeakerObserver'; -export * from './AudioLevelObserver'; +export * from './WorkerInterface'; +export * from './WebRtcServerInterface'; +export * from './RouterInterface'; +export * from './TransportInterface'; +export * from './WebRtcTransportInterface'; +export * from './PlainTransportInterface'; +export * from './PipeTransportInterface'; +export * from './DirectTransportInterface'; +export * from './ProducerInterface'; +export * from './ConsumerInterface'; +export * from './DataProducerInterface'; +export * from './DataConsumerInterface'; +export * from './RtpObserverInterface'; +export * from './ActiveSpeakerObserverInterface'; +export * from './AudioLevelObserverInterface'; export * from './errors'; -export type AppData = { - [key: string]: unknown; -}; - type Only = { [P in keyof T]: T[P]; } & { @@ -32,3 +28,7 @@ type Only = { }; export type Either = Only | Only; + +export type AppData = { + [key: string]: unknown; +}; diff --git a/node/src/utils.ts b/node/src/utils.ts index f7c8e8c8b9..c6e1d9748d 100644 --- a/node/src/utils.ts +++ b/node/src/utils.ts @@ -1,5 +1,5 @@ import { randomUUID, randomInt } from 'node:crypto'; -import { ProducerType } from './Producer'; +import { ProducerType } from './ProducerInterface'; import { Type as FbsRtpParametersType } from './fbs/rtp-parameters'; /** From 0a203d0f59e53611bb9ceb5216e5286853dbfb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 8 Nov 2024 18:16:03 +0100 Subject: [PATCH 02/14] rename xxxInterface.ts to xxxTypes.ts and suffix classes with "Impl" --- node/src/ActiveSpeakerObserver.ts | 10 ++-- ...rface.ts => ActiveSpeakerObserverTypes.ts} | 4 +- node/src/AudioLevelObserver.ts | 12 ++--- ...nterface.ts => AudioLevelObserverTypes.ts} | 4 +- node/src/Consumer.ts | 6 +-- ...{ConsumerInterface.ts => ConsumerTypes.ts} | 2 +- node/src/DataConsumer.ts | 4 +- ...sumerInterface.ts => DataConsumerTypes.ts} | 0 node/src/DataProducer.ts | 4 +- ...ducerInterface.ts => DataProducerTypes.ts} | 0 node/src/DirectTransport.ts | 12 +++-- ...rtInterface.ts => DirectTransportTypes.ts} | 2 +- node/src/PipeTransport.ts | 16 +++--- ...portInterface.ts => PipeTransportTypes.ts} | 4 +- node/src/PlainTransport.ts | 10 ++-- ...ortInterface.ts => PlainTransportTypes.ts} | 2 +- node/src/Producer.ts | 4 +- ...{ProducerInterface.ts => ProducerTypes.ts} | 0 node/src/Router.ts | 48 +++++++++--------- .../{RouterInterface.ts => RouterTypes.ts} | 24 ++++----- node/src/RtpObserver.ts | 6 +-- ...serverInterface.ts => RtpObserverTypes.ts} | 2 +- node/src/Transport.ts | 32 ++++++------ ...ransportInterface.ts => TransportTypes.ts} | 8 +-- node/src/WebRtcServer.ts | 6 +-- ...erverInterface.ts => WebRtcServerTypes.ts} | 4 +- node/src/WebRtcTransport.ts | 12 +++-- ...rtInterface.ts => WebRtcTransportTypes.ts} | 4 +- node/src/Worker.ts | 16 +++--- .../{WorkerInterface.ts => WorkerTypes.ts} | 4 +- node/src/index.ts | 6 +-- node/src/test/test-Consumer.ts | 4 +- node/src/test/test-DirectTransport.ts | 2 +- node/src/test/test-Producer.ts | 4 +- node/src/test/test-Router.ts | 6 +-- node/src/test/test-WebRtcServer.ts | 50 +++++++++---------- node/src/test/test-WebRtcTransport.ts | 6 +-- node/src/types.ts | 32 ++++++------ node/src/utils.ts | 2 +- 39 files changed, 192 insertions(+), 182 deletions(-) rename node/src/{ActiveSpeakerObserverInterface.ts => ActiveSpeakerObserverTypes.ts} (92%) rename node/src/{AudioLevelObserverInterface.ts => AudioLevelObserverTypes.ts} (94%) rename node/src/{ConsumerInterface.ts => ConsumerTypes.ts} (99%) rename node/src/{DataConsumerInterface.ts => DataConsumerTypes.ts} (100%) rename node/src/{DataProducerInterface.ts => DataProducerTypes.ts} (100%) rename node/src/{DirectTransportInterface.ts => DirectTransportTypes.ts} (97%) rename node/src/{PipeTransportInterface.ts => PipeTransportTypes.ts} (97%) rename node/src/{PlainTransportInterface.ts => PlainTransportTypes.ts} (99%) rename node/src/{ProducerInterface.ts => ProducerTypes.ts} (100%) rename node/src/{RouterInterface.ts => RouterTypes.ts} (90%) rename node/src/{RtpObserverInterface.ts => RtpObserverTypes.ts} (95%) rename node/src/{TransportInterface.ts => TransportTypes.ts} (96%) rename node/src/{WebRtcServerInterface.ts => WebRtcServerTypes.ts} (93%) rename node/src/{WebRtcTransportInterface.ts => WebRtcTransportTypes.ts} (98%) rename node/src/{WorkerInterface.ts => WorkerTypes.ts} (97%) diff --git a/node/src/ActiveSpeakerObserver.ts b/node/src/ActiveSpeakerObserver.ts index 10f6875057..6ff31dcaac 100644 --- a/node/src/ActiveSpeakerObserver.ts +++ b/node/src/ActiveSpeakerObserver.ts @@ -6,9 +6,9 @@ import { ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver, ActiveSpeakerObserverObserverEvents, -} from './ActiveSpeakerObserverInterface'; -import { RtpObserverInterface } from './RtpObserverInterface'; -import { RtpObserver, RtpObserverConstructorOptions } from './RtpObserver'; +} from './ActiveSpeakerObserverTypes'; +import { RtpObserverInterface } from './RtpObserverTypes'; +import { RtpObserverImpl, RtpObserverConstructorOptions } from './RtpObserver'; import { AppData } from './types'; import { Event, Notification } from './fbs/notification'; import * as FbsActiveSpeakerObserver from './fbs/active-speaker-observer'; @@ -18,10 +18,10 @@ type RtpObserverObserverConstructorOptions = const logger = new Logger('ActiveSpeakerObserver'); -export class ActiveSpeakerObserver< +export class ActiveSpeakerObserverImpl< ActiveSpeakerObserverAppData extends AppData = AppData, > - extends RtpObserver< + extends RtpObserverImpl< ActiveSpeakerObserverAppData, ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver diff --git a/node/src/ActiveSpeakerObserverInterface.ts b/node/src/ActiveSpeakerObserverTypes.ts similarity index 92% rename from node/src/ActiveSpeakerObserverInterface.ts rename to node/src/ActiveSpeakerObserverTypes.ts index 3e8bd0e3d9..b436c2ecdb 100644 --- a/node/src/ActiveSpeakerObserverInterface.ts +++ b/node/src/ActiveSpeakerObserverTypes.ts @@ -3,8 +3,8 @@ import { RtpObserverInterface, RtpObserverEvents, RtpObserverObserverEvents, -} from './RtpObserverInterface'; -import { ProducerInterface } from './ProducerInterface'; +} from './RtpObserverTypes'; +import { ProducerInterface } from './ProducerTypes'; import { AppData } from './types'; export type ActiveSpeakerObserverOptions< diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index bea9bb8a02..a3f09b6133 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -6,10 +6,10 @@ import { AudioLevelObserverEvents, AudioLevelObserverObserver, AudioLevelObserverObserverEvents, -} from './AudioLevelObserverInterface'; -import { RtpObserverInterface } from './RtpObserverInterface'; -import { RtpObserver, RtpObserverConstructorOptions } from './RtpObserver'; -import { ProducerInterface } from './ProducerInterface'; +} from './AudioLevelObserverTypes'; +import { RtpObserverInterface } from './RtpObserverTypes'; +import { RtpObserverImpl, RtpObserverConstructorOptions } from './RtpObserver'; +import { ProducerInterface } from './ProducerTypes'; import { AppData } from './types'; import * as utils from './utils'; import { Event, Notification } from './fbs/notification'; @@ -20,10 +20,10 @@ type AudioLevelObserverConstructorOptions = const logger = new Logger('AudioLevelObserver'); -export class AudioLevelObserver< +export class AudioLevelObserverImpl< AudioLevelObserverAppData extends AppData = AppData, > - extends RtpObserver< + extends RtpObserverImpl< AudioLevelObserverAppData, AudioLevelObserverEvents, AudioLevelObserverObserver diff --git a/node/src/AudioLevelObserverInterface.ts b/node/src/AudioLevelObserverTypes.ts similarity index 94% rename from node/src/AudioLevelObserverInterface.ts rename to node/src/AudioLevelObserverTypes.ts index ce808b39b6..9979adaf8e 100644 --- a/node/src/AudioLevelObserverInterface.ts +++ b/node/src/AudioLevelObserverTypes.ts @@ -3,8 +3,8 @@ import { RtpObserverInterface, RtpObserverEvents, RtpObserverObserverEvents, -} from './RtpObserverInterface'; -import { ProducerInterface } from './ProducerInterface'; +} from './RtpObserverTypes'; +import { ProducerInterface } from './ProducerTypes'; import { AppData } from './types'; export type AudioLevelObserverOptions< diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index 31bb0d0736..a47c43bbb3 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -21,10 +21,10 @@ import { ConsumerEvents, ConsumerObserver, ConsumerObserverEvents, -} from './ConsumerInterface'; +} from './ConsumerTypes'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; -import { ProducerStat } from './ProducerInterface'; +import { ProducerStat } from './ProducerTypes'; import { MediaKind, RtpParameters, @@ -58,7 +58,7 @@ type ConsumerData = { const logger = new Logger('Consumer'); -export class Consumer +export class ConsumerImpl extends EnhancedEventEmitter implements ConsumerInterface { diff --git a/node/src/ConsumerInterface.ts b/node/src/ConsumerTypes.ts similarity index 99% rename from node/src/ConsumerInterface.ts rename to node/src/ConsumerTypes.ts index 2bd9ef9486..9a611ce89a 100644 --- a/node/src/ConsumerInterface.ts +++ b/node/src/ConsumerTypes.ts @@ -1,5 +1,5 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { ProducerStat } from './ProducerInterface'; +import { ProducerStat } from './ProducerTypes'; import { MediaKind, RtpCapabilities, diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index 256232b7e9..040cc4dd03 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -8,7 +8,7 @@ import { DataConsumerEvents, DataConsumerObserver, DataConsumerObserverEvents, -} from './DataConsumerInterface'; +} from './DataConsumerTypes'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; import { @@ -38,7 +38,7 @@ type DataConsumerData = { const logger = new Logger('DataConsumer'); -export class DataConsumer +export class DataConsumerImpl extends EnhancedEventEmitter implements DataConsumerInterface { diff --git a/node/src/DataConsumerInterface.ts b/node/src/DataConsumerTypes.ts similarity index 100% rename from node/src/DataConsumerInterface.ts rename to node/src/DataConsumerTypes.ts diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index 3a5df11969..95a681f854 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -8,7 +8,7 @@ import { DataProducerEvents, DataProducerObserver, DataProducerObserverEvents, -} from './DataProducerInterface'; +} from './DataProducerTypes'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; import { @@ -34,7 +34,7 @@ type DataProducerData = { const logger = new Logger('DataProducer'); -export class DataProducer +export class DataProducerImpl extends EnhancedEventEmitter implements DataProducerInterface { diff --git a/node/src/DataProducerInterface.ts b/node/src/DataProducerTypes.ts similarity index 100% rename from node/src/DataProducerInterface.ts rename to node/src/DataProducerTypes.ts diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index db4616bf48..e5d65ed8ef 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -7,10 +7,10 @@ import { DirectTransportEvents, DirectTransportObserver, DirectTransportObserverEvents, -} from './DirectTransportInterface'; -import { TransportInterface, BaseTransportDump } from './TransportInterface'; +} from './DirectTransportTypes'; +import { TransportInterface, BaseTransportDump } from './TransportTypes'; import { - Transport, + TransportImpl, TransportConstructorOptions, parseBaseTransportDump, parseBaseTransportStats, @@ -36,8 +36,10 @@ export type DirectTransportData = { const logger = new Logger('DirectTransport'); -export class DirectTransport - extends Transport< +export class DirectTransportImpl< + DirectTransportAppData extends AppData = AppData, + > + extends TransportImpl< DirectTransportAppData, DirectTransportEvents, DirectTransportObserver diff --git a/node/src/DirectTransportInterface.ts b/node/src/DirectTransportTypes.ts similarity index 97% rename from node/src/DirectTransportInterface.ts rename to node/src/DirectTransportTypes.ts index 8bfcb29153..8b77198a75 100644 --- a/node/src/DirectTransportInterface.ts +++ b/node/src/DirectTransportTypes.ts @@ -5,7 +5,7 @@ import { BaseTransportStats, TransportEvents, TransportObserverEvents, -} from './TransportInterface'; +} from './TransportTypes'; import { AppData } from './types'; export type DirectTransportOptions< diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index 2a0526c5b7..afbfad450c 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -10,14 +10,14 @@ import { PipeTransportEvents, PipeTransportObserver, PipeTransportObserverEvents, -} from './PipeTransportInterface'; +} from './PipeTransportTypes'; import { TransportInterface, TransportTuple, SctpState, -} from './TransportInterface'; +} from './TransportTypes'; import { - Transport, + TransportImpl, TransportConstructorOptions, parseBaseTransportDump, parseBaseTransportStats, @@ -25,9 +25,9 @@ import { parseTuple, parseTransportTraceEventData, } from './Transport'; -import { ProducerInterface } from './ProducerInterface'; -import { ConsumerInterface, ConsumerType } from './ConsumerInterface'; -import { Consumer } from './Consumer'; +import { ProducerInterface } from './ProducerTypes'; +import { ConsumerInterface, ConsumerType } from './ConsumerTypes'; +import { ConsumerImpl } from './Consumer'; import { RtpParameters, serializeRtpEncodingParameters, @@ -64,7 +64,7 @@ export type PipeTransportData = { const logger = new Logger('PipeTransport'); export class PipeTransport - extends Transport< + extends TransportImpl< PipeTransportAppData, PipeTransportEvents, PipeTransportObserver @@ -317,7 +317,7 @@ export class PipeTransport type: 'pipe' as ConsumerType, }; - const consumer: ConsumerInterface = new Consumer({ + const consumer: ConsumerInterface = new ConsumerImpl({ internal: { ...this.internal, consumerId, diff --git a/node/src/PipeTransportInterface.ts b/node/src/PipeTransportTypes.ts similarity index 97% rename from node/src/PipeTransportInterface.ts rename to node/src/PipeTransportTypes.ts index c690ecae6e..593923c88e 100644 --- a/node/src/PipeTransportInterface.ts +++ b/node/src/PipeTransportTypes.ts @@ -9,8 +9,8 @@ import { BaseTransportStats, TransportEvents, TransportObserverEvents, -} from './TransportInterface'; -import { ConsumerInterface } from './ConsumerInterface'; +} from './TransportTypes'; +import { ConsumerInterface } from './ConsumerTypes'; import { SrtpParameters } from './SrtpParameters'; import { SctpParameters, NumSctpStreams } from './SctpParameters'; import { Either, AppData } from './types'; diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index 8776132f24..0d55164252 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -8,14 +8,14 @@ import { PlainTransportEvents, PlainTransportObserver, PlainTransportObserverEvents, -} from './PlainTransportInterface'; +} from './PlainTransportTypes'; import { TransportInterface, TransportTuple, SctpState, -} from './TransportInterface'; +} from './TransportTypes'; import { - Transport, + TransportImpl, TransportConstructorOptions, parseSctpState, parseTuple, @@ -52,8 +52,8 @@ export type PlainTransportData = { const logger = new Logger('PlainTransport'); -export class PlainTransport - extends Transport< +export class PlainTransportImpl + extends TransportImpl< PlainTransportAppData, PlainTransportEvents, PlainTransportObserver diff --git a/node/src/PlainTransportInterface.ts b/node/src/PlainTransportTypes.ts similarity index 99% rename from node/src/PlainTransportInterface.ts rename to node/src/PlainTransportTypes.ts index 595930debf..eeebd2c682 100644 --- a/node/src/PlainTransportInterface.ts +++ b/node/src/PlainTransportTypes.ts @@ -9,7 +9,7 @@ import { BaseTransportStats, TransportEvents, TransportObserverEvents, -} from './TransportInterface'; +} from './TransportTypes'; import { SrtpParameters, SrtpCryptoSuite } from './SrtpParameters'; import { SctpParameters, NumSctpStreams } from './SctpParameters'; import { Either, AppData } from './types'; diff --git a/node/src/Producer.ts b/node/src/Producer.ts index 673cd32c43..0ba9dc39c8 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -12,7 +12,7 @@ import { ProducerEvents, ProducerObserver, ProducerObserverEvents, -} from './ProducerInterface'; +} from './ProducerTypes'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; import { MediaKind, RtpParameters, parseRtpParameters } from './RtpParameters'; @@ -41,7 +41,7 @@ type ProducerData = { consumableRtpParameters: RtpParameters; }; -export class Producer +export class ProducerImpl extends EnhancedEventEmitter implements ProducerInterface { diff --git a/node/src/ProducerInterface.ts b/node/src/ProducerTypes.ts similarity index 100% rename from node/src/ProducerInterface.ts rename to node/src/ProducerTypes.ts diff --git a/node/src/Router.ts b/node/src/Router.ts index ce3bab5239..8fe8c8031c 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -12,57 +12,57 @@ import { RouterEvents, RouterObserver, RouterObserverEvents, -} from './RouterInterface'; +} from './RouterTypes'; import { TransportInterface, TransportListenIp, TransportProtocol, -} from './TransportInterface'; +} from './TransportTypes'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; import { WebRtcTransportInterface, WebRtcTransportOptions, -} from './WebRtcTransportInterface'; +} from './WebRtcTransportTypes'; import { - WebRtcTransport, + WebRtcTransportImpl, parseWebRtcTransportDumpResponse, } from './WebRtcTransport'; import { PlainTransportInterface, PlainTransportOptions, -} from './PlainTransportInterface'; +} from './PlainTransportTypes'; import { - PlainTransport, + PlainTransportImpl, parsePlainTransportDumpResponse, } from './PlainTransport'; import { PipeTransportInterface, PipeTransportOptions, -} from './PipeTransportInterface'; +} from './PipeTransportTypes'; import { PipeTransport, parsePipeTransportDumpResponse } from './PipeTransport'; import { DirectTransportInterface, DirectTransportOptions, -} from './DirectTransportInterface'; +} from './DirectTransportTypes'; import { - DirectTransport, + DirectTransportImpl, parseDirectTransportDumpResponse, } from './DirectTransport'; -import { ProducerInterface } from './ProducerInterface'; -import { ConsumerInterface } from './ConsumerInterface'; -import { DataProducerInterface } from './DataProducerInterface'; -import { DataConsumerInterface } from './DataConsumerInterface'; -import { RtpObserverInterface } from './RtpObserverInterface'; +import { ProducerInterface } from './ProducerTypes'; +import { ConsumerInterface } from './ConsumerTypes'; +import { DataProducerInterface } from './DataProducerTypes'; +import { DataConsumerInterface } from './DataConsumerTypes'; +import { RtpObserverInterface } from './RtpObserverTypes'; import { ActiveSpeakerObserverInterface, ActiveSpeakerObserverOptions, -} from './ActiveSpeakerObserverInterface'; -import { ActiveSpeakerObserver } from './ActiveSpeakerObserver'; +} from './ActiveSpeakerObserverTypes'; +import { ActiveSpeakerObserverImpl } from './ActiveSpeakerObserver'; import { AudioLevelObserverInterface, AudioLevelObserverOptions, -} from './AudioLevelObserverInterface'; -import { AudioLevelObserver } from './AudioLevelObserver'; +} from './AudioLevelObserverTypes'; +import { AudioLevelObserverImpl } from './AudioLevelObserver'; import { RtpCapabilities } from './RtpParameters'; import { cryptoSuiteToFbs } from './SrtpParameters'; import { AppData } from './types'; @@ -96,7 +96,7 @@ type RouterData = { const logger = new Logger('Router'); -export class Router +export class RouterImpl extends EnhancedEventEmitter implements RouterInterface { @@ -509,7 +509,7 @@ export class Router const webRtcTransportData = parseWebRtcTransportDumpResponse(data); const transport: WebRtcTransportInterface = - new WebRtcTransport({ + new WebRtcTransportImpl({ internal: { ...this.#internal, transportId: transportId, @@ -682,7 +682,7 @@ export class Router const plainTransportData = parsePlainTransportDumpResponse(data); const transport: PlainTransportInterface = - new PlainTransport({ + new PlainTransportImpl({ internal: { ...this.#internal, transportId: transportId, @@ -921,7 +921,7 @@ export class Router const directTransportData = parseDirectTransportDumpResponse(data); const transport: DirectTransportInterface = - new DirectTransport({ + new DirectTransportImpl({ internal: { ...this.#internal, transportId: transportId, @@ -1301,7 +1301,7 @@ export class Router ); const activeSpeakerObserver: ActiveSpeakerObserverInterface = - new ActiveSpeakerObserver({ + new ActiveSpeakerObserverImpl({ internal: { ...this.#internal, rtpObserverId: rtpObserverId, @@ -1377,7 +1377,7 @@ export class Router ); const audioLevelObserver: AudioLevelObserverInterface = - new AudioLevelObserver({ + new AudioLevelObserverImpl({ internal: { ...this.#internal, rtpObserverId: rtpObserverId, diff --git a/node/src/RouterInterface.ts b/node/src/RouterTypes.ts similarity index 90% rename from node/src/RouterInterface.ts rename to node/src/RouterTypes.ts index a3e2a10498..c0f12abd87 100644 --- a/node/src/RouterInterface.ts +++ b/node/src/RouterTypes.ts @@ -3,36 +3,36 @@ import { TransportInterface, TransportListenInfo, TransportListenIp, -} from './TransportInterface'; +} from './TransportTypes'; import { WebRtcTransportInterface, WebRtcTransportOptions, -} from './WebRtcTransportInterface'; +} from './WebRtcTransportTypes'; import { PlainTransportInterface, PlainTransportOptions, -} from './PlainTransportInterface'; +} from './PlainTransportTypes'; import { PipeTransportInterface, PipeTransportOptions, -} from './PipeTransportInterface'; +} from './PipeTransportTypes'; import { DirectTransportInterface, DirectTransportOptions, -} from './DirectTransportInterface'; -import { ProducerInterface } from './ProducerInterface'; -import { ConsumerInterface } from './ConsumerInterface'; -import { DataProducerInterface } from './DataProducerInterface'; -import { DataConsumerInterface } from './DataConsumerInterface'; -import { RtpObserverInterface } from './RtpObserverInterface'; +} from './DirectTransportTypes'; +import { ProducerInterface } from './ProducerTypes'; +import { ConsumerInterface } from './ConsumerTypes'; +import { DataProducerInterface } from './DataProducerTypes'; +import { DataConsumerInterface } from './DataConsumerTypes'; +import { RtpObserverInterface } from './RtpObserverTypes'; import { ActiveSpeakerObserverInterface, ActiveSpeakerObserverOptions, -} from './ActiveSpeakerObserverInterface'; +} from './ActiveSpeakerObserverTypes'; import { AudioLevelObserverInterface, AudioLevelObserverOptions, -} from './AudioLevelObserverInterface'; +} from './AudioLevelObserverTypes'; import { RtpCapabilities, RtpCodecCapability } from './RtpParameters'; import { NumSctpStreams } from './SctpParameters'; import { Either, AppData } from './types'; diff --git a/node/src/RtpObserver.ts b/node/src/RtpObserver.ts index ba07f2af3d..b277b07d31 100644 --- a/node/src/RtpObserver.ts +++ b/node/src/RtpObserver.ts @@ -1,9 +1,9 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { RtpObserverEvents, RtpObserverObserver } from './RtpObserverInterface'; +import { RtpObserverEvents, RtpObserverObserver } from './RtpObserverTypes'; import { Channel } from './Channel'; import { RouterInternal } from './Router'; -import { ProducerInterface } from './ProducerInterface'; +import { ProducerInterface } from './ProducerTypes'; import { AppData } from './types'; import * as FbsRequest from './fbs/request'; import * as FbsRouter from './fbs/router'; @@ -22,7 +22,7 @@ type RtpObserverObserverInternal = RouterInternal & { const logger = new Logger('RtpObserver'); -export abstract class RtpObserver< +export abstract class RtpObserverImpl< RtpObserverAppData extends AppData = AppData, Events extends RtpObserverEvents = RtpObserverEvents, Observer extends RtpObserverObserver = RtpObserverObserver, diff --git a/node/src/RtpObserverInterface.ts b/node/src/RtpObserverTypes.ts similarity index 95% rename from node/src/RtpObserverInterface.ts rename to node/src/RtpObserverTypes.ts index 8f047bcf1c..52c7c81329 100644 --- a/node/src/RtpObserverInterface.ts +++ b/node/src/RtpObserverTypes.ts @@ -1,5 +1,5 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { ProducerInterface } from './ProducerInterface'; +import { ProducerInterface } from './ProducerTypes'; import { AppData } from './types'; export type RtpObserverEvents = { diff --git a/node/src/Transport.ts b/node/src/Transport.ts index 2794ad6665..4ff00de575 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -18,29 +18,33 @@ import { TransportTraceEventData, TransportEvents, TransportObserver, -} from './TransportInterface'; +} from './TransportTypes'; import { Channel } from './Channel'; import { RouterInternal } from './Router'; import { WebRtcTransportData } from './WebRtcTransport'; import { PlainTransportData } from './PlainTransport'; import { PipeTransportData } from './PipeTransport'; import { DirectTransportData } from './DirectTransport'; -import { ProducerInterface, ProducerOptions } from './ProducerInterface'; -import { Producer, producerTypeFromFbs, producerTypeToFbs } from './Producer'; +import { ProducerInterface, ProducerOptions } from './ProducerTypes'; +import { + ProducerImpl, + producerTypeFromFbs, + producerTypeToFbs, +} from './Producer'; import { ConsumerInterface, ConsumerOptions, ConsumerType, ConsumerLayers, -} from './ConsumerInterface'; -import { Consumer } from './Consumer'; +} from './ConsumerTypes'; +import { ConsumerImpl } from './Consumer'; import { DataProducerInterface, DataProducerOptions, DataProducerType, -} from './DataProducerInterface'; +} from './DataProducerTypes'; import { - DataProducer, + DataProducerImpl, dataProducerTypeToFbs, parseDataProducerDumpResponse, } from './DataProducer'; @@ -48,9 +52,9 @@ import { DataConsumerInterface, DataConsumerOptions, DataConsumerType, -} from './DataConsumerInterface'; +} from './DataConsumerTypes'; import { - DataConsumer, + DataConsumerImpl, dataConsumerTypeToFbs, parseDataConsumerDumpResponse, } from './DataConsumer'; @@ -104,7 +108,7 @@ type TransportData = const logger = new Logger('Transport'); -export abstract class Transport< +export abstract class TransportImpl< TransportAppData extends AppData = AppData, Events extends TransportEvents = TransportEvents, Observer extends TransportObserver = TransportObserver, @@ -617,7 +621,7 @@ export abstract class Transport< consumableRtpParameters, }; - const producer: ProducerInterface = new Producer({ + const producer: ProducerInterface = new ProducerImpl({ internal: { ...this.internal, producerId, @@ -746,7 +750,7 @@ export abstract class Transport< type: pipe ? 'pipe' : (producer.type as ConsumerType), }; - const consumer: ConsumerInterface = new Consumer({ + const consumer: ConsumerInterface = new ConsumerImpl({ internal: { ...this.internal, consumerId, @@ -849,7 +853,7 @@ export abstract class Transport< const dump = parseDataProducerDumpResponse(produceDataResponse); const dataProducer: DataProducerInterface = - new DataProducer({ + new DataProducerImpl({ internal: { ...this.internal, dataProducerId, @@ -985,7 +989,7 @@ export abstract class Transport< const dump = parseDataConsumerDumpResponse(consumeDataResponse); const dataConsumer: DataConsumerInterface = - new DataConsumer({ + new DataConsumerImpl({ internal: { ...this.internal, dataConsumerId, diff --git a/node/src/TransportInterface.ts b/node/src/TransportTypes.ts similarity index 96% rename from node/src/TransportInterface.ts rename to node/src/TransportTypes.ts index 65cb0b1616..73c606d793 100644 --- a/node/src/TransportInterface.ts +++ b/node/src/TransportTypes.ts @@ -1,14 +1,14 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { ProducerInterface, ProducerOptions } from './ProducerInterface'; -import { ConsumerInterface, ConsumerOptions } from './ConsumerInterface'; +import { ProducerInterface, ProducerOptions } from './ProducerTypes'; +import { ConsumerInterface, ConsumerOptions } from './ConsumerTypes'; import { DataProducerInterface, DataProducerOptions, -} from './DataProducerInterface'; +} from './DataProducerTypes'; import { DataConsumerInterface, DataConsumerOptions, -} from './DataConsumerInterface'; +} from './DataConsumerTypes'; import { SctpParameters } from './SctpParameters'; import { AppData } from './types'; diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index 1822492171..c516b7fa29 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -10,8 +10,8 @@ import { WebRtcServerEvents, WebRtcServerObserver, WebRtcServerObserverEvents, -} from './WebRtcServerInterface'; -import { WebRtcTransportInterface } from './WebRtcTransportInterface'; +} from './WebRtcServerTypes'; +import { WebRtcTransportInterface } from './WebRtcTransportTypes'; import { AppData } from './types'; import * as utils from './utils'; import { Body as RequestBody, Method } from './fbs/request'; @@ -24,7 +24,7 @@ type WebRtcServerInternal = { const logger = new Logger('WebRtcServer'); -export class WebRtcServer +export class WebRtcServerImpl extends EnhancedEventEmitter implements WebRtcServerInterface { diff --git a/node/src/WebRtcServerInterface.ts b/node/src/WebRtcServerTypes.ts similarity index 93% rename from node/src/WebRtcServerInterface.ts rename to node/src/WebRtcServerTypes.ts index fc3b527b27..5dbcaeb207 100644 --- a/node/src/WebRtcServerInterface.ts +++ b/node/src/WebRtcServerTypes.ts @@ -1,6 +1,6 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { TransportListenInfo } from './TransportInterface'; -import { WebRtcTransportInterface } from './WebRtcTransportInterface'; +import { TransportListenInfo } from './TransportTypes'; +import { WebRtcTransportInterface } from './WebRtcTransportTypes'; import { AppData } from './types'; export type WebRtcServerOptions = diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index 14a4fde516..3a444cf665 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -19,14 +19,14 @@ import { WebRtcTransportEvents, WebRtcTransportObserver, WebRtcTransportObserverEvents, -} from './WebRtcTransportInterface'; +} from './WebRtcTransportTypes'; import { TransportInterface, TransportTuple, SctpState, -} from './TransportInterface'; +} from './TransportTypes'; import { - Transport, + TransportImpl, TransportConstructorOptions, parseSctpState, parseBaseTransportDump, @@ -70,8 +70,10 @@ export type WebRtcTransportData = { const logger = new Logger('WebRtcTransport'); -export class WebRtcTransport - extends Transport< +export class WebRtcTransportImpl< + WebRtcTransportAppData extends AppData = AppData, + > + extends TransportImpl< WebRtcTransportAppData, WebRtcTransportEvents, WebRtcTransportObserver diff --git a/node/src/WebRtcTransportInterface.ts b/node/src/WebRtcTransportTypes.ts similarity index 98% rename from node/src/WebRtcTransportInterface.ts rename to node/src/WebRtcTransportTypes.ts index 1b95cd68cc..1d713d5a0b 100644 --- a/node/src/WebRtcTransportInterface.ts +++ b/node/src/WebRtcTransportTypes.ts @@ -10,8 +10,8 @@ import { BaseTransportStats, TransportEvents, TransportObserverEvents, -} from './TransportInterface'; -import { WebRtcServerInterface } from './WebRtcServerInterface'; +} from './TransportTypes'; +import { WebRtcServerInterface } from './WebRtcServerTypes'; import { SctpParameters, NumSctpStreams } from './SctpParameters'; import { Either, AppData } from './types'; diff --git a/node/src/Worker.ts b/node/src/Worker.ts index 08fda4bd2a..236eac469f 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -14,15 +14,15 @@ import { WorkerEvents, WorkerObserver, WorkerObserverEvents, -} from './WorkerInterface'; +} from './WorkerTypes'; import { Channel } from './Channel'; import { WebRtcServerInterface, WebRtcServerOptions, -} from './WebRtcServerInterface'; -import { WebRtcServer } from './WebRtcServer'; -import { RouterInterface, RouterOptions } from './RouterInterface'; -import { Router } from './Router'; +} from './WebRtcServerTypes'; +import { WebRtcServerImpl } from './WebRtcServer'; +import { RouterInterface, RouterOptions } from './RouterTypes'; +import { RouterImpl } from './Router'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; import { RtpCodecCapability } from './RtpParameters'; import { AppData } from './types'; @@ -61,7 +61,7 @@ export const workerBin = process.env.MEDIASOUP_WORKER_BIN const logger = new Logger('Worker'); const workerLogger = new Logger('Worker'); -export class Worker +export class WorkerImpl extends EnhancedEventEmitter implements WorkerInterface { @@ -533,7 +533,7 @@ export class Worker ); const webRtcServer: WebRtcServerInterface = - new WebRtcServer({ + new WebRtcServerImpl({ internal: { webRtcServerId }, channel: this.#channel, appData, @@ -586,7 +586,7 @@ export class Worker ); const data = { rtpCapabilities }; - const router: RouterInterface = new Router({ + const router: RouterInterface = new RouterImpl({ internal: { routerId, }, diff --git a/node/src/WorkerInterface.ts b/node/src/WorkerTypes.ts similarity index 97% rename from node/src/WorkerInterface.ts rename to node/src/WorkerTypes.ts index 30b3696546..28df5d4b3a 100644 --- a/node/src/WorkerInterface.ts +++ b/node/src/WorkerTypes.ts @@ -2,8 +2,8 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { WebRtcServerInterface, WebRtcServerOptions, -} from './WebRtcServerInterface'; -import { RouterInterface, RouterOptions } from './RouterInterface'; +} from './WebRtcServerTypes'; +import { RouterInterface, RouterOptions } from './RouterTypes'; import { AppData } from './types'; export type WorkerLogLevel = 'debug' | 'warn' | 'error' | 'none'; diff --git a/node/src/index.ts b/node/src/index.ts index a781d44ddb..c0f389c6a2 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -1,7 +1,7 @@ import { Logger, LoggerEmitter } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { WorkerInterface, WorkerSettings } from './WorkerInterface'; -import { Worker, workerBin } from './Worker'; +import { WorkerInterface, WorkerSettings } from './WorkerTypes'; +import { WorkerImpl, workerBin } from './Worker'; import * as utils from './utils'; import { supportedRtpCapabilities } from './supportedRtpCapabilities'; import { RtpCapabilities } from './RtpParameters'; @@ -126,7 +126,7 @@ export async function createWorker< throw new TypeError('if given, appData must be an object'); } - const worker: WorkerInterface = new Worker({ + const worker: WorkerInterface = new WorkerImpl({ logLevel, logTags, rtcMinPort, diff --git a/node/src/test/test-Consumer.ts b/node/src/test/test-Consumer.ts index f190163f92..e6f90b3492 100644 --- a/node/src/test/test-Consumer.ts +++ b/node/src/test/test-Consumer.ts @@ -2,7 +2,7 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents, ConsumerEvents } from '../types'; -import { Consumer } from '../Consumer'; +import { ConsumerImpl } from '../Consumer'; import { UnsupportedError } from '../errors'; import * as utils from '../utils'; import { @@ -1054,7 +1054,7 @@ test('Consumer emits "score"', async () => { }); // API not exposed in the interface. - const channel = (audioConsumer as Consumer).channelForTesting; + const channel = (audioConsumer as ConsumerImpl).channelForTesting; const onScore = jest.fn(); audioConsumer.on('score', onScore); diff --git a/node/src/test/test-DirectTransport.ts b/node/src/test/test-DirectTransport.ts index cb8784f3bb..2380d96e18 100644 --- a/node/src/test/test-DirectTransport.ts +++ b/node/src/test/test-DirectTransport.ts @@ -1,6 +1,6 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { DirectTransportEvents } from '../DirectTransportInterface'; +import { DirectTransportEvents } from '../DirectTransportTypes'; import { WorkerEvents } from '../types'; type TestContext = { diff --git a/node/src/test/test-Producer.ts b/node/src/test/test-Producer.ts index 6587ae781c..0402ce0f6b 100644 --- a/node/src/test/test-Producer.ts +++ b/node/src/test/test-Producer.ts @@ -2,7 +2,7 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents, ProducerEvents } from '../types'; -import { Producer } from '../Producer'; +import { ProducerImpl } from '../Producer'; import { UnsupportedError } from '../errors'; import * as utils from '../utils'; import { @@ -728,7 +728,7 @@ test('Producer emits "score"', async () => { ); // API not exposed in the interface. - const channel = (videoProducer as Producer).channelForTesting; + const channel = (videoProducer as ProducerImpl).channelForTesting; const onScore = jest.fn(); videoProducer.on('score', onScore); diff --git a/node/src/test/test-Router.ts b/node/src/test/test-Router.ts index 81804755cd..f584e1dacb 100644 --- a/node/src/test/test-Router.ts +++ b/node/src/test/test-Router.ts @@ -1,6 +1,6 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { Worker } from '../Worker'; +import { WorkerImpl } from '../Worker'; import { WorkerEvents, RouterEvents } from '../types'; import { InvalidStateError } from '../errors'; import * as utils from '../utils'; @@ -96,14 +96,14 @@ test('worker.createRouter() succeeds', async () => { }); // API not exposed in the interface. - expect((ctx.worker! as Worker).routersForTesting.size).toBe(1); + expect((ctx.worker! as WorkerImpl).routersForTesting.size).toBe(1); ctx.worker!.close(); expect(router.closed).toBe(true); // API not exposed in the interface. - expect((ctx.worker! as Worker).routersForTesting.size).toBe(0); + expect((ctx.worker! as WorkerImpl).routersForTesting.size).toBe(0); }, 2000); test('worker.createRouter() with wrong arguments rejects with TypeError', async () => { diff --git a/node/src/test/test-WebRtcServer.ts b/node/src/test/test-WebRtcServer.ts index 9dff5aa1df..10f695af21 100644 --- a/node/src/test/test-WebRtcServer.ts +++ b/node/src/test/test-WebRtcServer.ts @@ -1,10 +1,10 @@ import { pickPort } from 'pick-port'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { Worker } from '../Worker'; +import { WorkerImpl } from '../Worker'; import { WorkerEvents, WebRtcServerEvents } from '../types'; -import { WebRtcServer } from '../WebRtcServer'; -import { Router } from '../Router'; +import { WebRtcServerImpl } from '../WebRtcServer'; +import { RouterImpl } from '../Router'; import { InvalidStateError } from '../errors'; type TestContext = { @@ -84,14 +84,14 @@ test('worker.createWebRtcServer() succeeds', async () => { }); // API not exposed in the interface. - expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(1); + expect((ctx.worker! as WorkerImpl).webRtcServersForTesting.size).toBe(1); ctx.worker!.close(); expect(webRtcServer.closed).toBe(true); // API not exposed in the interface. - expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(0); + expect((ctx.worker! as WorkerImpl).webRtcServersForTesting.size).toBe(0); }, 2000); test('worker.createWebRtcServer() with portRange succeeds', async () => { @@ -153,14 +153,14 @@ test('worker.createWebRtcServer() with portRange succeeds', async () => { }); // API not exposed in the interface. - expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(1); + expect((ctx.worker! as WorkerImpl).webRtcServersForTesting.size).toBe(1); ctx.worker!.close(); expect(webRtcServer.closed).toBe(true); // API not exposed in the interface. - expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(0); + expect((ctx.worker! as WorkerImpl).webRtcServersForTesting.size).toBe(0); }, 2000); test('worker.createWebRtcServer() without specifying port/portRange succeeds', async () => { @@ -209,14 +209,14 @@ test('worker.createWebRtcServer() without specifying port/portRange succeeds', a }); // API not exposed in the interface. - expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(1); + expect((ctx.worker! as WorkerImpl).webRtcServersForTesting.size).toBe(1); ctx.worker!.close(); expect(webRtcServer.closed).toBe(true); // API not exposed in the interface. - expect((ctx.worker! as Worker).webRtcServersForTesting.size).toBe(0); + expect((ctx.worker! as WorkerImpl).webRtcServersForTesting.size).toBe(0); }, 2000); test('worker.createWebRtcServer() with wrong arguments rejects with TypeError', async () => { @@ -439,11 +439,11 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is expect(transport.iceSelectedTuple).toBeUndefined(); // API not exposed in the interface. - expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( - 1 - ); + expect( + (webRtcServer as WebRtcServerImpl).webRtcTransportsForTesting.size + ).toBe(1); // API not exposed in the interface. - expect((router as Router).transportsForTesting.size).toBe(1); + expect((router as RouterImpl).transportsForTesting.size).toBe(1); await expect(webRtcServer.dump()).resolves.toMatchObject({ id: webRtcServer.id, @@ -462,11 +462,11 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and transport is expect(onObserverWebRtcTransportUnhandled).toHaveBeenCalledTimes(1); expect(onObserverWebRtcTransportUnhandled).toHaveBeenCalledWith(transport); // API not exposed in the interface. - expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( - 0 - ); + expect( + (webRtcServer as WebRtcServerImpl).webRtcTransportsForTesting.size + ).toBe(0); // API not exposed in the interface. - expect((router as Router).transportsForTesting.size).toBe(0); + expect((router as RouterImpl).transportsForTesting.size).toBe(0); await expect(webRtcServer.dump()).resolves.toMatchObject({ id: webRtcServer.id, @@ -543,11 +543,11 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and webRtcServer expect(transport.iceSelectedTuple).toBeUndefined(); // API not exposed in the interface. - expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( - 1 - ); + expect( + (webRtcServer as WebRtcServerImpl).webRtcTransportsForTesting.size + ).toBe(1); // API not exposed in the interface. - expect((router as Router).transportsForTesting.size).toBe(1); + expect((router as RouterImpl).transportsForTesting.size).toBe(1); await expect(webRtcServer.dump()).resolves.toMatchObject({ id: webRtcServer.id, @@ -597,11 +597,11 @@ test('router.createWebRtcTransport() with webRtcServer succeeds and webRtcServer expect(transport.dtlsState).toBe('closed'); expect(transport.sctpState).toBe(undefined); // API not exposed in the interface. - expect((webRtcServer as WebRtcServer).webRtcTransportsForTesting.size).toBe( - 0 - ); + expect( + (webRtcServer as WebRtcServerImpl).webRtcTransportsForTesting.size + ).toBe(0); // API not exposed in the interface. - expect((router as Router).transportsForTesting.size).toBe(0); + expect((router as RouterImpl).transportsForTesting.size).toBe(0); await expect(ctx.worker!.dump()).resolves.toMatchObject({ pid: ctx.worker!.pid, diff --git a/node/src/test/test-WebRtcTransport.ts b/node/src/test/test-WebRtcTransport.ts index f43849f8a8..bba38bd7c2 100644 --- a/node/src/test/test-WebRtcTransport.ts +++ b/node/src/test/test-WebRtcTransport.ts @@ -3,8 +3,8 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents, WebRtcTransportEvents } from '../types'; -import { WebRtcTransport } from '../WebRtcTransport'; -import { TransportTuple } from '../TransportInterface'; +import { WebRtcTransportImpl } from '../WebRtcTransport'; +import { TransportTuple } from '../TransportTypes'; import { serializeProtocol } from '../Transport'; import * as utils from '../utils'; import { @@ -670,7 +670,7 @@ test('WebRtcTransport events succeed', async () => { }); // API not exposed in the interface. - const channel = (webRtcTransport as WebRtcTransport).channelForTesting; + const channel = (webRtcTransport as WebRtcTransportImpl).channelForTesting; const onIceStateChange = jest.fn(); webRtcTransport.on('icestatechange', onIceStateChange); diff --git a/node/src/types.ts b/node/src/types.ts index cfe07698fb..d1006d7d47 100644 --- a/node/src/types.ts +++ b/node/src/types.ts @@ -1,24 +1,26 @@ export type { Observer, ObserverEvents, LogEventListeners } from './index'; +export type * from './WorkerTypes'; +export type * from './WebRtcServerTypes'; +export type * from './RouterTypes'; +export type * from './TransportTypes'; +export type * from './WebRtcTransportTypes'; +export type * from './PlainTransportTypes'; +export type * from './PipeTransportTypes'; +export type * from './DirectTransportTypes'; +export type * from './ProducerTypes'; +export type * from './ConsumerTypes'; +export type * from './DataProducerTypes'; +export type * from './DataConsumerTypes'; +export type * from './RtpObserverTypes'; +export type * from './ActiveSpeakerObserverTypes'; +export type * from './AudioLevelObserverTypes'; export type * from './RtpParameters'; export type * from './SctpParameters'; export type * from './SrtpParameters'; export type * from './scalabilityModes'; -export * from './WorkerInterface'; -export * from './WebRtcServerInterface'; -export * from './RouterInterface'; -export * from './TransportInterface'; -export * from './WebRtcTransportInterface'; -export * from './PlainTransportInterface'; -export * from './PipeTransportInterface'; -export * from './DirectTransportInterface'; -export * from './ProducerInterface'; -export * from './ConsumerInterface'; -export * from './DataProducerInterface'; -export * from './DataConsumerInterface'; -export * from './RtpObserverInterface'; -export * from './ActiveSpeakerObserverInterface'; -export * from './AudioLevelObserverInterface'; +// TODO: Here we are exporting real classes rather than types. This should +// be exported somehow else rather than in mediasoup.types namespace. export * from './errors'; type Only = { diff --git a/node/src/utils.ts b/node/src/utils.ts index c6e1d9748d..7ecfcc2e67 100644 --- a/node/src/utils.ts +++ b/node/src/utils.ts @@ -1,5 +1,5 @@ import { randomUUID, randomInt } from 'node:crypto'; -import { ProducerType } from './ProducerInterface'; +import { ProducerType } from './ProducerTypes'; import { Type as FbsRtpParametersType } from './fbs/rtp-parameters'; /** From eff296cb5aa2e430f986dde7ad59cf08082dc1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 8 Nov 2024 19:15:40 +0100 Subject: [PATCH 03/14] done AFAIS --- CHANGELOG.md | 2 + node/src/ActiveSpeakerObserverTypes.ts | 5 ++ node/src/AudioLevelObserverTypes.ts | 5 ++ node/src/Consumer.ts | 86 +----------------------- node/src/ConsumerTypes.ts | 75 +++++++++++++++++++++ node/src/DataConsumer.ts | 80 ----------------------- node/src/DataConsumerTypes.ts | 72 +++++++++++++++++++++ node/src/DataProducer.ts | 56 ---------------- node/src/DataProducerTypes.ts | 48 ++++++++++++++ node/src/DirectTransport.ts | 44 ------------- node/src/DirectTransportTypes.ts | 23 +++++++ node/src/PipeTransport.ts | 69 +++----------------- node/src/PipeTransportTypes.ts | 27 +++++++- node/src/PlainTransport.ts | 47 -------------- node/src/PlainTransportTypes.ts | 29 ++++++++- node/src/Producer.ts | 64 ------------------ node/src/ProducerTypes.ts | 51 +++++++++++++++ node/src/Router.ts | 62 +----------------- node/src/RouterTypes.ts | 36 +++++++++++ node/src/RtpObserver.ts | 42 ------------ node/src/RtpObserverTypes.ts | 35 ++++++++++ node/src/Transport.ts | 90 +------------------------- node/src/TransportTypes.ts | 87 ++++++++++++++++++++++++- node/src/WebRtcServer.ts | 33 ---------- node/src/WebRtcServerTypes.ts | 15 +++++ node/src/WebRtcTransport.ts | 67 ------------------- node/src/WebRtcTransportTypes.ts | 35 ++++++++++ node/src/Worker.ts | 46 ------------- node/src/WorkerTypes.ts | 27 ++++++++ 29 files changed, 583 insertions(+), 775 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cb5c6df80..69b07bb4fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### NEXT +- Node: Add TypeScript interfaces for all exported classes ([PR #1463](https://github.com/versatica/mediasoup/pull/1463)). + ### 3.14.16 - `SimulcastConsumer`: Fix cannot switch layers if initial `tsReferenceSpatialLayer disappears` disappears ([PR #1459](https://github.com/versatica/mediasoup/pull/1459) by @Lynnworld). diff --git a/node/src/ActiveSpeakerObserverTypes.ts b/node/src/ActiveSpeakerObserverTypes.ts index b436c2ecdb..da09eb205a 100644 --- a/node/src/ActiveSpeakerObserverTypes.ts +++ b/node/src/ActiveSpeakerObserverTypes.ts @@ -43,5 +43,10 @@ export interface ActiveSpeakerObserverInterface< ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver > { + /** + * Observer. + * + * @override + */ get observer(): ActiveSpeakerObserverObserver; } diff --git a/node/src/AudioLevelObserverTypes.ts b/node/src/AudioLevelObserverTypes.ts index 9979adaf8e..92c8f5fac1 100644 --- a/node/src/AudioLevelObserverTypes.ts +++ b/node/src/AudioLevelObserverTypes.ts @@ -65,5 +65,10 @@ export interface AudioLevelObserverInterface< AudioLevelObserverEvents, AudioLevelObserverObserver > { + /** + * Observer. + * + * @override + */ get observer(): AudioLevelObserverObserver; } diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index a47c43bbb3..5d8422c701 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -99,9 +99,6 @@ export class ConsumerImpl readonly #observer: ConsumerObserver = new EnhancedEventEmitter(); - /** - * @private - */ constructor({ internal, data, @@ -137,122 +134,75 @@ export class ConsumerImpl this.handleWorkerNotifications(); } - /** - * Consumer id. - */ get id(): string { return this.#internal.consumerId; } - /** - * Associated Producer id. - */ get producerId(): string { return this.#data.producerId; } - /** - * Whether the Consumer is closed. - */ get closed(): boolean { return this.#closed; } - /** - * Media kind. - */ get kind(): MediaKind { return this.#data.kind; } - /** - * RTP parameters. - */ get rtpParameters(): RtpParameters { return this.#data.rtpParameters; } - /** - * Consumer type. - */ get type(): ConsumerType { return this.#data.type; } - /** - * Whether the Consumer is paused. - */ get paused(): boolean { return this.#paused; } - /** - * Whether the associate Producer is paused. - */ get producerPaused(): boolean { return this.#producerPaused; } - /** - * Current priority. - */ get priority(): number { return this.#priority; } - /** - * Consumer score. - */ get score(): ConsumerScore { return this.#score; } - /** - * Preferred video layers. - */ get preferredLayers(): ConsumerLayers | undefined { return this.#preferredLayers; } - /** - * Current video layers. - */ get currentLayers(): ConsumerLayers | undefined { return this.#currentLayers; } - /** - * App custom data. - */ get appData(): ConsumerAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: ConsumerAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): ConsumerObserver { return this.#observer; } /** - * @private * Just for testing purposes. + * + * @private */ get channelForTesting(): Channel { return this.#channel; } - /** - * Close the Consumer. - */ close(): void { if (this.#closed) { return; @@ -285,11 +235,6 @@ export class ConsumerImpl this.#observer.safeEmit('close'); } - /** - * Transport was closed. - * - * @private - */ transportClosed(): void { if (this.#closed) { return; @@ -308,9 +253,6 @@ export class ConsumerImpl this.#observer.safeEmit('close'); } - /** - * Dump Consumer. - */ async dump(): Promise { logger.debug('dump()'); @@ -329,9 +271,6 @@ export class ConsumerImpl return parseConsumerDumpResponse(data); } - /** - * Get Consumer stats. - */ async getStats(): Promise<(ConsumerStat | ProducerStat)[]> { logger.debug('getStats()'); @@ -350,9 +289,6 @@ export class ConsumerImpl return parseConsumerStats(data); } - /** - * Pause the Consumer. - */ async pause(): Promise { logger.debug('pause()'); @@ -373,9 +309,6 @@ export class ConsumerImpl } } - /** - * Resume the Consumer. - */ async resume(): Promise { logger.debug('resume()'); @@ -396,9 +329,6 @@ export class ConsumerImpl } } - /** - * Set preferred video layers. - */ async setPreferredLayers({ spatialLayer, temporalLayer, @@ -453,9 +383,6 @@ export class ConsumerImpl this.#preferredLayers = preferredLayers; } - /** - * Set priority. - */ async setPriority(priority: number): Promise { logger.debug('setPriority()'); @@ -485,18 +412,12 @@ export class ConsumerImpl this.#priority = status.priority; } - /** - * Unset priority. - */ async unsetPriority(): Promise { logger.debug('unsetPriority()'); await this.setPriority(1); } - /** - * Request a key frame to the Producer. - */ async requestKeyFrame(): Promise { logger.debug('requestKeyFrame()'); @@ -508,9 +429,6 @@ export class ConsumerImpl ); } - /** - * Enable 'trace' event. - */ async enableTraceEvent(types: ConsumerTraceEventType[] = []): Promise { logger.debug('enableTraceEvent()'); diff --git a/node/src/ConsumerTypes.ts b/node/src/ConsumerTypes.ts index 9a611ce89a..85a6793309 100644 --- a/node/src/ConsumerTypes.ts +++ b/node/src/ConsumerTypes.ts @@ -256,36 +256,84 @@ export type ConsumerObserverEvents = { export interface ConsumerInterface extends EnhancedEventEmitter { + /** + * Consumer id. + */ get id(): string; + /** + * Associated Producer id. + */ get producerId(): string; + /** + * Whether the Consumer is closed. + */ get closed(): boolean; + /** + * Media kind. + */ get kind(): MediaKind; + /** + * RTP parameters. + */ get rtpParameters(): RtpParameters; + /** + * Consumer type. + */ get type(): ConsumerType; + /** + * Whether the Consumer is paused. + */ get paused(): boolean; + /** + * Whether the associate Producer is paused. + */ get producerPaused(): boolean; + /** + * Current priority. + */ get priority(): number; + /** + * Consumer score. + */ get score(): ConsumerScore; + /** + * Preferred video layers. + */ get preferredLayers(): ConsumerLayers | undefined; + /** + * Current video layers. + */ get currentLayers(): ConsumerLayers | undefined; + /** + * App custom data. + */ get appData(): ConsumerAppData; + /** + * App custom data setter. + */ set appData(appData: ConsumerAppData); + /** + * Observer. + */ get observer(): ConsumerObserver; + /** + * Close the Consumer. + */ close(): void; /** @@ -295,24 +343,51 @@ export interface ConsumerInterface */ transportClosed(): void; + /** + * Dump Consumer. + */ dump(): Promise; + /** + * Get Consumer stats. + */ getStats(): Promise<(ConsumerStat | ProducerStat)[]>; + /** + * Pause the Consumer. + */ pause(): Promise; + /** + * Resume the Consumer. + */ resume(): Promise; + /** + * Set preferred video layers. + */ setPreferredLayers({ spatialLayer, temporalLayer, }: ConsumerLayers): Promise; + /** + * Set priority. + */ setPriority(priority: number): Promise; + /** + * Unset priority. + */ unsetPriority(): Promise; + /** + * Request a key frame to the Producer. + */ requestKeyFrame(): Promise; + /** + * Enable 'trace' event. + */ enableTraceEvent(types?: ConsumerTraceEventType[]): Promise; } diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index 040cc4dd03..f34ae1fe64 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -70,9 +70,6 @@ export class DataConsumerImpl readonly #observer: DataConsumerObserver = new EnhancedEventEmitter(); - /** - * @private - */ constructor({ internal, data, @@ -105,100 +102,58 @@ export class DataConsumerImpl this.handleWorkerNotifications(); } - /** - * DataConsumer id. - */ get id(): string { return this.#internal.dataConsumerId; } - /** - * Associated DataProducer id. - */ get dataProducerId(): string { return this.#data.dataProducerId; } - /** - * Whether the DataConsumer is closed. - */ get closed(): boolean { return this.#closed; } - /** - * DataConsumer type. - */ get type(): DataConsumerType { return this.#data.type; } - /** - * SCTP stream parameters. - */ get sctpStreamParameters(): SctpStreamParameters | undefined { return this.#data.sctpStreamParameters; } - /** - * DataChannel label. - */ get label(): string { return this.#data.label; } - /** - * DataChannel protocol. - */ get protocol(): string { return this.#data.protocol; } - /** - * Whether the DataConsumer is paused. - */ get paused(): boolean { return this.#paused; } - /** - * Whether the associate DataProducer is paused. - */ get dataProducerPaused(): boolean { return this.#dataProducerPaused; } - /** - * Get current subchannels this data consumer is subscribed to. - */ get subchannels(): number[] { return Array.from(this.#subchannels); } - /** - * App custom data. - */ get appData(): DataConsumerAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: DataConsumerAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): DataConsumerObserver { return this.#observer; } - /** - * Close the DataConsumer. - */ close(): void { if (this.#closed) { return; @@ -231,11 +186,6 @@ export class DataConsumerImpl this.#observer.safeEmit('close'); } - /** - * Transport was closed. - * - * @private - */ transportClosed(): void { if (this.#closed) { return; @@ -254,9 +204,6 @@ export class DataConsumerImpl this.#observer.safeEmit('close'); } - /** - * Dump DataConsumer. - */ async dump(): Promise { logger.debug('dump()'); @@ -275,9 +222,6 @@ export class DataConsumerImpl return parseDataConsumerDumpResponse(dumpResponse); } - /** - * Get DataConsumer stats. - */ async getStats(): Promise { logger.debug('getStats()'); @@ -296,9 +240,6 @@ export class DataConsumerImpl return [parseDataConsumerStats(data)]; } - /** - * Pause the DataConsumer. - */ async pause(): Promise { logger.debug('pause()'); @@ -319,9 +260,6 @@ export class DataConsumerImpl } } - /** - * Resume the DataConsumer. - */ async resume(): Promise { logger.debug('resume()'); @@ -342,9 +280,6 @@ export class DataConsumerImpl } } - /** - * Set buffered amount low threshold. - */ async setBufferedAmountLowThreshold(threshold: number): Promise { logger.debug(`setBufferedAmountLowThreshold() [threshold:${threshold}]`); @@ -363,9 +298,6 @@ export class DataConsumerImpl ); } - /** - * Get buffered amount size. - */ async getBufferedAmount(): Promise { logger.debug('getBufferedAmount()'); @@ -383,9 +315,6 @@ export class DataConsumerImpl return data.bufferedAmount(); } - /** - * Send data. - */ async send(message: string | Buffer, ppid?: number): Promise { if (typeof message !== 'string' && !Buffer.isBuffer(message)) { throw new TypeError('message must be a string or a Buffer'); @@ -449,9 +378,6 @@ export class DataConsumerImpl ); } - /** - * Set subchannels. - */ async setSubchannels(subchannels: number[]): Promise { logger.debug('setSubchannels()'); @@ -476,9 +402,6 @@ export class DataConsumerImpl this.#subchannels = utils.parseVector(data, 'subchannels'); } - /** - * Add a subchannel. - */ async addSubchannel(subchannel: number): Promise { logger.debug('addSubchannel()'); @@ -505,9 +428,6 @@ export class DataConsumerImpl this.#subchannels = utils.parseVector(data, 'subchannels'); } - /** - * Remove a subchannel. - */ async removeSubchannel(subchannel: number): Promise { logger.debug('removeSubchannel()'); diff --git a/node/src/DataConsumerTypes.ts b/node/src/DataConsumerTypes.ts index bc74283c51..2a4c6f6a60 100644 --- a/node/src/DataConsumerTypes.ts +++ b/node/src/DataConsumerTypes.ts @@ -105,32 +105,74 @@ export type DataConsumerObserverEvents = { export interface DataConsumerInterface< DataConsumerAppData extends AppData = AppData, > extends EnhancedEventEmitter { + /** + * DataConsumer id. + */ get id(): string; + /** + * Associated DataProducer id. + */ get dataProducerId(): string; + /** + * Whether the DataConsumer is closed. + */ get closed(): boolean; + /** + * DataConsumer type. + */ get type(): DataConsumerType; + /** + * SCTP stream parameters. + */ get sctpStreamParameters(): SctpStreamParameters | undefined; + /** + * DataChannel label. + */ get label(): string; + /** + * DataChannel protocol. + */ get protocol(): string; + /** + * Whether the DataConsumer is paused. + */ get paused(): boolean; + /** + * Whether the associate DataProducer is paused. + */ get dataProducerPaused(): boolean; + /** + * Get current subchannels this data consumer is subscribed to. + */ get subchannels(): number[]; + /** + * App custom data. + */ get appData(): DataConsumerAppData; + /** + * App custom data setter. + */ set appData(appData: DataConsumerAppData); + /** + * Observer. + */ get observer(): DataConsumerObserver; + /** + * Close the DataConsumer. + */ close(): void; /** @@ -140,23 +182,53 @@ export interface DataConsumerInterface< */ transportClosed(): void; + /** + * Dump DataConsumer. + */ dump(): Promise; + /** + * Get DataConsumer stats. + */ getStats(): Promise; + /** + * Pause the DataConsumer. + */ pause(): Promise; + /** + * Resume the DataConsumer. + */ resume(): Promise; + /** + * Set buffered amount low threshold. + */ setBufferedAmountLowThreshold(threshold: number): Promise; + /** + * Get buffered amount size. + */ getBufferedAmount(): Promise; + /** + * Send a message. + */ send(message: string | Buffer, ppid?: number): Promise; + /** + * Set subchannels. + */ setSubchannels(subchannels: number[]): Promise; + /** + * Add a subchannel. + */ addSubchannel(subchannel: number): Promise; + /** + * Remove a subchannel. + */ removeSubchannel(subchannel: number): Promise; } diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index 95a681f854..d1f1be3e19 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -60,9 +60,6 @@ export class DataProducerImpl readonly #observer: DataProducerObserver = new EnhancedEventEmitter(); - /** - * @private - */ constructor({ internal, data, @@ -89,79 +86,46 @@ export class DataProducerImpl this.handleWorkerNotifications(); } - /** - * DataProducer id. - */ get id(): string { return this.#internal.dataProducerId; } - /** - * Whether the DataProducer is closed. - */ get closed(): boolean { return this.#closed; } - /** - * DataProducer type. - */ get type(): DataProducerType { return this.#data.type; } - /** - * SCTP stream parameters. - */ get sctpStreamParameters(): SctpStreamParameters | undefined { return this.#data.sctpStreamParameters; } - /** - * DataChannel label. - */ get label(): string { return this.#data.label; } - /** - * DataChannel protocol. - */ get protocol(): string { return this.#data.protocol; } - /** - * Whether the DataProducer is paused. - */ get paused(): boolean { return this.#paused; } - /** - * App custom data. - */ get appData(): DataProducerAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: DataProducerAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): DataProducerObserver { return this.#observer; } - /** - * Close the DataProducer. - */ close(): void { if (this.#closed) { return; @@ -194,11 +158,6 @@ export class DataProducerImpl this.#observer.safeEmit('close'); } - /** - * Transport was closed. - * - * @private - */ transportClosed(): void { if (this.#closed) { return; @@ -217,9 +176,6 @@ export class DataProducerImpl this.#observer.safeEmit('close'); } - /** - * Dump DataProducer. - */ async dump(): Promise { logger.debug('dump()'); @@ -238,9 +194,6 @@ export class DataProducerImpl return parseDataProducerDumpResponse(produceResponse); } - /** - * Get DataProducer stats. - */ async getStats(): Promise { logger.debug('getStats()'); @@ -259,9 +212,6 @@ export class DataProducerImpl return [parseDataProducerStats(data)]; } - /** - * Pause the DataProducer. - */ async pause(): Promise { logger.debug('pause()'); @@ -282,9 +232,6 @@ export class DataProducerImpl } } - /** - * Resume the DataProducer. - */ async resume(): Promise { logger.debug('resume()'); @@ -305,9 +252,6 @@ export class DataProducerImpl } } - /** - * Send data (just valid for DataProducers created on a DirectTransport). - */ send( message: string | Buffer, ppid?: number, diff --git a/node/src/DataProducerTypes.ts b/node/src/DataProducerTypes.ts index e84650d892..ab71db3adc 100644 --- a/node/src/DataProducerTypes.ts +++ b/node/src/DataProducerTypes.ts @@ -78,26 +78,59 @@ export type DataProducerObserverEvents = { export interface DataProducerInterface< DataProducerAppData extends AppData = AppData, > extends EnhancedEventEmitter { + /** + * DataProducer id. + */ get id(): string; + /** + * Whether the DataProducer is closed. + */ get closed(): boolean; + /** + * DataProducer type. + */ get type(): DataProducerType; + /** + * SCTP stream parameters. + */ get sctpStreamParameters(): SctpStreamParameters | undefined; + /** + * DataChannel label. + */ get label(): string; + /** + * DataChannel protocol. + */ get protocol(): string; + /** + * Whether the DataProducer is paused. + */ get paused(): boolean; + /** + * App custom data. + */ get appData(): DataProducerAppData; + /** + * App custom data setter. + */ set appData(appData: DataProducerAppData); + /** + * Observer. + */ get observer(): DataProducerObserver; + /** + * Close the DataProducer. + */ close(): void; /** @@ -107,14 +140,29 @@ export interface DataProducerInterface< */ transportClosed(): void; + /** + * Dump DataProducer. + */ dump(): Promise; + /** + * Get DataProducer stats. + */ getStats(): Promise; + /** + * Pause the DataProducer. + */ pause(): Promise; + /** + * Resume the DataProducer. + */ resume(): Promise; + /** + * Send data (just valid for DataProducers created on a DirectTransport). + */ send( message: string | Buffer, ppid?: number, diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index e5d65ed8ef..2c005092e3 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -50,9 +50,6 @@ export class DirectTransportImpl< // eslint-disable-next-line no-unused-private-class-members readonly #data: DirectTransportData; - /** - * @private - */ constructor( options: DirectTransportConstructorOptions ) { @@ -70,20 +67,10 @@ export class DirectTransportImpl< this.handleWorkerNotifications(); } - /** - * Observer. - * - * @override - */ get observer(): DirectTransportObserver { return super.observer; } - /** - * Close the DirectTransport. - * - * @override - */ close(): void { if (this.closed) { return; @@ -92,12 +79,6 @@ export class DirectTransportImpl< super.close(); } - /** - * Router was closed. - * - * @private - * @override - */ routerClosed(): void { if (this.closed) { return; @@ -106,9 +87,6 @@ export class DirectTransportImpl< super.routerClosed(); } - /** - * Dump DirectTransport. - */ async dump(): Promise { logger.debug('dump()'); @@ -127,11 +105,6 @@ export class DirectTransportImpl< return parseDirectTransportDumpResponse(data); } - /** - * Get DirectTransport stats. - * - * @override - */ async getStats(): Promise { logger.debug('getStats()'); @@ -150,19 +123,11 @@ export class DirectTransportImpl< return [parseGetStatsResponse(data)]; } - /** - * NO-OP method in DirectTransport. - * - * @override - */ // eslint-disable-next-line @typescript-eslint/require-await async connect(): Promise { logger.debug('connect()'); } - /** - * @override - */ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await async setMaxIncomingBitrate(bitrate: number): Promise { throw new UnsupportedError( @@ -170,9 +135,6 @@ export class DirectTransportImpl< ); } - /** - * @override - */ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await async setMaxOutgoingBitrate(bitrate: number): Promise { throw new UnsupportedError( @@ -180,9 +142,6 @@ export class DirectTransportImpl< ); } - /** - * @override - */ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await async setMinOutgoingBitrate(bitrate: number): Promise { throw new UnsupportedError( @@ -190,9 +149,6 @@ export class DirectTransportImpl< ); } - /** - * Send RTCP packet. - */ sendRtcp(rtcpPacket: Buffer): void { if (!Buffer.isBuffer(rtcpPacket)) { throw new TypeError('rtcpPacket must be a Buffer'); diff --git a/node/src/DirectTransportTypes.ts b/node/src/DirectTransportTypes.ts index 8b77198a75..4205c0110e 100644 --- a/node/src/DirectTransportTypes.ts +++ b/node/src/DirectTransportTypes.ts @@ -47,13 +47,36 @@ export interface DirectTransportInterface< DirectTransportEvents, DirectTransportObserver > { + /** + * Observer. + * + * @override + */ get observer(): DirectTransportObserver; + /** + * Dump DirectTransport. + * + * @override + */ dump(): Promise; + /** + * Get DirectTransport stats. + * + * @override + */ getStats(): Promise; + /** + * NO-OP method in DirectTransport. + * + * @override + */ connect(): Promise; + /** + * Send RTCP packet. + */ sendRtcp(rtcpPacket: Buffer): void; } diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index afbfad450c..e92095971e 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -74,9 +74,6 @@ export class PipeTransport // PipeTransport data. readonly #data: PipeTransportData; - /** - * @private - */ constructor(options: PipeTransportConstructorOptions) { const observer: PipeTransportObserver = new EnhancedEventEmitter(); @@ -98,48 +95,26 @@ export class PipeTransport this.handleWorkerNotifications(); } - /** - * Observer. - * - * @override - */ get observer(): PipeTransportObserver { return super.observer; } - /** - * Transport tuple. - */ get tuple(): TransportTuple { return this.#data.tuple; } - /** - * SCTP parameters. - */ get sctpParameters(): SctpParameters | undefined { return this.#data.sctpParameters; } - /** - * SCTP state. - */ get sctpState(): SctpState | undefined { return this.#data.sctpState; } - /** - * SRTP parameters. - */ get srtpParameters(): SrtpParameters | undefined { return this.#data.srtpParameters; } - /** - * Close the PipeTransport. - * - * @override - */ close(): void { if (this.closed) { return; @@ -152,12 +127,6 @@ export class PipeTransport super.close(); } - /** - * Router was closed. - * - * @private - * @override - */ routerClosed(): void { if (this.closed) { return; @@ -170,55 +139,42 @@ export class PipeTransport super.routerClosed(); } - /** - * Get PipeTransport stats. - * - * @override - */ - async getStats(): Promise { - logger.debug('getStats()'); + async dump(): Promise { + logger.debug('dump()'); const response = await this.channel.request( - FbsRequest.Method.TRANSPORT_GET_STATS, + FbsRequest.Method.TRANSPORT_DUMP, undefined, undefined, this.internal.transportId ); /* Decode Response. */ - const data = new FbsPipeTransport.GetStatsResponse(); + const data = new FbsPipeTransport.DumpResponse(); response.body(data); - return [parseGetStatsResponse(data)]; + return parsePipeTransportDumpResponse(data); } - /** - * Dump PipeTransport. - */ - async dump(): Promise { - logger.debug('dump()'); + async getStats(): Promise { + logger.debug('getStats()'); const response = await this.channel.request( - FbsRequest.Method.TRANSPORT_DUMP, + FbsRequest.Method.TRANSPORT_GET_STATS, undefined, undefined, this.internal.transportId ); /* Decode Response. */ - const data = new FbsPipeTransport.DumpResponse(); + const data = new FbsPipeTransport.GetStatsResponse(); response.body(data); - return parsePipeTransportDumpResponse(data); + return [parseGetStatsResponse(data)]; } - /** - * Provide the PipeTransport remote parameters. - * - * @override - */ async connect({ ip, port, @@ -256,11 +212,6 @@ export class PipeTransport } } - /** - * Create a pipe Consumer. - * - * @override - */ async consume({ producerId, appData, diff --git a/node/src/PipeTransportTypes.ts b/node/src/PipeTransportTypes.ts index 593923c88e..d60ce63ac1 100644 --- a/node/src/PipeTransportTypes.ts +++ b/node/src/PipeTransportTypes.ts @@ -79,8 +79,8 @@ type PipeTransportListenIp = { listenIp: TransportListenIp | string; /** - * Fixed port to listen on instead of selecting automatically from Worker's port - * range. + * Fixed port to listen on instead of selecting automatically from Worker's + * port range. */ port?: number; }; @@ -126,8 +126,16 @@ export interface PipeTransportInterface< PipeTransportEvents, PipeTransportObserver > { + /** + * Observer. + * + * @override + */ get observer(): PipeTransportObserver; + /** + * PipeTransport tuple. + */ get tuple(): TransportTuple; /** @@ -145,10 +153,25 @@ export interface PipeTransportInterface< */ get srtpParameters(): SrtpParameters | undefined; + /** + * Dump PipeTransport. + * + * @override + */ dump(): Promise; + /** + * Get PipeTransport stats. + * + * @override + */ getStats(): Promise; + /** + * Provide the PipeTransport remote parameters. + * + * @override + */ connect({ ip, port, diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index 0d55164252..9993e79ff8 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -63,9 +63,6 @@ export class PlainTransportImpl // PlainTransport data. readonly #data: PlainTransportData; - /** - * @private - */ constructor( options: PlainTransportConstructorOptions ) { @@ -91,55 +88,30 @@ export class PlainTransportImpl this.handleWorkerNotifications(); } - /** - * Observer. - * - * @override - */ get observer(): PlainTransportObserver { return super.observer; } - /** - * Transport tuple. - */ get tuple(): TransportTuple { return this.#data.tuple; } - /** - * Transport RTCP tuple. - */ get rtcpTuple(): TransportTuple | undefined { return this.#data.rtcpTuple; } - /** - * SCTP parameters. - */ get sctpParameters(): SctpParameters | undefined { return this.#data.sctpParameters; } - /** - * SCTP state. - */ get sctpState(): SctpState | undefined { return this.#data.sctpState; } - /** - * SRTP parameters. - */ get srtpParameters(): SrtpParameters | undefined { return this.#data.srtpParameters; } - /** - * Close the PlainTransport. - * - * @override - */ close(): void { if (this.closed) { return; @@ -152,12 +124,6 @@ export class PlainTransportImpl super.close(); } - /** - * Router was closed. - * - * @private - * @override - */ routerClosed(): void { if (this.closed) { return; @@ -170,9 +136,6 @@ export class PlainTransportImpl super.routerClosed(); } - /** - * Dump PlainTransport. - */ async dump(): Promise { logger.debug('dump()'); @@ -191,11 +154,6 @@ export class PlainTransportImpl return parsePlainTransportDumpResponse(data); } - /** - * Get PlainTransport stats. - * - * @override - */ async getStats(): Promise { logger.debug('getStats()'); @@ -214,11 +172,6 @@ export class PlainTransportImpl return [parseGetStatsResponse(data)]; } - /** - * Provide the PlainTransport remote parameters. - * - * @override - */ async connect({ ip, port, diff --git a/node/src/PlainTransportTypes.ts b/node/src/PlainTransportTypes.ts index eeebd2c682..accc461d26 100644 --- a/node/src/PlainTransportTypes.ts +++ b/node/src/PlainTransportTypes.ts @@ -94,8 +94,8 @@ type PlainTransportListenIp = { listenIp: TransportListenIp | string; /** - * Fixed port to listen on instead of selecting automatically from Worker's port - * range. + * Fixed port to listen on instead of selecting automatically from Worker's + * port range. */ port?: number; }; @@ -138,12 +138,20 @@ export interface PlainTransportInterface< PlainTransportEvents, PlainTransportObserver > { + /** + * Observer. + * + * @override + */ get observer(): PlainTransportObserver; + /** + * PlainTransport tuple. + */ get tuple(): TransportTuple; /** - * Transport RTCP tuple. + * PlainTransport RTCP tuple. */ get rtcpTuple(): TransportTuple | undefined; @@ -162,10 +170,25 @@ export interface PlainTransportInterface< */ get srtpParameters(): SrtpParameters | undefined; + /** + * Dump PlainTransport. + * + * @override + */ dump(): Promise; + /** + * Get PlainTransport stats. + * + * @override + */ getStats(): Promise; + /** + * Provide the PlainTransport remote parameters. + * + * @override + */ connect({ ip, port, diff --git a/node/src/Producer.ts b/node/src/Producer.ts index 0ba9dc39c8..f0f72e9d9e 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -70,9 +70,6 @@ export class ProducerImpl readonly #observer: ProducerObserver = new EnhancedEventEmitter(); - /** - * @private - */ constructor({ internal, data, @@ -99,81 +96,46 @@ export class ProducerImpl this.handleWorkerNotifications(); } - /** - * Producer id. - */ get id(): string { return this.#internal.producerId; } - /** - * Whether the Producer is closed. - */ get closed(): boolean { return this.#closed; } - /** - * Media kind. - */ get kind(): MediaKind { return this.#data.kind; } - /** - * RTP parameters. - */ get rtpParameters(): RtpParameters { return this.#data.rtpParameters; } - /** - * Producer type. - */ get type(): ProducerType { return this.#data.type; } - /** - * Consumable RTP parameters. - * - * @private - */ get consumableRtpParameters(): RtpParameters { return this.#data.consumableRtpParameters; } - /** - * Whether the Producer is paused. - */ get paused(): boolean { return this.#paused; } - /** - * Producer score list. - */ get score(): ProducerScore[] { return this.#score; } - /** - * App custom data. - */ get appData(): ProducerAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: ProducerAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): ProducerObserver { return this.#observer; } @@ -187,9 +149,6 @@ export class ProducerImpl return this.#channel; } - /** - * Close the Producer. - */ close(): void { if (this.#closed) { return; @@ -222,11 +181,6 @@ export class ProducerImpl this.#observer.safeEmit('close'); } - /** - * Transport was closed. - * - * @private - */ transportClosed(): void { if (this.#closed) { return; @@ -245,9 +199,6 @@ export class ProducerImpl this.#observer.safeEmit('close'); } - /** - * Dump Producer. - */ async dump(): Promise { logger.debug('dump()'); @@ -266,9 +217,6 @@ export class ProducerImpl return parseProducerDump(dumpResponse); } - /** - * Get Producer stats. - */ async getStats(): Promise { logger.debug('getStats()'); @@ -287,9 +235,6 @@ export class ProducerImpl return parseProducerStats(data); } - /** - * Pause the Producer. - */ async pause(): Promise { logger.debug('pause()'); @@ -310,9 +255,6 @@ export class ProducerImpl } } - /** - * Resume the Producer. - */ async resume(): Promise { logger.debug('resume()'); @@ -333,9 +275,6 @@ export class ProducerImpl } } - /** - * Enable 'trace' event. - */ async enableTraceEvent(types: ProducerTraceEventType[] = []): Promise { logger.debug('enableTraceEvent()'); @@ -370,9 +309,6 @@ export class ProducerImpl ); } - /** - * Send RTP packet (just valid for Producers created on a DirectTransport). - */ send(rtpPacket: Buffer): void { if (!Buffer.isBuffer(rtpPacket)) { throw new TypeError('rtpPacket must be a Buffer'); diff --git a/node/src/ProducerTypes.ts b/node/src/ProducerTypes.ts index d4786cd340..8eadc1f66d 100644 --- a/node/src/ProducerTypes.ts +++ b/node/src/ProducerTypes.ts @@ -152,14 +152,29 @@ export type ProducerObserverEvents = { export interface ProducerInterface extends EnhancedEventEmitter { + /** + * Producer id. + */ get id(): string; + /** + * Whether the Producer is closed. + */ get closed(): boolean; + /** + * Media kind. + */ get kind(): MediaKind; + /** + * RTP parameters. + */ get rtpParameters(): RtpParameters; + /** + * Producer type. + */ get type(): ProducerType; /** @@ -169,16 +184,34 @@ export interface ProducerInterface */ get consumableRtpParameters(): RtpParameters; + /** + * Whether the Producer is paused. + */ get paused(): boolean; + /** + * Producer score list. + */ get score(): ProducerScore[]; + /** + * App custom data. + */ get appData(): ProducerAppData; + /** + * App custom data setter. + */ set appData(appData: ProducerAppData); + /** + * Observer. + */ get observer(): ProducerObserver; + /** + * Close the Producer. + */ close(): void; /** @@ -188,15 +221,33 @@ export interface ProducerInterface */ transportClosed(): void; + /** + * Dump Producer. + */ dump(): Promise; + /** + * Get Producer stats. + */ getStats(): Promise; + /** + * Pause the Producer. + */ pause(): Promise; + /** + * Resume the Producer. + */ resume(): Promise; + /** + * Enable 'trace' event. + */ enableTraceEvent(types?: ProducerTraceEventType[]): Promise; + /** + * Send RTP packet (just valid for Producers created on a DirectTransport). + */ send(rtpPacket: Buffer): void; } diff --git a/node/src/Router.ts b/node/src/Router.ts index 8fe8c8031c..f1aadeed73 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -138,9 +138,6 @@ export class RouterImpl readonly #observer: RouterObserver = new EnhancedEventEmitter(); - /** - * @private - */ constructor({ internal, data, @@ -162,59 +159,39 @@ export class RouterImpl this.#appData = appData ?? ({} as RouterAppData); } - /** - * Router id. - */ get id(): string { return this.#internal.routerId; } - /** - * Whether the Router is closed. - */ get closed(): boolean { return this.#closed; } - /** - * RTP capabilities of the Router. - */ get rtpCapabilities(): RtpCapabilities { return this.#data.rtpCapabilities; } - /** - * App custom data. - */ get appData(): RouterAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: RouterAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): RouterObserver { return this.#observer; } /** - * @private * Just for testing purposes. + * + * @private */ get transportsForTesting(): Map { return this.#transports; } - /** - * Close the Router. - */ close(): void { if (this.#closed) { return; @@ -260,11 +237,6 @@ export class RouterImpl this.#observer.safeEmit('close'); } - /** - * Worker was closed. - * - * @private - */ workerClosed(): void { if (this.#closed) { return; @@ -298,9 +270,6 @@ export class RouterImpl this.#observer.safeEmit('close'); } - /** - * Dump Router. - */ async dump(): Promise { logger.debug('dump()'); @@ -320,9 +289,6 @@ export class RouterImpl return parseRouterDumpResponse(dump); } - /** - * Create a WebRtcTransport. - */ async createWebRtcTransport< WebRtcTransportAppData extends AppData = AppData, >({ @@ -555,9 +521,6 @@ export class RouterImpl return transport; } - /** - * Create a PlainTransport. - */ async createPlainTransport({ listenInfo, rtcpListenInfo, @@ -724,9 +687,6 @@ export class RouterImpl return transport; } - /** - * Create a PipeTransport. - */ async createPipeTransport({ listenInfo, listenIp, @@ -865,9 +825,6 @@ export class RouterImpl return transport; } - /** - * Create a DirectTransport. - */ async createDirectTransport( { maxMessageSize = 262144, @@ -963,9 +920,6 @@ export class RouterImpl return transport; } - /** - * Pipes the given Producer or DataProducer into another Router in same host. - */ async pipeToRouter({ producerId, dataProducerId, @@ -1226,9 +1180,6 @@ export class RouterImpl } } - /** - * @private - */ addPipeTransportPair( pipeTransportPairKey: string, pipeTransportPairPromise: Promise @@ -1263,9 +1214,6 @@ export class RouterImpl }); } - /** - * Create an ActiveSpeakerObserver - */ async createActiveSpeakerObserver< ActiveSpeakerObserverAppData extends AppData = AppData, >({ @@ -1323,9 +1271,6 @@ export class RouterImpl return activeSpeakerObserver; } - /** - * Create an AudioLevelObserver. - */ async createAudioLevelObserver< AudioLevelObserverAppData extends AppData = AppData, >({ @@ -1399,9 +1344,6 @@ export class RouterImpl return audioLevelObserver; } - /** - * Check whether the given RTP capabilities can consume the given Producer. - */ canConsume({ producerId, rtpCapabilities, diff --git a/node/src/RouterTypes.ts b/node/src/RouterTypes.ts index c0f12abd87..fc0419c7fa 100644 --- a/node/src/RouterTypes.ts +++ b/node/src/RouterTypes.ts @@ -177,8 +177,14 @@ export type RouterObserverEvents = { export interface RouterInterface extends EnhancedEventEmitter { + /** + * Router id. + */ get id(): string; + /** + * Whether the Router is closed. + */ get closed(): boolean; /** @@ -201,6 +207,9 @@ export interface RouterInterface */ get observer(): RouterObserver; + /** + * Close the Router. + */ close(): void; /** @@ -210,24 +219,42 @@ export interface RouterInterface */ workerClosed(): void; + /** + * Dump Router. + */ dump(): Promise; + /** + * Create a WebRtcTransport. + */ createWebRtcTransport( options: WebRtcTransportOptions ): Promise>; + /** + * Create a PlainTransport. + */ createPlainTransport( options: PlainTransportOptions ): Promise>; + /** + * Create a PipeTransport. + */ createPipeTransport( options: PipeTransportOptions ): Promise>; + /** + * Create a DirectTransport. + */ createDirectTransport( options?: DirectTransportOptions ): Promise>; + /** + * Pipes the given Producer or DataProducer into another Router in same host. + */ pipeToRouter(options: PipeToRouterOptions): Promise; /** @@ -238,16 +265,25 @@ export interface RouterInterface pipeTransportPairPromise: Promise ): void; + /** + * Create an ActiveSpeakerObserver + */ createActiveSpeakerObserver< ActiveSpeakerObserverAppData extends AppData = AppData, >( options?: ActiveSpeakerObserverOptions ): Promise>; + /** + * Create an AudioLevelObserver. + */ createAudioLevelObserver( options?: AudioLevelObserverOptions ): Promise>; + /** + * Check whether the given RTP capabilities can consume the given Producer. + */ canConsume({ producerId, rtpCapabilities, diff --git a/node/src/RtpObserver.ts b/node/src/RtpObserver.ts index b277b07d31..e9744be597 100644 --- a/node/src/RtpObserver.ts +++ b/node/src/RtpObserver.ts @@ -50,10 +50,6 @@ export abstract class RtpObserverImpl< // Observer instance. readonly #observer: Observer; - /** - * @private - * @interface - */ constructor( { internal, @@ -74,51 +70,30 @@ export abstract class RtpObserverImpl< this.#observer = observer; } - /** - * RtpObserver id. - */ get id(): string { return this.internal.rtpObserverId; } - /** - * Whether the RtpObserver is closed. - */ get closed(): boolean { return this.#closed; } - /** - * Whether the RtpObserver is paused. - */ get paused(): boolean { return this.#paused; } - /** - * App custom data. - */ get appData(): RtpObserverAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: RtpObserverAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): Observer { return this.#observer; } - /** - * Close the RtpObserver. - */ close(): void { if (this.#closed) { return; @@ -151,11 +126,6 @@ export abstract class RtpObserverImpl< this.#observer.safeEmit('close'); } - /** - * Router was closed. - * - * @private - */ routerClosed(): void { if (this.#closed) { return; @@ -174,9 +144,6 @@ export abstract class RtpObserverImpl< this.#observer.safeEmit('close'); } - /** - * Pause the RtpObserver. - */ async pause(): Promise { logger.debug('pause()'); @@ -197,9 +164,6 @@ export abstract class RtpObserverImpl< } } - /** - * Resume the RtpObserver. - */ async resume(): Promise { logger.debug('resume()'); @@ -220,9 +184,6 @@ export abstract class RtpObserverImpl< } } - /** - * Add a Producer to the RtpObserver. - */ async addProducer({ producerId }: { producerId: string }): Promise { logger.debug('addProducer()'); @@ -247,9 +208,6 @@ export abstract class RtpObserverImpl< this.#observer.safeEmit('addproducer', producer); } - /** - * Remove a Producer from the RtpObserver. - */ async removeProducer({ producerId }: { producerId: string }): Promise { logger.debug('removeProducer()'); diff --git a/node/src/RtpObserverTypes.ts b/node/src/RtpObserverTypes.ts index 52c7c81329..d745b57940 100644 --- a/node/src/RtpObserverTypes.ts +++ b/node/src/RtpObserverTypes.ts @@ -25,18 +25,41 @@ export interface RtpObserverInterface< Events extends RtpObserverEvents = RtpObserverEvents, Observer extends RtpObserverObserver = RtpObserverObserver, > extends EnhancedEventEmitter { + /** + * RtpObserver id. + */ get id(): string; + /** + * Whether the RtpObserver is closed. + */ get closed(): boolean; + /** + * Whether the RtpObserver is paused. + */ get paused(): boolean; + /** + * App custom data. + */ get appData(): RtpObserverAppData; + /** + * App custom data setter. + */ set appData(appData: RtpObserverAppData); + /** + * Observer. + * + * @virtual + */ get observer(): Observer; + /** + * Close the RtpObserver. + */ close(): void; /** @@ -46,11 +69,23 @@ export interface RtpObserverInterface< */ routerClosed(): void; + /** + * Pause the RtpObserver. + */ pause(): Promise; + /** + * Resume the RtpObserver. + */ resume(): Promise; + /** + * Add a Producer to the RtpObserver. + */ addProducer({ producerId }: { producerId: string }): Promise; + /** + * Remove a Producer from the RtpObserver. + */ removeProducer({ producerId }: { producerId: string }): Promise; } diff --git a/node/src/Transport.ts b/node/src/Transport.ts index 4ff00de575..4b7a7beae4 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -203,52 +203,33 @@ export abstract class TransportImpl< this.#observer = observer; } - /** - * Transport id. - */ get id(): string { return this.internal.transportId; } - /** - * Whether the Transport is closed. - */ get closed(): boolean { return this.#closed; } - /** - * App custom data. - */ get appData(): TransportAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: TransportAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): Observer { return this.#observer; } /** - * @private * Just for testing purposes. */ get channelForTesting(): Channel { return this.channel; } - /** - * Close the Transport. - */ close(): void { if (this.#closed) { return; @@ -311,12 +292,6 @@ export abstract class TransportImpl< this.#observer.safeEmit('close'); } - /** - * Router was closed. - * - * @private - * @virtual - */ routerClosed(): void { if (this.#closed) { return; @@ -365,12 +340,6 @@ export abstract class TransportImpl< this.#observer.safeEmit('close'); } - /** - * Listen server was closed (this just happens in WebRtcTransports when their - * associated WebRtcServer is closed). - * - * @private - */ listenServerClosed(): void { if (this.#closed) { return; @@ -424,42 +393,12 @@ export abstract class TransportImpl< this.#observer.safeEmit('close'); } - /** - * Dump Transport. - * - * @abstract - */ - // eslint-disable-next-line @typescript-eslint/require-await - async dump(): Promise { - // Should not happen. - throw new Error('method implemented in the subclass'); - } + abstract dump(): Promise; - /** - * Get Transport stats. - * - * @abstract - */ - // eslint-disable-next-line @typescript-eslint/require-await - async getStats(): Promise { - // Should not happen. - throw new Error('method implemented in the subclass'); - } + abstract getStats(): Promise; - /** - * Provide the Transport remote parameters. - * - * @abstract - */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await - async connect(params: any): Promise { - // Should not happen. - throw new Error('method implemented in the subclass'); - } + abstract connect(params: any): Promise; - /** - * Set maximum incoming bitrate for receiving media. - */ async setMaxIncomingBitrate(bitrate: number): Promise { logger.debug(`setMaxIncomingBitrate() [bitrate:${bitrate}]`); @@ -478,9 +417,6 @@ export abstract class TransportImpl< ); } - /** - * Set maximum outgoing bitrate for sending media. - */ async setMaxOutgoingBitrate(bitrate: number): Promise { logger.debug(`setMaxOutgoingBitrate() [bitrate:${bitrate}]`); @@ -497,9 +433,6 @@ export abstract class TransportImpl< ); } - /** - * Set minimum outgoing bitrate for sending media. - */ async setMinOutgoingBitrate(bitrate: number): Promise { logger.debug(`setMinOutgoingBitrate() [bitrate:${bitrate}]`); @@ -516,9 +449,6 @@ export abstract class TransportImpl< ); } - /** - * Create a Producer. - */ async produce({ id = undefined, kind, @@ -646,11 +576,6 @@ export abstract class TransportImpl< return producer; } - /** - * Create a Consumer. - * - * @virtual - */ async consume({ producerId, rtpCapabilities, @@ -779,9 +704,6 @@ export abstract class TransportImpl< return consumer; } - /** - * Create a DataProducer. - */ async produceData({ id = undefined, sctpStreamParameters, @@ -883,9 +805,6 @@ export abstract class TransportImpl< return dataProducer; } - /** - * Create a DataConsumer. - */ async consumeData({ dataProducerId, ordered, @@ -1031,9 +950,6 @@ export abstract class TransportImpl< return dataConsumer; } - /** - * Enable 'trace' event. - */ async enableTraceEvent(types: TransportTraceEventType[] = []): Promise { logger.debug('enableTraceEvent()'); diff --git a/node/src/TransportTypes.ts b/node/src/TransportTypes.ts index 73c606d793..0cedbc65fd 100644 --- a/node/src/TransportTypes.ts +++ b/node/src/TransportTypes.ts @@ -221,7 +221,7 @@ export type TransportTraceEventData = { /** * Per type information. */ - info: any; + info: unknown; }; export type TransportEvents = { @@ -254,22 +254,45 @@ export interface TransportInterface< Events extends TransportEvents = TransportEvents, Observer extends TransportObserver = TransportObserver, > extends EnhancedEventEmitter { + /** + * Transport id. + */ get id(): string; + /** + * Whether the Transport is closed. + */ get closed(): boolean; + /** + * App custom data. + */ get appData(): TransportAppData; + /** + * App custom data setter. + */ set appData(appData: TransportAppData); + /** + * Observer. + * + * @virtual + */ get observer(): Observer; + /** + * Close the Transport. + * + * @virtual + */ close(): void; /** * Router was closed. * * @private + * @virtual */ routerClosed(): void; @@ -278,30 +301,92 @@ export interface TransportInterface< * associated WebRtcServer is closed). * * @private + * @virtual */ listenServerClosed(): void; + /** + * Dump Transport. + * + * @abstract + */ + dump(): Promise; + + /** + * Get Transport stats. + * + * @abstract + */ + getStats(): Promise; + + /** + * Provide the Transport remote parameters. + * + * @abstract + */ + connect(params: unknown): Promise; + + /** + * Set maximum incoming bitrate for receiving media. + * + * @virtual + * @privateRemarks + * - It's marked as virtual method because DirectTransport overrides it. + */ setMaxIncomingBitrate(bitrate: number): Promise; + /** + * Set maximum outgoing bitrate for sending media. + * + * @virtual + * @privateRemarks + * - It's marked as virtual method because DirectTransport overrides it. + */ setMaxOutgoingBitrate(bitrate: number): Promise; + /** + * Set minimum outgoing bitrate for sending media. + * + * @virtual + * @privateRemarks + * - It's marked as virtual method because DirectTransport overrides it. + */ setMinOutgoingBitrate(bitrate: number): Promise; + /** + * Create a Producer. + */ produce( options: ProducerOptions ): Promise>; + /** + * Create a Consumer. + * + * @virtual + * @privateRemarks + * - It's marked as virtual method because PipeTransport overrides it. + */ consume( options: ConsumerOptions ): Promise>; + /** + * Create a DataProducer. + */ produceData( options?: DataProducerOptions ): Promise>; + /** + * Create a DataConsumer. + */ consumeData( options: DataConsumerOptions ): Promise>; + /** + * Enable 'trace' event. + */ enableTraceEvent(types?: TransportTraceEventType[]): Promise; } diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index c516b7fa29..624f355197 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -47,9 +47,6 @@ export class WebRtcServerImpl readonly #observer: WebRtcServerObserver = new EnhancedEventEmitter(); - /** - * @private - */ constructor({ internal, channel, @@ -68,52 +65,33 @@ export class WebRtcServerImpl this.#appData = appData ?? ({} as WebRtcServerAppData); } - /** - * WebRtcServer id. - */ get id(): string { return this.#internal.webRtcServerId; } - /** - * Whether the WebRtcServer is closed. - */ get closed(): boolean { return this.#closed; } - /** - * App custom data. - */ get appData(): WebRtcServerAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: WebRtcServerAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): WebRtcServerObserver { return this.#observer; } /** - * @private * Just for testing purposes. */ get webRtcTransportsForTesting(): Map { return this.#webRtcTransports; } - /** - * Close the WebRtcServer. - */ close(): void { if (this.#closed) { return; @@ -151,11 +129,6 @@ export class WebRtcServerImpl this.#observer.safeEmit('close'); } - /** - * Worker was closed. - * - * @private - */ workerClosed(): void { if (this.#closed) { return; @@ -175,9 +148,6 @@ export class WebRtcServerImpl this.#observer.safeEmit('close'); } - /** - * Dump WebRtcServer. - */ async dump(): Promise { logger.debug('dump()'); @@ -196,9 +166,6 @@ export class WebRtcServerImpl return parseWebRtcServerDump(dump); } - /** - * @private - */ handleWebRtcTransport(webRtcTransport: WebRtcTransportInterface): void { this.#webRtcTransports.set(webRtcTransport.id, webRtcTransport); diff --git a/node/src/WebRtcServerTypes.ts b/node/src/WebRtcServerTypes.ts index 5dbcaeb207..9a8e1e11e3 100644 --- a/node/src/WebRtcServerTypes.ts +++ b/node/src/WebRtcServerTypes.ts @@ -64,10 +64,19 @@ export type WebRtcServerObserverEvents = { export interface WebRtcServerInterface< WebRtcServerAppData extends AppData = AppData, > extends EnhancedEventEmitter { + /** + * WebRtcServer id. + */ get id(): string; + /** + * Whether the WebRtcServer is closed. + */ get closed(): boolean; + /** + * App custom data. + */ get appData(): WebRtcServerAppData; /** @@ -80,6 +89,9 @@ export interface WebRtcServerInterface< */ get observer(): WebRtcServerObserver; + /** + * Close the WebRtcServer. + */ close(): void; /** @@ -89,6 +101,9 @@ export interface WebRtcServerInterface< */ workerClosed(): void; + /** + * Dump WebRtcServer. + */ dump(): Promise; /** diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index 3a444cf665..25f1d29854 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -114,90 +114,50 @@ export class WebRtcTransportImpl< this.handleWorkerNotifications(); } - /** - * Observer. - * - * @override - */ get observer(): WebRtcTransportObserver { return super.observer; } - /** - * ICE role. - */ get iceRole(): 'controlled' { return this.#data.iceRole; } - /** - * ICE parameters. - */ get iceParameters(): IceParameters { return this.#data.iceParameters; } - /** - * ICE candidates. - */ get iceCandidates(): IceCandidate[] { return this.#data.iceCandidates; } - /** - * ICE state. - */ get iceState(): IceState { return this.#data.iceState; } - /** - * ICE selected tuple. - */ get iceSelectedTuple(): TransportTuple | undefined { return this.#data.iceSelectedTuple; } - /** - * DTLS parameters. - */ get dtlsParameters(): DtlsParameters { return this.#data.dtlsParameters; } - /** - * DTLS state. - */ get dtlsState(): DtlsState { return this.#data.dtlsState; } - /** - * Remote certificate in PEM format. - */ get dtlsRemoteCert(): string | undefined { return this.#data.dtlsRemoteCert; } - /** - * SCTP parameters. - */ get sctpParameters(): SctpParameters | undefined { return this.#data.sctpParameters; } - /** - * SCTP state. - */ get sctpState(): SctpState | undefined { return this.#data.sctpState; } - /** - * Close the WebRtcTransport. - * - * @override - */ close(): void { if (this.closed) { return; @@ -214,12 +174,6 @@ export class WebRtcTransportImpl< super.close(); } - /** - * Router was closed. - * - * @private - * @override - */ routerClosed(): void { if (this.closed) { return; @@ -236,11 +190,6 @@ export class WebRtcTransportImpl< super.routerClosed(); } - /** - * Called when closing the associated listenServer (WebRtcServer). - * - * @private - */ listenServerClosed(): void { if (this.closed) { return; @@ -257,9 +206,6 @@ export class WebRtcTransportImpl< super.listenServerClosed(); } - /** - * Dump WebRtcTransport. - */ async dump(): Promise { logger.debug('dump()'); @@ -278,11 +224,6 @@ export class WebRtcTransportImpl< return parseWebRtcTransportDumpResponse(data); } - /** - * Get WebRtcTransport stats. - * - * @override - */ async getStats(): Promise { logger.debug('getStats()'); @@ -301,11 +242,6 @@ export class WebRtcTransportImpl< return [parseGetStatsResponse(data)]; } - /** - * Provide the WebRtcTransport remote parameters. - * - * @override - */ async connect({ dtlsParameters, }: { @@ -335,9 +271,6 @@ export class WebRtcTransportImpl< this.#data.dtlsParameters.role = dtlsRoleFromFbs(data.dtlsLocalRole()); } - /** - * Restart ICE. - */ async restartIce(): Promise { logger.debug('restartIce()'); diff --git a/node/src/WebRtcTransportTypes.ts b/node/src/WebRtcTransportTypes.ts index 1d713d5a0b..b1ef621086 100644 --- a/node/src/WebRtcTransportTypes.ts +++ b/node/src/WebRtcTransportTypes.ts @@ -223,14 +223,31 @@ export interface WebRtcTransportInterface< WebRtcTransportEvents, WebRtcTransportObserver > { + /** + * Observer. + * + * @override + */ get observer(): WebRtcTransportObserver; + /** + * ICE role. + */ get iceRole(): 'controlled'; + /** + * ICE parameters. + */ get iceParameters(): IceParameters; + /** + * ICE candidates. + */ get iceCandidates(): IceCandidate[]; + /** + * ICE state. + */ get iceState(): IceState; /** @@ -263,15 +280,33 @@ export interface WebRtcTransportInterface< */ get sctpState(): SctpState | undefined; + /** + * Dump WebRtcTransport. + * + * @override + */ dump(): Promise; + /** + * Get WebRtcTransport stats. + * + * @override + */ getStats(): Promise; + /** + * Provide the WebRtcTransport remote parameters. + * + * @override + */ connect({ dtlsParameters, }: { dtlsParameters: DtlsParameters; }): Promise; + /** + * Restart ICE. + */ restartIce(): Promise; } diff --git a/node/src/Worker.ts b/node/src/Worker.ts index 236eac469f..01137e9c21 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -96,9 +96,6 @@ export class WorkerImpl readonly #observer: WorkerObserver = new EnhancedEventEmitter(); - /** - * @private - */ constructor({ logLevel, logTags, @@ -306,59 +303,36 @@ export class WorkerImpl }); } - /** - * Worker process identifier (PID). - */ get pid(): number { return this.#pid; } - /** - * Whether the Worker is closed. - */ get closed(): boolean { return this.#closed; } - /** - * Whether the Worker died. - */ get died(): boolean { return this.#died; } - /** - * Whether the Worker subprocess is closed. - */ get subprocessClosed(): boolean { return this.#subprocessClosed; } - /** - * App custom data. - */ get appData(): WorkerAppData { return this.#appData; } - /** - * App custom data setter. - */ set appData(appData: WorkerAppData) { this.#appData = appData; } - /** - * Observer. - */ get observer(): WorkerObserver { return this.#observer; } /** * Just for testing purposes. - * - * @private */ get webRtcServersForTesting(): Set { return this.#webRtcServers; @@ -366,16 +340,11 @@ export class WorkerImpl /** * Just for testing purposes. - * - * @private */ get routersForTesting(): Set { return this.#routers; } - /** - * Close the Worker. - */ close(): void { if (this.#closed) { return; @@ -407,9 +376,6 @@ export class WorkerImpl this.#observer.safeEmit('close'); } - /** - * Dump Worker. - */ async dump(): Promise { logger.debug('dump()'); @@ -424,9 +390,6 @@ export class WorkerImpl return parseWorkerDumpResponse(dump); } - /** - * Get mediasoup-worker process resource usage. - */ async getResourceUsage(): Promise { logger.debug('getResourceUsage()'); @@ -461,9 +424,6 @@ export class WorkerImpl }; } - /** - * Update settings. - */ async updateSettings({ logLevel, logTags, @@ -483,9 +443,6 @@ export class WorkerImpl ); } - /** - * Create a WebRtcServer. - */ async createWebRtcServer({ listenInfos, appData, @@ -548,9 +505,6 @@ export class WorkerImpl return webRtcServer; } - /** - * Create a Router. - */ async createRouter({ mediaCodecs, appData, diff --git a/node/src/WorkerTypes.ts b/node/src/WorkerTypes.ts index 28df5d4b3a..5f468c7614 100644 --- a/node/src/WorkerTypes.ts +++ b/node/src/WorkerTypes.ts @@ -209,10 +209,19 @@ export type WorkerObserverEvents = { export interface WorkerInterface extends EnhancedEventEmitter { + /** + * Worker process identifier (PID). + */ get pid(): number; + /** + * Whether the Worker is closed. + */ get closed(): boolean; + /** + * Whether the Worker died. + */ get died(): boolean; /** @@ -235,20 +244,38 @@ export interface WorkerInterface */ get observer(): WorkerObserver; + /** + * Close the Worker. + */ close(): void; + /** + * Dump Worker. + */ dump(): Promise; + /** + * Get mediasoup-worker process resource usage. + */ getResourceUsage(): Promise; + /** + * Update settings. + */ updateSettings( options?: WorkerUpdateableSettings ): Promise; + /** + * Create a WebRtcServer. + */ createWebRtcServer( options: WebRtcServerOptions ): Promise>; + /** + * Create a Router. + */ createRouter( options?: RouterOptions ): Promise>; From 1fac13e6eadfe29ec52aebf5070b4e6020df30ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 8 Nov 2024 19:17:57 +0100 Subject: [PATCH 04/14] cosmetic --- node/src/index.ts | 13 +++---------- node/src/types.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/node/src/index.ts b/node/src/index.ts index c0f389c6a2..f5b73483b5 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -44,15 +44,6 @@ export { workerBin }; const logger = new Logger(); -/** - * Event listeners for mediasoup generated logs. - */ -export type LogEventListeners = { - ondebug?: (namespace: string, log: string) => void; - onwarn?: (namespace: string, log: string) => void; - onerror?: (namespace: string, log: string, error?: Error) => void; -}; - /** * Set event listeners for mediasoup generated logs. If called with no arguments * then no events will be emitted. @@ -74,7 +65,9 @@ export type LogEventListeners = { * }); * ``` */ -export function setLogEventListeners(listeners?: LogEventListeners): void { +export function setLogEventListeners( + listeners?: types.LogEventListeners +): void { logger.debug('setLogEventListeners()'); let debugLogEmitter: LoggerEmitter | undefined; diff --git a/node/src/types.ts b/node/src/types.ts index d1006d7d47..032f6c5690 100644 --- a/node/src/types.ts +++ b/node/src/types.ts @@ -1,4 +1,4 @@ -export type { Observer, ObserverEvents, LogEventListeners } from './index'; +export type { Observer, ObserverEvents } from './index'; export type * from './WorkerTypes'; export type * from './WebRtcServerTypes'; export type * from './RouterTypes'; @@ -34,3 +34,12 @@ export type Either = Only | Only; export type AppData = { [key: string]: unknown; }; + +/** + * Event listeners for mediasoup generated logs. + */ +export type LogEventListeners = { + ondebug?: (namespace: string, log: string) => void; + onwarn?: (namespace: string, log: string) => void; + onerror?: (namespace: string, log: string, error?: Error) => void; +}; From 90b226559234d2420b431b873721914b8a9aa0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 8 Nov 2024 19:38:04 +0100 Subject: [PATCH 05/14] fix --- node/src/ActiveSpeakerObserver.ts | 6 +- node/src/ActiveSpeakerObserverTypes.ts | 10 +- node/src/AudioLevelObserver.ts | 12 +- node/src/AudioLevelObserverTypes.ts | 10 +- node/src/Consumer.ts | 4 +- node/src/ConsumerTypes.ts | 2 +- node/src/DataConsumer.ts | 4 +- node/src/DataConsumerTypes.ts | 5 +- node/src/DataProducer.ts | 4 +- node/src/DataProducerTypes.ts | 5 +- node/src/DirectTransport.ts | 6 +- node/src/DirectTransportTypes.ts | 6 +- node/src/PipeTransport.ts | 24 ++-- node/src/PipeTransportTypes.ts | 13 +- node/src/PlainTransport.ts | 10 +- node/src/PlainTransportTypes.ts | 7 +- node/src/Producer.ts | 4 +- node/src/ProducerTypes.ts | 2 +- node/src/Router.ts | 145 ++++++++++---------- node/src/RouterTypes.ts | 60 ++++---- node/src/RtpObserver.ts | 6 +- node/src/RtpObserverTypes.ts | 8 +- node/src/Transport.ts | 67 ++++----- node/src/TransportTypes.ts | 40 +++--- node/src/WebRtcServer.ts | 12 +- node/src/WebRtcServerTypes.ts | 13 +- node/src/WebRtcTransport.ts | 10 +- node/src/WebRtcTransportTypes.ts | 10 +- node/src/Worker.ts | 29 ++-- node/src/WorkerTypes.ts | 17 +-- node/src/index.ts | 10 +- node/src/test/test-ActiveSpeakerObserver.ts | 4 +- node/src/test/test-AudioLevelObserver.ts | 4 +- node/src/test/test-Consumer.ts | 12 +- node/src/test/test-DataConsumer.ts | 12 +- node/src/test/test-DataProducer.ts | 8 +- node/src/test/test-DirectTransport.ts | 4 +- node/src/test/test-PipeTransport.ts | 38 ++--- node/src/test/test-PlainTransport.ts | 4 +- node/src/test/test-Producer.ts | 8 +- node/src/test/test-Router.ts | 2 +- node/src/test/test-WebRtcServer.ts | 2 +- node/src/test/test-WebRtcTransport.ts | 4 +- node/src/test/test-Worker.ts | 4 +- node/src/test/test-multiopus.ts | 6 +- node/src/test/test-node-sctp.ts | 10 +- 46 files changed, 311 insertions(+), 372 deletions(-) diff --git a/node/src/ActiveSpeakerObserver.ts b/node/src/ActiveSpeakerObserver.ts index 6ff31dcaac..a78d54ed0c 100644 --- a/node/src/ActiveSpeakerObserver.ts +++ b/node/src/ActiveSpeakerObserver.ts @@ -1,13 +1,13 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - ActiveSpeakerObserverInterface, + ActiveSpeakerObserver, ActiveSpeakerObserverDominantSpeaker, ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver, ActiveSpeakerObserverObserverEvents, } from './ActiveSpeakerObserverTypes'; -import { RtpObserverInterface } from './RtpObserverTypes'; +import { RtpObserver } from './RtpObserverTypes'; import { RtpObserverImpl, RtpObserverConstructorOptions } from './RtpObserver'; import { AppData } from './types'; import { Event, Notification } from './fbs/notification'; @@ -26,7 +26,7 @@ export class ActiveSpeakerObserverImpl< ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver > - implements RtpObserverInterface, ActiveSpeakerObserverInterface + implements RtpObserver, ActiveSpeakerObserver { /** * @private diff --git a/node/src/ActiveSpeakerObserverTypes.ts b/node/src/ActiveSpeakerObserverTypes.ts index da09eb205a..cd6822053a 100644 --- a/node/src/ActiveSpeakerObserverTypes.ts +++ b/node/src/ActiveSpeakerObserverTypes.ts @@ -1,10 +1,10 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { - RtpObserverInterface, + RtpObserver, RtpObserverEvents, RtpObserverObserverEvents, } from './RtpObserverTypes'; -import { ProducerInterface } from './ProducerTypes'; +import { Producer } from './ProducerTypes'; import { AppData } from './types'; export type ActiveSpeakerObserverOptions< @@ -22,7 +22,7 @@ export type ActiveSpeakerObserverDominantSpeaker = { /** * The audio Producer instance. */ - producer: ProducerInterface; + producer: Producer; }; export type ActiveSpeakerObserverEvents = RtpObserverEvents & { @@ -36,9 +36,9 @@ export type ActiveSpeakerObserverObserverEvents = RtpObserverObserverEvents & { dominantspeaker: [ActiveSpeakerObserverDominantSpeaker]; }; -export interface ActiveSpeakerObserverInterface< +export interface ActiveSpeakerObserver< ActiveSpeakerObserverAppData extends AppData = AppData, -> extends RtpObserverInterface< +> extends RtpObserver< ActiveSpeakerObserverAppData, ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index a3f09b6133..06e04b8ac2 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -1,15 +1,15 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - AudioLevelObserverInterface, + AudioLevelObserver, AudioLevelObserverVolume, AudioLevelObserverEvents, AudioLevelObserverObserver, AudioLevelObserverObserverEvents, } from './AudioLevelObserverTypes'; -import { RtpObserverInterface } from './RtpObserverTypes'; +import { RtpObserver } from './RtpObserverTypes'; import { RtpObserverImpl, RtpObserverConstructorOptions } from './RtpObserver'; -import { ProducerInterface } from './ProducerTypes'; +import { Producer } from './ProducerTypes'; import { AppData } from './types'; import * as utils from './utils'; import { Event, Notification } from './fbs/notification'; @@ -28,7 +28,7 @@ export class AudioLevelObserverImpl< AudioLevelObserverEvents, AudioLevelObserverObserver > - implements RtpObserverInterface, AudioLevelObserverInterface + implements RtpObserver, AudioLevelObserver { /** * @private @@ -80,9 +80,7 @@ export class AudioLevelObserverImpl< volume, }) ) - .filter( - ({ producer }: { producer: ProducerInterface }) => producer - ); + .filter(({ producer }: { producer: Producer }) => producer); if (volumes.length > 0) { this.safeEmit('volumes', volumes); diff --git a/node/src/AudioLevelObserverTypes.ts b/node/src/AudioLevelObserverTypes.ts index 92c8f5fac1..ddff9fb985 100644 --- a/node/src/AudioLevelObserverTypes.ts +++ b/node/src/AudioLevelObserverTypes.ts @@ -1,10 +1,10 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { - RtpObserverInterface, + RtpObserver, RtpObserverEvents, RtpObserverObserverEvents, } from './RtpObserverTypes'; -import { ProducerInterface } from './ProducerTypes'; +import { Producer } from './ProducerTypes'; import { AppData } from './types'; export type AudioLevelObserverOptions< @@ -36,7 +36,7 @@ export type AudioLevelObserverVolume = { /** * The audio Producer instance. */ - producer: ProducerInterface; + producer: Producer; /** * The average volume (in dBvo from -127 to 0) of the audio Producer in the @@ -58,9 +58,9 @@ export type AudioLevelObserverObserverEvents = RtpObserverObserverEvents & { silence: []; }; -export interface AudioLevelObserverInterface< +export interface AudioLevelObserver< AudioLevelObserverAppData extends AppData = AppData, -> extends RtpObserverInterface< +> extends RtpObserver< AudioLevelObserverAppData, AudioLevelObserverEvents, AudioLevelObserverObserver diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index 5d8422c701..947d477b16 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -1,7 +1,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - ConsumerInterface, + Consumer, ConsumerType, ConsumerScore, ConsumerLayers, @@ -60,7 +60,7 @@ const logger = new Logger('Consumer'); export class ConsumerImpl extends EnhancedEventEmitter - implements ConsumerInterface + implements Consumer { // Internal data. readonly #internal: ConsumerInternal; diff --git a/node/src/ConsumerTypes.ts b/node/src/ConsumerTypes.ts index 85a6793309..bc8c1ad0b2 100644 --- a/node/src/ConsumerTypes.ts +++ b/node/src/ConsumerTypes.ts @@ -254,7 +254,7 @@ export type ConsumerObserverEvents = { trace: [ConsumerTraceEventData]; }; -export interface ConsumerInterface +export interface Consumer extends EnhancedEventEmitter { /** * Consumer id. diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index f34ae1fe64..dfc5312bed 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -1,7 +1,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - DataConsumerInterface, + DataConsumer, DataConsumerType, DataConsumerDump, DataConsumerStat, @@ -40,7 +40,7 @@ const logger = new Logger('DataConsumer'); export class DataConsumerImpl extends EnhancedEventEmitter - implements DataConsumerInterface + implements DataConsumer { // Internal data. readonly #internal: DataConsumerInternal; diff --git a/node/src/DataConsumerTypes.ts b/node/src/DataConsumerTypes.ts index 2a4c6f6a60..f3f1b175dc 100644 --- a/node/src/DataConsumerTypes.ts +++ b/node/src/DataConsumerTypes.ts @@ -102,9 +102,8 @@ export type DataConsumerObserverEvents = { resume: []; }; -export interface DataConsumerInterface< - DataConsumerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export interface DataConsumer + extends EnhancedEventEmitter { /** * DataConsumer id. */ diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index d1f1be3e19..eb068aa0a9 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -1,7 +1,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - DataProducerInterface, + DataProducer, DataProducerType, DataProducerDump, DataProducerStat, @@ -36,7 +36,7 @@ const logger = new Logger('DataProducer'); export class DataProducerImpl extends EnhancedEventEmitter - implements DataProducerInterface + implements DataProducer { // Internal data. readonly #internal: DataProducerInternal; diff --git a/node/src/DataProducerTypes.ts b/node/src/DataProducerTypes.ts index ab71db3adc..b0dd2eefa8 100644 --- a/node/src/DataProducerTypes.ts +++ b/node/src/DataProducerTypes.ts @@ -75,9 +75,8 @@ export type DataProducerObserverEvents = { resume: []; }; -export interface DataProducerInterface< - DataProducerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export interface DataProducer + extends EnhancedEventEmitter { /** * DataProducer id. */ diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index 2c005092e3..abc7cd24e3 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -1,14 +1,14 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - DirectTransportInterface, + DirectTransport, DirectTransportDump, DirectTransportStat, DirectTransportEvents, DirectTransportObserver, DirectTransportObserverEvents, } from './DirectTransportTypes'; -import { TransportInterface, BaseTransportDump } from './TransportTypes'; +import { Transport, BaseTransportDump } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -44,7 +44,7 @@ export class DirectTransportImpl< DirectTransportEvents, DirectTransportObserver > - implements TransportInterface, DirectTransportInterface + implements Transport, DirectTransport { // DirectTransport data. // eslint-disable-next-line no-unused-private-class-members diff --git a/node/src/DirectTransportTypes.ts b/node/src/DirectTransportTypes.ts index 4205c0110e..97d7c63b90 100644 --- a/node/src/DirectTransportTypes.ts +++ b/node/src/DirectTransportTypes.ts @@ -1,6 +1,6 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { - TransportInterface, + Transport, BaseTransportDump, BaseTransportStats, TransportEvents, @@ -40,9 +40,9 @@ export type DirectTransportObserverEvents = TransportObserverEvents & { rtcp: [Buffer]; }; -export interface DirectTransportInterface< +export interface DirectTransport< DirectTransportAppData extends AppData = AppData, -> extends TransportInterface< +> extends Transport< DirectTransportAppData, DirectTransportEvents, DirectTransportObserver diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index e92095971e..fc4f0e9ac4 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -3,7 +3,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; import { - PipeTransportInterface, + PipeTransport, PipeConsumerOptions, PipeTransportDump, PipeTransportStat, @@ -11,11 +11,7 @@ import { PipeTransportObserver, PipeTransportObserverEvents, } from './PipeTransportTypes'; -import { - TransportInterface, - TransportTuple, - SctpState, -} from './TransportTypes'; +import { Transport, TransportTuple, SctpState } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -25,8 +21,8 @@ import { parseTuple, parseTransportTraceEventData, } from './Transport'; -import { ProducerInterface } from './ProducerTypes'; -import { ConsumerInterface, ConsumerType } from './ConsumerTypes'; +import { Producer } from './ProducerTypes'; +import { Consumer, ConsumerType } from './ConsumerTypes'; import { ConsumerImpl } from './Consumer'; import { RtpParameters, @@ -63,13 +59,13 @@ export type PipeTransportData = { const logger = new Logger('PipeTransport'); -export class PipeTransport +export class PipeTransportImpl extends TransportImpl< PipeTransportAppData, PipeTransportEvents, PipeTransportObserver > - implements TransportInterface, PipeTransportInterface + implements Transport, PipeTransport { // PipeTransport data. readonly #data: PipeTransportData; @@ -215,9 +211,7 @@ export class PipeTransport async consume({ producerId, appData, - }: PipeConsumerOptions): Promise< - ConsumerInterface - > { + }: PipeConsumerOptions): Promise> { logger.debug('consume()'); if (!producerId || typeof producerId !== 'string') { @@ -268,7 +262,7 @@ export class PipeTransport type: 'pipe' as ConsumerType, }; - const consumer: ConsumerInterface = new ConsumerImpl({ + const consumer: Consumer = new ConsumerImpl({ internal: { ...this.internal, consumerId, @@ -383,7 +377,7 @@ function createConsumeRequest({ }: { builder: flatbuffers.Builder; consumerId: string; - producer: ProducerInterface; + producer: Producer; rtpParameters: RtpParameters; }): number { // Build the request. diff --git a/node/src/PipeTransportTypes.ts b/node/src/PipeTransportTypes.ts index d60ce63ac1..351adaed1f 100644 --- a/node/src/PipeTransportTypes.ts +++ b/node/src/PipeTransportTypes.ts @@ -1,6 +1,6 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { - TransportInterface, + Transport, TransportListenInfo, TransportListenIp, TransportTuple, @@ -10,7 +10,7 @@ import { TransportEvents, TransportObserverEvents, } from './TransportTypes'; -import { ConsumerInterface } from './ConsumerTypes'; +import { Consumer } from './ConsumerTypes'; import { SrtpParameters } from './SrtpParameters'; import { SctpParameters, NumSctpStreams } from './SctpParameters'; import { Either, AppData } from './types'; @@ -119,9 +119,8 @@ export type PipeTransportObserverEvents = TransportObserverEvents & { sctpstatechange: [SctpState]; }; -export interface PipeTransportInterface< - PipeTransportAppData extends AppData = AppData, -> extends TransportInterface< +export interface PipeTransport + extends Transport< PipeTransportAppData, PipeTransportEvents, PipeTransportObserver @@ -190,7 +189,5 @@ export interface PipeTransportInterface< consume({ producerId, appData, - }: PipeConsumerOptions): Promise< - ConsumerInterface - >; + }: PipeConsumerOptions): Promise>; } diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index 9993e79ff8..589cbe7415 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -2,18 +2,14 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - PlainTransportInterface, + PlainTransport, PlainTransportDump, PlainTransportStat, PlainTransportEvents, PlainTransportObserver, PlainTransportObserverEvents, } from './PlainTransportTypes'; -import { - TransportInterface, - TransportTuple, - SctpState, -} from './TransportTypes'; +import { Transport, TransportTuple, SctpState } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -58,7 +54,7 @@ export class PlainTransportImpl PlainTransportEvents, PlainTransportObserver > - implements TransportInterface, PlainTransportInterface + implements Transport, PlainTransport { // PlainTransport data. readonly #data: PlainTransportData; diff --git a/node/src/PlainTransportTypes.ts b/node/src/PlainTransportTypes.ts index accc461d26..d4a55833e9 100644 --- a/node/src/PlainTransportTypes.ts +++ b/node/src/PlainTransportTypes.ts @@ -1,6 +1,6 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { - TransportInterface, + Transport, TransportListenInfo, TransportListenIp, TransportTuple, @@ -131,9 +131,8 @@ export type PlainTransportObserverEvents = TransportObserverEvents & { sctpstatechange: [SctpState]; }; -export interface PlainTransportInterface< - PlainTransportAppData extends AppData = AppData, -> extends TransportInterface< +export interface PlainTransport + extends Transport< PlainTransportAppData, PlainTransportEvents, PlainTransportObserver diff --git a/node/src/Producer.ts b/node/src/Producer.ts index f0f72e9d9e..79ad9a8b34 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -1,7 +1,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - ProducerInterface, + Producer, ProducerType, ProducerScore, ProducerVideoOrientation, @@ -43,7 +43,7 @@ type ProducerData = { export class ProducerImpl extends EnhancedEventEmitter - implements ProducerInterface + implements Producer { // Internal data. readonly #internal: ProducerInternal; diff --git a/node/src/ProducerTypes.ts b/node/src/ProducerTypes.ts index 8eadc1f66d..c6fbd1404e 100644 --- a/node/src/ProducerTypes.ts +++ b/node/src/ProducerTypes.ts @@ -150,7 +150,7 @@ export type ProducerObserverEvents = { trace: [ProducerTraceEventData]; }; -export interface ProducerInterface +export interface Producer extends EnhancedEventEmitter { /** * Producer id. diff --git a/node/src/Router.ts b/node/src/Router.ts index f1aadeed73..8b0f572dea 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -4,7 +4,7 @@ import * as ortc from './ortc'; import { InvalidStateError } from './errors'; import { Channel } from './Channel'; import { - RouterInterface, + Router, PipeToRouterOptions, PipeToRouterResult, PipeTransportPair, @@ -14,52 +14,49 @@ import { RouterObserverEvents, } from './RouterTypes'; import { - TransportInterface, + Transport, TransportListenIp, TransportProtocol, } from './TransportTypes'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; import { - WebRtcTransportInterface, + WebRtcTransport, WebRtcTransportOptions, } from './WebRtcTransportTypes'; import { WebRtcTransportImpl, parseWebRtcTransportDumpResponse, } from './WebRtcTransport'; -import { - PlainTransportInterface, - PlainTransportOptions, -} from './PlainTransportTypes'; +import { PlainTransport, PlainTransportOptions } from './PlainTransportTypes'; import { PlainTransportImpl, parsePlainTransportDumpResponse, } from './PlainTransport'; +import { PipeTransport, PipeTransportOptions } from './PipeTransportTypes'; import { - PipeTransportInterface, - PipeTransportOptions, -} from './PipeTransportTypes'; -import { PipeTransport, parsePipeTransportDumpResponse } from './PipeTransport'; + PipeTransportImpl, + parsePipeTransportDumpResponse, +} from './PipeTransport'; import { - DirectTransportInterface, + DirectTransport, DirectTransportOptions, } from './DirectTransportTypes'; import { DirectTransportImpl, parseDirectTransportDumpResponse, } from './DirectTransport'; -import { ProducerInterface } from './ProducerTypes'; -import { ConsumerInterface } from './ConsumerTypes'; -import { DataProducerInterface } from './DataProducerTypes'; -import { DataConsumerInterface } from './DataConsumerTypes'; -import { RtpObserverInterface } from './RtpObserverTypes'; +import { Producer } from './ProducerTypes'; +import { Consumer } from './ConsumerTypes'; +import { DataProducer } from './DataProducerTypes'; +import { DataConsumer } from './DataConsumerTypes'; +import { RtpObserver } from './RtpObserverTypes'; import { - ActiveSpeakerObserverInterface, + ActiveSpeakerObserver, ActiveSpeakerObserverOptions, } from './ActiveSpeakerObserverTypes'; import { ActiveSpeakerObserverImpl } from './ActiveSpeakerObserver'; import { - AudioLevelObserverInterface, + AudioLevelObserver, AudioLevelObserverOptions, } from './AudioLevelObserverTypes'; import { AudioLevelObserverImpl } from './AudioLevelObserver'; @@ -98,7 +95,7 @@ const logger = new Logger('Router'); export class RouterImpl extends EnhancedEventEmitter - implements RouterInterface + implements Router { // Internal data. readonly #internal: RouterInternal; @@ -116,16 +113,16 @@ export class RouterImpl #appData: RouterAppData; // Transports map. - readonly #transports: Map = new Map(); + readonly #transports: Map = new Map(); // Producers map. - readonly #producers: Map = new Map(); + readonly #producers: Map = new Map(); // RtpObservers map. - readonly #rtpObservers: Map = new Map(); + readonly #rtpObservers: Map = new Map(); // DataProducers map. - readonly #dataProducers: Map = new Map(); + readonly #dataProducers: Map = new Map(); // Map of PipeTransport pair Promises indexed by the id of the Router in // which pipeToRouter() was called. @@ -188,7 +185,7 @@ export class RouterImpl * * @private */ - get transportsForTesting(): Map { + get transportsForTesting(): Map { return this.#transports; } @@ -308,7 +305,7 @@ export class RouterImpl iceConsentTimeout = 30, appData, }: WebRtcTransportOptions): Promise< - WebRtcTransportInterface + WebRtcTransport > { logger.debug('createWebRtcTransport()'); @@ -474,7 +471,7 @@ export class RouterImpl const webRtcTransportData = parseWebRtcTransportDumpResponse(data); - const transport: WebRtcTransportInterface = + const transport: WebRtcTransport = new WebRtcTransportImpl({ internal: { ...this.#internal, @@ -485,12 +482,11 @@ export class RouterImpl appData, getRouterRtpCapabilities: (): RtpCapabilities => this.#data.rtpCapabilities, - getProducerById: (producerId: string): ProducerInterface | undefined => + getProducerById: (producerId: string): Producer | undefined => this.#producers.get(producerId), getDataProducerById: ( dataProducerId: string - ): DataProducerInterface | undefined => - this.#dataProducers.get(dataProducerId), + ): DataProducer | undefined => this.#dataProducers.get(dataProducerId), }); this.#transports.set(transport.id, transport); @@ -498,16 +494,16 @@ export class RouterImpl transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: ProducerInterface) => + transport.on('@newproducer', (producer: Producer) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: ProducerInterface) => + transport.on('@producerclose', (producer: Producer) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => + transport.on('@newdataproducer', (dataProducer: DataProducer) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => + transport.on('@dataproducerclose', (dataProducer: DataProducer) => this.#dataProducers.delete(dataProducer.id) ); @@ -536,7 +532,7 @@ export class RouterImpl srtpCryptoSuite = 'AES_CM_128_HMAC_SHA1_80', appData, }: PlainTransportOptions): Promise< - PlainTransportInterface + PlainTransport > { logger.debug('createPlainTransport()'); @@ -644,7 +640,7 @@ export class RouterImpl const plainTransportData = parsePlainTransportDumpResponse(data); - const transport: PlainTransportInterface = + const transport: PlainTransport = new PlainTransportImpl({ internal: { ...this.#internal, @@ -655,12 +651,11 @@ export class RouterImpl appData, getRouterRtpCapabilities: (): RtpCapabilities => this.#data.rtpCapabilities, - getProducerById: (producerId: string): ProducerInterface | undefined => + getProducerById: (producerId: string): Producer | undefined => this.#producers.get(producerId), getDataProducerById: ( dataProducerId: string - ): DataProducerInterface | undefined => - this.#dataProducers.get(dataProducerId), + ): DataProducer | undefined => this.#dataProducers.get(dataProducerId), }); this.#transports.set(transport.id, transport); @@ -668,16 +663,16 @@ export class RouterImpl transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: ProducerInterface) => + transport.on('@newproducer', (producer: Producer) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: ProducerInterface) => + transport.on('@producerclose', (producer: Producer) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => + transport.on('@newdataproducer', (dataProducer: DataProducer) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => + transport.on('@dataproducerclose', (dataProducer: DataProducer) => this.#dataProducers.delete(dataProducer.id) ); @@ -699,7 +694,7 @@ export class RouterImpl enableSrtp = false, appData, }: PipeTransportOptions): Promise< - PipeTransportInterface + PipeTransport > { logger.debug('createPipeTransport()'); @@ -782,8 +777,8 @@ export class RouterImpl const plainTransportData = parsePipeTransportDumpResponse(data); - const transport: PipeTransportInterface = - new PipeTransport({ + const transport: PipeTransport = + new PipeTransportImpl({ internal: { ...this.#internal, transportId, @@ -793,12 +788,11 @@ export class RouterImpl appData, getRouterRtpCapabilities: (): RtpCapabilities => this.#data.rtpCapabilities, - getProducerById: (producerId: string): ProducerInterface | undefined => + getProducerById: (producerId: string): Producer | undefined => this.#producers.get(producerId), getDataProducerById: ( dataProducerId: string - ): DataProducerInterface | undefined => - this.#dataProducers.get(dataProducerId), + ): DataProducer | undefined => this.#dataProducers.get(dataProducerId), }); this.#transports.set(transport.id, transport); @@ -806,16 +800,16 @@ export class RouterImpl transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: ProducerInterface) => + transport.on('@newproducer', (producer: Producer) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: ProducerInterface) => + transport.on('@producerclose', (producer: Producer) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => + transport.on('@newdataproducer', (dataProducer: DataProducer) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => + transport.on('@dataproducerclose', (dataProducer: DataProducer) => this.#dataProducers.delete(dataProducer.id) ); @@ -832,7 +826,7 @@ export class RouterImpl }: DirectTransportOptions = { maxMessageSize: 262144, } - ): Promise> { + ): Promise> { logger.debug('createDirectTransport()'); if (typeof maxMessageSize !== 'number' || maxMessageSize < 0) { @@ -877,7 +871,7 @@ export class RouterImpl const directTransportData = parseDirectTransportDumpResponse(data); - const transport: DirectTransportInterface = + const transport: DirectTransport = new DirectTransportImpl({ internal: { ...this.#internal, @@ -888,12 +882,11 @@ export class RouterImpl appData, getRouterRtpCapabilities: (): RtpCapabilities => this.#data.rtpCapabilities, - getProducerById: (producerId: string): ProducerInterface | undefined => + getProducerById: (producerId: string): Producer | undefined => this.#producers.get(producerId), getDataProducerById: ( dataProducerId: string - ): DataProducerInterface | undefined => - this.#dataProducers.get(dataProducerId), + ): DataProducer | undefined => this.#dataProducers.get(dataProducerId), }); this.#transports.set(transport.id, transport); @@ -901,16 +894,16 @@ export class RouterImpl transport.on('@listenserverclose', () => this.#transports.delete(transport.id) ); - transport.on('@newproducer', (producer: ProducerInterface) => + transport.on('@newproducer', (producer: Producer) => this.#producers.set(producer.id, producer) ); - transport.on('@producerclose', (producer: ProducerInterface) => + transport.on('@producerclose', (producer: Producer) => this.#producers.delete(producer.id) ); - transport.on('@newdataproducer', (dataProducer: DataProducerInterface) => + transport.on('@newdataproducer', (dataProducer: DataProducer) => this.#dataProducers.set(dataProducer.id, dataProducer) ); - transport.on('@dataproducerclose', (dataProducer: DataProducerInterface) => + transport.on('@dataproducerclose', (dataProducer: DataProducer) => this.#dataProducers.delete(dataProducer.id) ); @@ -966,8 +959,8 @@ export class RouterImpl }; } - let producer: ProducerInterface | undefined; - let dataProducer: DataProducerInterface | undefined; + let producer: Producer | undefined; + let dataProducer: DataProducer | undefined; if (producerId) { producer = this.#producers.get(producerId); @@ -987,8 +980,8 @@ export class RouterImpl let pipeTransportPairPromise = this.#mapRouterPairPipeTransportPairPromise.get(pipeTransportPairKey); let pipeTransportPair: PipeTransportPair; - let localPipeTransport: PipeTransportInterface; - let remotePipeTransport: PipeTransportInterface; + let localPipeTransport: PipeTransport; + let remotePipeTransport: PipeTransport; if (pipeTransportPairPromise) { pipeTransportPair = await pipeTransportPairPromise; @@ -1079,8 +1072,8 @@ export class RouterImpl } if (producer) { - let pipeConsumer: ConsumerInterface | undefined; - let pipeProducer: ProducerInterface | undefined; + let pipeConsumer: Consumer | undefined; + let pipeProducer: Producer | undefined; try { pipeConsumer = await localPipeTransport!.consume({ @@ -1136,8 +1129,8 @@ export class RouterImpl throw error; } } else if (dataProducer) { - let pipeDataConsumer: DataConsumerInterface | undefined; - let pipeDataProducer: DataProducerInterface | undefined; + let pipeDataConsumer: DataConsumer | undefined; + let pipeDataProducer: DataProducer | undefined; try { pipeDataConsumer = await localPipeTransport!.consumeData({ @@ -1220,7 +1213,7 @@ export class RouterImpl interval = 300, appData, }: ActiveSpeakerObserverOptions = {}): Promise< - ActiveSpeakerObserverInterface + ActiveSpeakerObserver > { logger.debug('createActiveSpeakerObserver()'); @@ -1248,7 +1241,7 @@ export class RouterImpl this.#internal.routerId ); - const activeSpeakerObserver: ActiveSpeakerObserverInterface = + const activeSpeakerObserver: ActiveSpeakerObserver = new ActiveSpeakerObserverImpl({ internal: { ...this.#internal, @@ -1256,7 +1249,7 @@ export class RouterImpl }, channel: this.#channel, appData, - getProducerById: (producerId: string): ProducerInterface | undefined => + getProducerById: (producerId: string): Producer | undefined => this.#producers.get(producerId), }); @@ -1279,7 +1272,7 @@ export class RouterImpl interval = 1000, appData, }: AudioLevelObserverOptions = {}): Promise< - AudioLevelObserverInterface + AudioLevelObserver > { logger.debug('createAudioLevelObserver()'); @@ -1321,7 +1314,7 @@ export class RouterImpl this.#internal.routerId ); - const audioLevelObserver: AudioLevelObserverInterface = + const audioLevelObserver: AudioLevelObserver = new AudioLevelObserverImpl({ internal: { ...this.#internal, @@ -1329,7 +1322,7 @@ export class RouterImpl }, channel: this.#channel, appData, - getProducerById: (producerId: string): ProducerInterface | undefined => + getProducerById: (producerId: string): Producer | undefined => this.#producers.get(producerId), }); diff --git a/node/src/RouterTypes.ts b/node/src/RouterTypes.ts index fc0419c7fa..accbd51b11 100644 --- a/node/src/RouterTypes.ts +++ b/node/src/RouterTypes.ts @@ -1,36 +1,30 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { - TransportInterface, + Transport, TransportListenInfo, TransportListenIp, } from './TransportTypes'; import { - WebRtcTransportInterface, + WebRtcTransport, WebRtcTransportOptions, } from './WebRtcTransportTypes'; +import { PlainTransport, PlainTransportOptions } from './PlainTransportTypes'; +import { PipeTransport, PipeTransportOptions } from './PipeTransportTypes'; import { - PlainTransportInterface, - PlainTransportOptions, -} from './PlainTransportTypes'; -import { - PipeTransportInterface, - PipeTransportOptions, -} from './PipeTransportTypes'; -import { - DirectTransportInterface, + DirectTransport, DirectTransportOptions, } from './DirectTransportTypes'; -import { ProducerInterface } from './ProducerTypes'; -import { ConsumerInterface } from './ConsumerTypes'; -import { DataProducerInterface } from './DataProducerTypes'; -import { DataConsumerInterface } from './DataConsumerTypes'; -import { RtpObserverInterface } from './RtpObserverTypes'; +import { Producer } from './ProducerTypes'; +import { Consumer } from './ConsumerTypes'; +import { DataProducer } from './DataProducerTypes'; +import { DataConsumer } from './DataConsumerTypes'; +import { RtpObserver } from './RtpObserverTypes'; import { - ActiveSpeakerObserverInterface, + ActiveSpeakerObserver, ActiveSpeakerObserverOptions, } from './ActiveSpeakerObserverTypes'; import { - AudioLevelObserverInterface, + AudioLevelObserver, AudioLevelObserverOptions, } from './AudioLevelObserverTypes'; import { RtpCapabilities, RtpCodecCapability } from './RtpParameters'; @@ -63,7 +57,7 @@ export type PipeToRouterOptions = { /** * Target Router instance. */ - router: RouterInterface; + router: Router; /** * Create a SCTP association. Default true. @@ -103,26 +97,26 @@ export type PipeToRouterResult = { /** * The Consumer created in the current Router. */ - pipeConsumer?: ConsumerInterface; + pipeConsumer?: Consumer; /** * The Producer created in the target Router. */ - pipeProducer?: ProducerInterface; + pipeProducer?: Producer; /** * The DataConsumer created in the current Router. */ - pipeDataConsumer?: DataConsumerInterface; + pipeDataConsumer?: DataConsumer; /** * The DataProducer created in the target Router. */ - pipeDataProducer?: DataProducerInterface; + pipeDataProducer?: DataProducer; }; export type PipeTransportPair = { - [key: string]: PipeTransportInterface; + [key: string]: PipeTransport; }; export type RouterDump = { @@ -171,11 +165,11 @@ export type RouterObserver = EnhancedEventEmitter; export type RouterObserverEvents = { close: []; - newtransport: [TransportInterface]; - newrtpobserver: [RtpObserverInterface]; + newtransport: [Transport]; + newrtpobserver: [RtpObserver]; }; -export interface RouterInterface +export interface Router extends EnhancedEventEmitter { /** * Router id. @@ -229,28 +223,28 @@ export interface RouterInterface */ createWebRtcTransport( options: WebRtcTransportOptions - ): Promise>; + ): Promise>; /** * Create a PlainTransport. */ createPlainTransport( options: PlainTransportOptions - ): Promise>; + ): Promise>; /** * Create a PipeTransport. */ createPipeTransport( options: PipeTransportOptions - ): Promise>; + ): Promise>; /** * Create a DirectTransport. */ createDirectTransport( options?: DirectTransportOptions - ): Promise>; + ): Promise>; /** * Pipes the given Producer or DataProducer into another Router in same host. @@ -272,14 +266,14 @@ export interface RouterInterface ActiveSpeakerObserverAppData extends AppData = AppData, >( options?: ActiveSpeakerObserverOptions - ): Promise>; + ): Promise>; /** * Create an AudioLevelObserver. */ createAudioLevelObserver( options?: AudioLevelObserverOptions - ): Promise>; + ): Promise>; /** * Check whether the given RTP capabilities can consume the given Producer. diff --git a/node/src/RtpObserver.ts b/node/src/RtpObserver.ts index e9744be597..9b04126899 100644 --- a/node/src/RtpObserver.ts +++ b/node/src/RtpObserver.ts @@ -3,7 +3,7 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { RtpObserverEvents, RtpObserverObserver } from './RtpObserverTypes'; import { Channel } from './Channel'; import { RouterInternal } from './Router'; -import { ProducerInterface } from './ProducerTypes'; +import { Producer } from './ProducerTypes'; import { AppData } from './types'; import * as FbsRequest from './fbs/request'; import * as FbsRouter from './fbs/router'; @@ -13,7 +13,7 @@ export type RtpObserverConstructorOptions = { internal: RtpObserverObserverInternal; channel: Channel; appData?: RtpObserverAppData; - getProducerById: (producerId: string) => ProducerInterface | undefined; + getProducerById: (producerId: string) => Producer | undefined; }; type RtpObserverObserverInternal = RouterInternal & { @@ -45,7 +45,7 @@ export abstract class RtpObserverImpl< // Method to retrieve a Producer. protected readonly getProducerById: ( producerId: string - ) => ProducerInterface | undefined; + ) => Producer | undefined; // Observer instance. readonly #observer: Observer; diff --git a/node/src/RtpObserverTypes.ts b/node/src/RtpObserverTypes.ts index d745b57940..15a6bcdad5 100644 --- a/node/src/RtpObserverTypes.ts +++ b/node/src/RtpObserverTypes.ts @@ -1,5 +1,5 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { ProducerInterface } from './ProducerTypes'; +import { Producer } from './ProducerTypes'; import { AppData } from './types'; export type RtpObserverEvents = { @@ -16,11 +16,11 @@ export type RtpObserverObserverEvents = { close: []; pause: []; resume: []; - addproducer: [ProducerInterface]; - removeproducer: [ProducerInterface]; + addproducer: [Producer]; + removeproducer: [Producer]; }; -export interface RtpObserverInterface< +export interface RtpObserver< RtpObserverAppData extends AppData = AppData, Events extends RtpObserverEvents = RtpObserverEvents, Observer extends RtpObserverObserver = RtpObserverObserver, diff --git a/node/src/Transport.ts b/node/src/Transport.ts index 4b7a7beae4..8cba700abe 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -3,7 +3,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; import { - TransportInterface, + Transport, TransportProtocol, TransportPortRange, TransportSocketFlags, @@ -25,21 +25,21 @@ import { WebRtcTransportData } from './WebRtcTransport'; import { PlainTransportData } from './PlainTransport'; import { PipeTransportData } from './PipeTransport'; import { DirectTransportData } from './DirectTransport'; -import { ProducerInterface, ProducerOptions } from './ProducerTypes'; +import { Producer, ProducerOptions } from './ProducerTypes'; import { ProducerImpl, producerTypeFromFbs, producerTypeToFbs, } from './Producer'; import { - ConsumerInterface, + Consumer, ConsumerOptions, ConsumerType, ConsumerLayers, } from './ConsumerTypes'; import { ConsumerImpl } from './Consumer'; import { - DataProducerInterface, + DataProducer, DataProducerOptions, DataProducerType, } from './DataProducerTypes'; @@ -49,7 +49,7 @@ import { parseDataProducerDumpResponse, } from './DataProducer'; import { - DataConsumerInterface, + DataConsumer, DataConsumerOptions, DataConsumerType, } from './DataConsumerTypes'; @@ -90,10 +90,8 @@ export type TransportConstructorOptions = { channel: Channel; appData?: TransportAppData; getRouterRtpCapabilities: () => RtpCapabilities; - getProducerById: (producerId: string) => ProducerInterface | undefined; - getDataProducerById: ( - dataProducerId: string - ) => DataProducerInterface | undefined; + getProducerById: (producerId: string) => Producer | undefined; + getDataProducerById: (dataProducerId: string) => DataProducer | undefined; }; export type TransportInternal = RouterInternal & { @@ -114,7 +112,7 @@ export abstract class TransportImpl< Observer extends TransportObserver = TransportObserver, > extends EnhancedEventEmitter - implements TransportInterface + implements Transport { // Internal data. protected readonly internal: TransportInternal; @@ -137,26 +135,24 @@ export abstract class TransportImpl< // Method to retrieve a Producer. protected readonly getProducerById: ( producerId: string - ) => ProducerInterface | undefined; + ) => Producer | undefined; // Method to retrieve a DataProducer. protected readonly getDataProducerById: ( dataProducerId: string - ) => DataProducerInterface | undefined; + ) => DataProducer | undefined; // Producers map. - readonly #producers: Map = new Map(); + readonly #producers: Map = new Map(); // Consumers map. - protected readonly consumers: Map = new Map(); + protected readonly consumers: Map = new Map(); // DataProducers map. - protected readonly dataProducers: Map = - new Map(); + protected readonly dataProducers: Map = new Map(); // DataConsumers map. - protected readonly dataConsumers: Map = - new Map(); + protected readonly dataConsumers: Map = new Map(); // RTCP CNAME for Producers. #cnameForProducers?: string; @@ -173,10 +169,6 @@ export abstract class TransportImpl< // Observer instance. readonly #observer: Observer; - /** - * @private - * @interface - */ constructor( { internal, @@ -456,9 +448,7 @@ export abstract class TransportImpl< paused = false, keyFrameRequestDelay, appData, - }: ProducerOptions): Promise< - ProducerInterface - > { + }: ProducerOptions): Promise> { logger.debug('produce()'); if (id && this.#producers.has(id)) { @@ -486,7 +476,8 @@ export abstract class TransportImpl< // Don't do this in PipeTransports since there we must keep CNAME value in // each Producer. - if (this.constructor.name !== 'PipeTransport') { + // TODO: This is error prune if we rename the class name. + if (this.constructor.name !== 'PipeTransportImpl') { // If CNAME is given and we don't have yet a CNAME for Producers in this // Transport, take it. if (!this.#cnameForProducers && clonedRtpParameters.rtcp?.cname) { @@ -551,7 +542,7 @@ export abstract class TransportImpl< consumableRtpParameters, }; - const producer: ProducerInterface = new ProducerImpl({ + const producer: Producer = new ProducerImpl({ internal: { ...this.internal, producerId, @@ -586,9 +577,7 @@ export abstract class TransportImpl< enableRtx, pipe = false, appData, - }: ConsumerOptions): Promise< - ConsumerInterface - > { + }: ConsumerOptions): Promise> { logger.debug('consume()'); if (!producerId || typeof producerId !== 'string') { @@ -675,7 +664,7 @@ export abstract class TransportImpl< type: pipe ? 'pipe' : (producer.type as ConsumerType), }; - const consumer: ConsumerInterface = new ConsumerImpl({ + const consumer: Consumer = new ConsumerImpl({ internal: { ...this.internal, consumerId, @@ -712,7 +701,7 @@ export abstract class TransportImpl< paused = false, appData, }: DataProducerOptions = {}): Promise< - DataProducerInterface + DataProducer > { logger.debug('produceData()'); @@ -730,7 +719,8 @@ export abstract class TransportImpl< >(sctpStreamParameters); // If this is not a DirectTransport, sctpStreamParameters are required. - if (this.constructor.name !== 'DirectTransport') { + // TODO: This is error prune if we rename the class name. + if (this.constructor.name !== 'DirectTransportImpl') { type = 'sctp'; // This may throw. @@ -774,7 +764,7 @@ export abstract class TransportImpl< const dump = parseDataProducerDumpResponse(produceDataResponse); - const dataProducer: DataProducerInterface = + const dataProducer: DataProducer = new DataProducerImpl({ internal: { ...this.internal, @@ -814,7 +804,7 @@ export abstract class TransportImpl< subchannels, appData, }: DataConsumerOptions): Promise< - DataConsumerInterface + DataConsumer > { logger.debug('consumeData()'); @@ -836,7 +826,8 @@ export abstract class TransportImpl< // If this is not a DirectTransport, use sctpStreamParameters from the // DataProducer (if type 'sctp') unless they are given in method parameters. - if (this.constructor.name !== 'DirectTransport') { + // TODO: This is error prune if we rename the class name. + if (this.constructor.name !== 'DirectTransportImpl') { type = 'sctp'; sctpStreamParameters = @@ -907,7 +898,7 @@ export abstract class TransportImpl< const dump = parseDataConsumerDumpResponse(consumeDataResponse); - const dataConsumer: DataConsumerInterface = + const dataConsumer: DataConsumer = new DataConsumerImpl({ internal: { ...this.internal, @@ -1333,7 +1324,7 @@ function createConsumeRequest({ pipe, }: { builder: flatbuffers.Builder; - producer: ProducerInterface; + producer: Producer; consumerId: string; rtpParameters: RtpParameters; paused: boolean; diff --git a/node/src/TransportTypes.ts b/node/src/TransportTypes.ts index 0cedbc65fd..dc9ca99c2b 100644 --- a/node/src/TransportTypes.ts +++ b/node/src/TransportTypes.ts @@ -1,14 +1,8 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { ProducerInterface, ProducerOptions } from './ProducerTypes'; -import { ConsumerInterface, ConsumerOptions } from './ConsumerTypes'; -import { - DataProducerInterface, - DataProducerOptions, -} from './DataProducerTypes'; -import { - DataConsumerInterface, - DataConsumerOptions, -} from './DataConsumerTypes'; +import { Producer, ProducerOptions } from './ProducerTypes'; +import { Consumer, ConsumerOptions } from './ConsumerTypes'; +import { DataProducer, DataProducerOptions } from './DataProducerTypes'; +import { DataConsumer, DataConsumerOptions } from './DataConsumerTypes'; import { SctpParameters } from './SctpParameters'; import { AppData } from './types'; @@ -231,10 +225,10 @@ export type TransportEvents = { listenererror: [string, Error]; // Private events. '@close': []; - '@newproducer': [ProducerInterface]; - '@producerclose': [ProducerInterface]; - '@newdataproducer': [DataProducerInterface]; - '@dataproducerclose': [DataProducerInterface]; + '@newproducer': [Producer]; + '@producerclose': [Producer]; + '@newdataproducer': [DataProducer]; + '@dataproducerclose': [DataProducer]; '@listenserverclose': []; }; @@ -242,14 +236,14 @@ export type TransportObserver = EnhancedEventEmitter; export type TransportObserverEvents = { close: []; - newproducer: [ProducerInterface]; - newconsumer: [ConsumerInterface]; - newdataproducer: [DataProducerInterface]; - newdataconsumer: [DataConsumerInterface]; + newproducer: [Producer]; + newconsumer: [Consumer]; + newdataproducer: [DataProducer]; + newdataconsumer: [DataConsumer]; trace: [TransportTraceEventData]; }; -export interface TransportInterface< +export interface Transport< TransportAppData extends AppData = AppData, Events extends TransportEvents = TransportEvents, Observer extends TransportObserver = TransportObserver, @@ -358,7 +352,7 @@ export interface TransportInterface< */ produce( options: ProducerOptions - ): Promise>; + ): Promise>; /** * Create a Consumer. @@ -369,21 +363,21 @@ export interface TransportInterface< */ consume( options: ConsumerOptions - ): Promise>; + ): Promise>; /** * Create a DataProducer. */ produceData( options?: DataProducerOptions - ): Promise>; + ): Promise>; /** * Create a DataConsumer. */ consumeData( options: DataConsumerOptions - ): Promise>; + ): Promise>; /** * Enable 'trace' event. diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index 624f355197..e623c77d8b 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -2,7 +2,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { Channel } from './Channel'; import { - WebRtcServerInterface, + WebRtcServer, IpPort, IceUserNameFragment, TupleHash, @@ -11,7 +11,7 @@ import { WebRtcServerObserver, WebRtcServerObserverEvents, } from './WebRtcServerTypes'; -import { WebRtcTransportInterface } from './WebRtcTransportTypes'; +import { WebRtcTransport } from './WebRtcTransportTypes'; import { AppData } from './types'; import * as utils from './utils'; import { Body as RequestBody, Method } from './fbs/request'; @@ -26,7 +26,7 @@ const logger = new Logger('WebRtcServer'); export class WebRtcServerImpl extends EnhancedEventEmitter - implements WebRtcServerInterface + implements WebRtcServer { // Internal data. readonly #internal: WebRtcServerInternal; @@ -41,7 +41,7 @@ export class WebRtcServerImpl #appData: WebRtcServerAppData; // Transports map. - readonly #webRtcTransports: Map = new Map(); + readonly #webRtcTransports: Map = new Map(); // Observer instance. readonly #observer: WebRtcServerObserver = @@ -88,7 +88,7 @@ export class WebRtcServerImpl /** * Just for testing purposes. */ - get webRtcTransportsForTesting(): Map { + get webRtcTransportsForTesting(): Map { return this.#webRtcTransports; } @@ -166,7 +166,7 @@ export class WebRtcServerImpl return parseWebRtcServerDump(dump); } - handleWebRtcTransport(webRtcTransport: WebRtcTransportInterface): void { + handleWebRtcTransport(webRtcTransport: WebRtcTransport): void { this.#webRtcTransports.set(webRtcTransport.id, webRtcTransport); // Emit observer event. diff --git a/node/src/WebRtcServerTypes.ts b/node/src/WebRtcServerTypes.ts index 9a8e1e11e3..122c79c404 100644 --- a/node/src/WebRtcServerTypes.ts +++ b/node/src/WebRtcServerTypes.ts @@ -1,6 +1,6 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { TransportListenInfo } from './TransportTypes'; -import { WebRtcTransportInterface } from './WebRtcTransportTypes'; +import { WebRtcTransport } from './WebRtcTransportTypes'; import { AppData } from './types'; export type WebRtcServerOptions = @@ -57,13 +57,12 @@ export type WebRtcServerObserver = export type WebRtcServerObserverEvents = { close: []; - webrtctransporthandled: [WebRtcTransportInterface]; - webrtctransportunhandled: [WebRtcTransportInterface]; + webrtctransporthandled: [WebRtcTransport]; + webrtctransportunhandled: [WebRtcTransport]; }; -export interface WebRtcServerInterface< - WebRtcServerAppData extends AppData = AppData, -> extends EnhancedEventEmitter { +export interface WebRtcServer + extends EnhancedEventEmitter { /** * WebRtcServer id. */ @@ -109,5 +108,5 @@ export interface WebRtcServerInterface< /** * @private */ - handleWebRtcTransport(webRtcTransport: WebRtcTransportInterface): void; + handleWebRtcTransport(webRtcTransport: WebRtcTransport): void; } diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index 25f1d29854..d216856df8 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -2,7 +2,7 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import { - WebRtcTransportInterface, + WebRtcTransport, IceParameters, IceCandidate, DtlsParameters, @@ -20,11 +20,7 @@ import { WebRtcTransportObserver, WebRtcTransportObserverEvents, } from './WebRtcTransportTypes'; -import { - TransportInterface, - TransportTuple, - SctpState, -} from './TransportTypes'; +import { Transport, TransportTuple, SctpState } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -78,7 +74,7 @@ export class WebRtcTransportImpl< WebRtcTransportEvents, WebRtcTransportObserver > - implements TransportInterface, WebRtcTransportInterface + implements Transport, WebRtcTransport { // WebRtcTransport data. readonly #data: WebRtcTransportData; diff --git a/node/src/WebRtcTransportTypes.ts b/node/src/WebRtcTransportTypes.ts index b1ef621086..dbb38afd34 100644 --- a/node/src/WebRtcTransportTypes.ts +++ b/node/src/WebRtcTransportTypes.ts @@ -1,6 +1,6 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import { - TransportInterface, + Transport, TransportListenInfo, TransportListenIp, TransportProtocol, @@ -11,7 +11,7 @@ import { TransportEvents, TransportObserverEvents, } from './TransportTypes'; -import { WebRtcServerInterface } from './WebRtcServerTypes'; +import { WebRtcServer } from './WebRtcServerTypes'; import { SctpParameters, NumSctpStreams } from './SctpParameters'; import { Either, AppData } from './types'; @@ -111,7 +111,7 @@ type WebRtcTransportListenServer = { /** * Instance of WebRtcServer. */ - webRtcServer: WebRtcServerInterface; + webRtcServer: WebRtcServer; }; export type IceParameters = { @@ -216,9 +216,9 @@ export type WebRtcTransportObserverEvents = TransportObserverEvents & { sctpstatechange: [SctpState]; }; -export interface WebRtcTransportInterface< +export interface WebRtcTransport< WebRtcTransportAppData extends AppData = AppData, -> extends TransportInterface< +> extends Transport< WebRtcTransportAppData, WebRtcTransportEvents, WebRtcTransportObserver diff --git a/node/src/Worker.ts b/node/src/Worker.ts index 01137e9c21..95d63a0547 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -6,7 +6,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; import { - WorkerInterface, + Worker, WorkerSettings, WorkerUpdateableSettings, WorkerResourceUsage, @@ -16,12 +16,9 @@ import { WorkerObserverEvents, } from './WorkerTypes'; import { Channel } from './Channel'; -import { - WebRtcServerInterface, - WebRtcServerOptions, -} from './WebRtcServerTypes'; +import { WebRtcServer, WebRtcServerOptions } from './WebRtcServerTypes'; import { WebRtcServerImpl } from './WebRtcServer'; -import { RouterInterface, RouterOptions } from './RouterTypes'; +import { Router, RouterOptions } from './RouterTypes'; import { RouterImpl } from './Router'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; import { RtpCodecCapability } from './RtpParameters'; @@ -63,7 +60,7 @@ const workerLogger = new Logger('Worker'); export class WorkerImpl extends EnhancedEventEmitter - implements WorkerInterface + implements Worker { // mediasoup-worker child process. #child: ChildProcess; @@ -87,10 +84,10 @@ export class WorkerImpl #appData: WorkerAppData; // WebRtcServers set. - readonly #webRtcServers: Set = new Set(); + readonly #webRtcServers: Set = new Set(); // Routers set. - readonly #routers: Set = new Set(); + readonly #routers: Set = new Set(); // Observer instance. readonly #observer: WorkerObserver = @@ -334,14 +331,14 @@ export class WorkerImpl /** * Just for testing purposes. */ - get webRtcServersForTesting(): Set { + get webRtcServersForTesting(): Set { return this.#webRtcServers; } /** * Just for testing purposes. */ - get routersForTesting(): Set { + get routersForTesting(): Set { return this.#routers; } @@ -447,7 +444,7 @@ export class WorkerImpl listenInfos, appData, }: WebRtcServerOptions): Promise< - WebRtcServerInterface + WebRtcServer > { logger.debug('createWebRtcServer()'); @@ -489,7 +486,7 @@ export class WorkerImpl createWebRtcServerRequestOffset ); - const webRtcServer: WebRtcServerInterface = + const webRtcServer: WebRtcServer = new WebRtcServerImpl({ internal: { webRtcServerId }, channel: this.#channel, @@ -508,9 +505,7 @@ export class WorkerImpl async createRouter({ mediaCodecs, appData, - }: RouterOptions = {}): Promise< - RouterInterface - > { + }: RouterOptions = {}): Promise> { logger.debug('createRouter()'); if (appData && typeof appData !== 'object') { @@ -540,7 +535,7 @@ export class WorkerImpl ); const data = { rtpCapabilities }; - const router: RouterInterface = new RouterImpl({ + const router: Router = new RouterImpl({ internal: { routerId, }, diff --git a/node/src/WorkerTypes.ts b/node/src/WorkerTypes.ts index 5f468c7614..15e7a32b34 100644 --- a/node/src/WorkerTypes.ts +++ b/node/src/WorkerTypes.ts @@ -1,9 +1,6 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { - WebRtcServerInterface, - WebRtcServerOptions, -} from './WebRtcServerTypes'; -import { RouterInterface, RouterOptions } from './RouterTypes'; +import { WebRtcServer, WebRtcServerOptions } from './WebRtcServerTypes'; +import { Router, RouterOptions } from './RouterTypes'; import { AppData } from './types'; export type WorkerLogLevel = 'debug' | 'warn' | 'error' | 'none'; @@ -203,11 +200,11 @@ export type WorkerObserver = EnhancedEventEmitter; export type WorkerObserverEvents = { close: []; - newwebrtcserver: [WebRtcServerInterface]; - newrouter: [RouterInterface]; + newwebrtcserver: [WebRtcServer]; + newrouter: [Router]; }; -export interface WorkerInterface +export interface Worker extends EnhancedEventEmitter { /** * Worker process identifier (PID). @@ -271,12 +268,12 @@ export interface WorkerInterface */ createWebRtcServer( options: WebRtcServerOptions - ): Promise>; + ): Promise>; /** * Create a Router. */ createRouter( options?: RouterOptions - ): Promise>; + ): Promise>; } diff --git a/node/src/index.ts b/node/src/index.ts index f5b73483b5..bf3b13137b 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -1,6 +1,6 @@ import { Logger, LoggerEmitter } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { WorkerInterface, WorkerSettings } from './WorkerTypes'; +import { Worker, WorkerSettings } from './WorkerTypes'; import { WorkerImpl, workerBin } from './Worker'; import * as utils from './utils'; import { supportedRtpCapabilities } from './supportedRtpCapabilities'; @@ -27,7 +27,7 @@ export { parse as parseScalabilityMode } from './scalabilityModes'; export type Observer = EnhancedEventEmitter; export type ObserverEvents = { - newworker: [WorkerInterface]; + newworker: [Worker]; }; const observer: Observer = new EnhancedEventEmitter(); @@ -110,16 +110,14 @@ export async function createWorker< libwebrtcFieldTrials, disableLiburing, appData, -}: WorkerSettings = {}): Promise< - WorkerInterface -> { +}: WorkerSettings = {}): Promise> { logger.debug('createWorker()'); if (appData && typeof appData !== 'object') { throw new TypeError('if given, appData must be an object'); } - const worker: WorkerInterface = new WorkerImpl({ + const worker: Worker = new WorkerImpl({ logLevel, logTags, rtcMinPort, diff --git a/node/src/test/test-ActiveSpeakerObserver.ts b/node/src/test/test-ActiveSpeakerObserver.ts index f0d6c04d48..51a8d59190 100644 --- a/node/src/test/test-ActiveSpeakerObserver.ts +++ b/node/src/test/test-ActiveSpeakerObserver.ts @@ -5,8 +5,8 @@ import * as utils from '../utils'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; }; const ctx: TestContext = { diff --git a/node/src/test/test-AudioLevelObserver.ts b/node/src/test/test-AudioLevelObserver.ts index 4f3f716c0c..f1a1a5fb17 100644 --- a/node/src/test/test-AudioLevelObserver.ts +++ b/node/src/test/test-AudioLevelObserver.ts @@ -5,8 +5,8 @@ import * as utils from '../utils'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; }; const ctx: TestContext = { diff --git a/node/src/test/test-Consumer.ts b/node/src/test/test-Consumer.ts index e6f90b3492..cc69554cd4 100644 --- a/node/src/test/test-Consumer.ts +++ b/node/src/test/test-Consumer.ts @@ -17,12 +17,12 @@ type TestContext = { audioProducerOptions: mediasoup.types.ProducerOptions; videoProducerOptions: mediasoup.types.ProducerOptions; consumerDeviceCapabilities: mediasoup.types.RtpCapabilities; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; - webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; - webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; - audioProducer?: mediasoup.types.ProducerInterface; - videoProducer?: mediasoup.types.ProducerInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; + webRtcTransport1?: mediasoup.types.WebRtcTransport; + webRtcTransport2?: mediasoup.types.WebRtcTransport; + audioProducer?: mediasoup.types.Producer; + videoProducer?: mediasoup.types.Producer; }; const ctx: TestContext = { diff --git a/node/src/test/test-DataConsumer.ts b/node/src/test/test-DataConsumer.ts index 7b3c91a2d0..f61bb8291c 100644 --- a/node/src/test/test-DataConsumer.ts +++ b/node/src/test/test-DataConsumer.ts @@ -5,12 +5,12 @@ import * as utils from '../utils'; type TestContext = { dataProducerOptions: mediasoup.types.DataProducerOptions; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; - webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; - webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; - directTransport?: mediasoup.types.DirectTransportInterface; - dataProducer?: mediasoup.types.DataProducerInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; + webRtcTransport1?: mediasoup.types.WebRtcTransport; + webRtcTransport2?: mediasoup.types.WebRtcTransport; + directTransport?: mediasoup.types.DirectTransport; + dataProducer?: mediasoup.types.DataProducer; }; const ctx: TestContext = { diff --git a/node/src/test/test-DataProducer.ts b/node/src/test/test-DataProducer.ts index 61d6394768..4f490792ce 100644 --- a/node/src/test/test-DataProducer.ts +++ b/node/src/test/test-DataProducer.ts @@ -6,10 +6,10 @@ import * as utils from '../utils'; type TestContext = { dataProducerOptions1: mediasoup.types.DataProducerOptions; dataProducerOptions2: mediasoup.types.DataProducerOptions; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; - webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; - webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; + webRtcTransport1?: mediasoup.types.WebRtcTransport; + webRtcTransport2?: mediasoup.types.WebRtcTransport; }; const ctx: TestContext = { diff --git a/node/src/test/test-DirectTransport.ts b/node/src/test/test-DirectTransport.ts index 2380d96e18..a9f773220d 100644 --- a/node/src/test/test-DirectTransport.ts +++ b/node/src/test/test-DirectTransport.ts @@ -4,8 +4,8 @@ import { DirectTransportEvents } from '../DirectTransportTypes'; import { WorkerEvents } from '../types'; type TestContext = { - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; }; const ctx: TestContext = {}; diff --git a/node/src/test/test-PipeTransport.ts b/node/src/test/test-PipeTransport.ts index 86603da30f..1d7534ac04 100644 --- a/node/src/test/test-PipeTransport.ts +++ b/node/src/test/test-PipeTransport.ts @@ -15,17 +15,17 @@ type TestContext = { videoProducerOptions: mediasoup.types.ProducerOptions; dataProducerOptions: mediasoup.types.DataProducerOptions; consumerDeviceCapabilities: mediasoup.types.RtpCapabilities; - worker1?: mediasoup.types.WorkerInterface; - worker2?: mediasoup.types.WorkerInterface; - router1?: mediasoup.types.RouterInterface; - router2?: mediasoup.types.RouterInterface; - webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; - webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; - audioProducer?: mediasoup.types.ProducerInterface; - videoProducer?: mediasoup.types.ProducerInterface; - videoConsumer?: mediasoup.types.ConsumerInterface; - dataProducer?: mediasoup.types.DataProducerInterface; - dataConsumer?: mediasoup.types.DataConsumerInterface; + worker1?: mediasoup.types.Worker; + worker2?: mediasoup.types.Worker; + router1?: mediasoup.types.Router; + router2?: mediasoup.types.Router; + webRtcTransport1?: mediasoup.types.WebRtcTransport; + webRtcTransport2?: mediasoup.types.WebRtcTransport; + audioProducer?: mediasoup.types.Producer; + videoProducer?: mediasoup.types.Producer; + videoConsumer?: mediasoup.types.Consumer; + dataProducer?: mediasoup.types.DataProducer; + dataConsumer?: mediasoup.types.DataConsumer; }; const ctx: TestContext = { @@ -221,8 +221,8 @@ test('router.pipeToRouter() succeeds with audio', async () => { producerId: ctx.audioProducer!.id, router: ctx.router2!, })) as { - pipeConsumer: mediasoup.types.ConsumerInterface; - pipeProducer: mediasoup.types.ProducerInterface; + pipeConsumer: mediasoup.types.Consumer; + pipeProducer: mediasoup.types.Producer; }; const dump1 = await ctx.router1!.dump(); @@ -336,8 +336,8 @@ test('router.pipeToRouter() succeeds with video', async () => { producerId: ctx.videoProducer!.id, router: ctx.router2!, })) as { - pipeConsumer: mediasoup.types.ConsumerInterface; - pipeProducer: mediasoup.types.ProducerInterface; + pipeConsumer: mediasoup.types.Consumer; + pipeProducer: mediasoup.types.Producer; }; const dump1 = await ctx.router1!.dump(); @@ -937,8 +937,8 @@ test('router.pipeToRouter() succeeds with data', async () => { dataProducerId: ctx.dataProducer!.id, router: ctx.router2!, })) as { - pipeDataConsumer: mediasoup.types.DataConsumerInterface; - pipeDataProducer: mediasoup.types.DataProducerInterface; + pipeDataConsumer: mediasoup.types.DataConsumer; + pipeDataProducer: mediasoup.types.DataProducer; }; const dump1 = await ctx.router1!.dump(); @@ -1081,7 +1081,7 @@ test('router.pipeToRouter() called in two Routers passing one to each other as a const pipeTransportsB = new Map(); routerA.observer.on('newtransport', transport => { - if (transport.constructor.name !== 'PipeTransport') { + if (transport.constructor.name !== 'PipeTransportImpl') { return; } @@ -1090,7 +1090,7 @@ test('router.pipeToRouter() called in two Routers passing one to each other as a }); routerB.observer.on('newtransport', transport => { - if (transport.constructor.name !== 'PipeTransport') { + if (transport.constructor.name !== 'PipeTransportImpl') { return; } diff --git a/node/src/test/test-PlainTransport.ts b/node/src/test/test-PlainTransport.ts index c3c91b3b57..abd7c326b9 100644 --- a/node/src/test/test-PlainTransport.ts +++ b/node/src/test/test-PlainTransport.ts @@ -9,8 +9,8 @@ const IS_WINDOWS = os.platform() === 'win32'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; }; const ctx: TestContext = { diff --git a/node/src/test/test-Producer.ts b/node/src/test/test-Producer.ts index 0402ce0f6b..3cdeae6ffb 100644 --- a/node/src/test/test-Producer.ts +++ b/node/src/test/test-Producer.ts @@ -16,10 +16,10 @@ type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; audioProducerOptions: mediasoup.types.ProducerOptions; videoProducerOptions: mediasoup.types.ProducerOptions; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; - webRtcTransport1?: mediasoup.types.WebRtcTransportInterface; - webRtcTransport2?: mediasoup.types.WebRtcTransportInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; + webRtcTransport1?: mediasoup.types.WebRtcTransport; + webRtcTransport2?: mediasoup.types.WebRtcTransport; }; const ctx: TestContext = { diff --git a/node/src/test/test-Router.ts b/node/src/test/test-Router.ts index f584e1dacb..bc79574d9b 100644 --- a/node/src/test/test-Router.ts +++ b/node/src/test/test-Router.ts @@ -7,7 +7,7 @@ import * as utils from '../utils'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.WorkerInterface; + worker?: mediasoup.types.Worker; }; const ctx: TestContext = { diff --git a/node/src/test/test-WebRtcServer.ts b/node/src/test/test-WebRtcServer.ts index 10f695af21..2376e6569d 100644 --- a/node/src/test/test-WebRtcServer.ts +++ b/node/src/test/test-WebRtcServer.ts @@ -8,7 +8,7 @@ import { RouterImpl } from '../Router'; import { InvalidStateError } from '../errors'; type TestContext = { - worker?: mediasoup.types.WorkerInterface; + worker?: mediasoup.types.Worker; }; const ctx: TestContext = {}; diff --git a/node/src/test/test-WebRtcTransport.ts b/node/src/test/test-WebRtcTransport.ts index bba38bd7c2..8fad39909e 100644 --- a/node/src/test/test-WebRtcTransport.ts +++ b/node/src/test/test-WebRtcTransport.ts @@ -17,8 +17,8 @@ import * as FbsWebRtcTransport from '../fbs/web-rtc-transport'; type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; }; const ctx: TestContext = { diff --git a/node/src/test/test-Worker.ts b/node/src/test/test-Worker.ts index b9e9a1ec16..a00ba79fb0 100644 --- a/node/src/test/test-Worker.ts +++ b/node/src/test/test-Worker.ts @@ -43,7 +43,7 @@ test('createWorker() succeeds', async () => { expect(onObserverNewWorker).toHaveBeenCalledTimes(1); expect(onObserverNewWorker).toHaveBeenCalledWith(worker1); - expect(worker1.constructor.name).toBe('Worker'); + expect(worker1.constructor.name).toBe('WorkerImpl'); expect(typeof worker1.pid).toBe('number'); expect(worker1.closed).toBe(false); expect(worker1.died).toBe(false); @@ -67,7 +67,7 @@ test('createWorker() succeeds', async () => { appData: { foo: 456 }, }); - expect(worker2.constructor.name).toBe('Worker'); + expect(worker2.constructor.name).toBe('WorkerImpl'); expect(typeof worker2.pid).toBe('number'); expect(worker2.closed).toBe(false); expect(worker2.died).toBe(false); diff --git a/node/src/test/test-multiopus.ts b/node/src/test/test-multiopus.ts index 22b9484cc0..4b8ab50450 100644 --- a/node/src/test/test-multiopus.ts +++ b/node/src/test/test-multiopus.ts @@ -8,9 +8,9 @@ type TestContext = { mediaCodecs: mediasoup.types.RtpCodecCapability[]; audioProducerOptions: mediasoup.types.ProducerOptions; consumerDeviceCapabilities: mediasoup.types.RtpCapabilities; - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; - webRtcTransport?: mediasoup.types.WebRtcTransportInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; + webRtcTransport?: mediasoup.types.WebRtcTransport; }; const ctx: TestContext = { diff --git a/node/src/test/test-node-sctp.ts b/node/src/test/test-node-sctp.ts index cb4fb14f64..e344c1a484 100644 --- a/node/src/test/test-node-sctp.ts +++ b/node/src/test/test-node-sctp.ts @@ -6,11 +6,11 @@ import { enhancedOnce } from '../enhancedEvents'; import { WorkerEvents } from '../types'; type TestContext = { - worker?: mediasoup.types.WorkerInterface; - router?: mediasoup.types.RouterInterface; - plainTransport?: mediasoup.types.PlainTransportInterface; - dataProducer?: mediasoup.types.DataProducerInterface; - dataConsumer?: mediasoup.types.DataConsumerInterface; + worker?: mediasoup.types.Worker; + router?: mediasoup.types.Router; + plainTransport?: mediasoup.types.PlainTransport; + dataProducer?: mediasoup.types.DataProducer; + dataConsumer?: mediasoup.types.DataConsumer; udpSocket?: dgram.Socket; sctpSocket?: any; sctpSendStreamId?: number; From fd1f37fd6a553459aafbda6d1f13f7ffc31741b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sat, 9 Nov 2024 00:33:05 +0100 Subject: [PATCH 06/14] split RtpParameters.ts into rtpParametersTypes.ts and rtpParametersFbsUtils.ts and same for SCTP and SRTP files --- node/src/AudioLevelObserver.ts | 4 +- node/src/Consumer.ts | 17 +- node/src/ConsumerTypes.ts | 2 +- node/src/DataConsumer.ts | 16 +- node/src/DataConsumerTypes.ts | 2 +- node/src/DataProducer.ts | 6 +- node/src/DataProducerTypes.ts | 2 +- node/src/DirectTransport.ts | 2 +- node/src/PipeTransport.ts | 10 +- node/src/PipeTransportTypes.ts | 4 +- node/src/PlainTransport.ts | 6 +- node/src/PlainTransportTypes.ts | 4 +- node/src/Producer.ts | 15 +- node/src/ProducerTypes.ts | 2 +- node/src/Router.ts | 41 +- node/src/RouterTypes.ts | 4 +- node/src/Transport.ts | 41 +- node/src/TransportTypes.ts | 2 +- node/src/WebRtcServer.ts | 12 +- node/src/WebRtcTransport.ts | 6 +- node/src/WebRtcTransportTypes.ts | 2 +- node/src/Worker.ts | 13 +- node/src/fbsUtils.ts | 117 ++++++ node/src/index.ts | 3 +- node/src/ortc.ts | 4 +- ...Parameters.ts => rtpParametersFbsUtils.ts} | 381 +----------------- node/src/rtpParametersTypes.ts | 357 ++++++++++++++++ node/src/sctpParametersFbsUtils.ts | 54 +++ ...tpParameters.ts => sctpParametersTypes.ts} | 51 --- ...arameters.ts => srtpParametersFbsUtils.ts} | 25 +- node/src/srtpParametersTypes.ts | 23 ++ node/src/supportedRtpCapabilities.ts | 2 +- node/src/types.ts | 6 +- node/src/utils.ts | 144 ------- 34 files changed, 685 insertions(+), 695 deletions(-) create mode 100644 node/src/fbsUtils.ts rename node/src/{RtpParameters.ts => rtpParametersFbsUtils.ts} (55%) create mode 100644 node/src/rtpParametersTypes.ts create mode 100644 node/src/sctpParametersFbsUtils.ts rename node/src/{SctpParameters.ts => sctpParametersTypes.ts} (67%) rename node/src/{SrtpParameters.ts => srtpParametersFbsUtils.ts} (81%) create mode 100644 node/src/srtpParametersTypes.ts diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index 06e04b8ac2..accf6caf27 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -11,7 +11,7 @@ import { RtpObserver } from './RtpObserverTypes'; import { RtpObserverImpl, RtpObserverConstructorOptions } from './RtpObserver'; import { Producer } from './ProducerTypes'; import { AppData } from './types'; -import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import * as FbsAudioLevelObserver from './fbs/audio-level-observer'; @@ -66,7 +66,7 @@ export class AudioLevelObserverImpl< // Get the corresponding Producer instance and remove entries with // no Producer (it may have been closed in the meanwhile). - const volumes: AudioLevelObserverVolume[] = utils + const volumes: AudioLevelObserverVolume[] = fbsUtils .parseVector(notification, 'volumes', parseVolume) .map( ({ diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index 947d477b16..020fa92a82 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -25,15 +25,14 @@ import { import { Channel } from './Channel'; import { TransportInternal } from './Transport'; import { ProducerStat } from './ProducerTypes'; +import { MediaKind, RtpParameters } from './rtpParametersTypes'; import { - MediaKind, - RtpParameters, parseRtpEncodingParameters, parseRtpParameters, -} from './RtpParameters'; +} from './rtpParametersFbsUtils'; import { parseRtpStreamStats } from './RtpStream'; import { AppData } from './types'; -import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import { TraceDirection as FbsTraceDirection } from './fbs/common'; import * as FbsRequest from './fbs/request'; @@ -765,18 +764,18 @@ function parseBaseConsumerDump( rtpParameters: parseRtpParameters(data.rtpParameters()!), consumableRtpEncodings: data.consumableRtpEncodingsLength() > 0 - ? utils.parseVector( + ? fbsUtils.parseVector( data, 'consumableRtpEncodings', parseRtpEncodingParameters ) : undefined, - traceEventTypes: utils.parseVector( + traceEventTypes: fbsUtils.parseVector( data, 'traceEventTypes', consumerTraceEventTypeFromFbs ), - supportedCodecPayloadTypes: utils.parseVector( + supportedCodecPayloadTypes: fbsUtils.parseVector( data, 'supportedCodecPayloadTypes' ), @@ -830,7 +829,7 @@ function parsePipeConsumerDump( data: FbsConsumer.ConsumerDump ): PipeConsumerDump { const base = parseBaseConsumerDump(data.base()!); - const rtpStreams = utils.parseVector(data, 'rtpStreams', parseRtpStream); + const rtpStreams = fbsUtils.parseVector(data, 'rtpStreams', parseRtpStream); return { ...base, @@ -886,5 +885,5 @@ function parseConsumerDumpResponse( function parseConsumerStats( binary: FbsConsumer.GetStatsResponse ): (ConsumerStat | ProducerStat)[] { - return utils.parseVector(binary, 'stats', parseRtpStreamStats); + return fbsUtils.parseVector(binary, 'stats', parseRtpStreamStats); } diff --git a/node/src/ConsumerTypes.ts b/node/src/ConsumerTypes.ts index bc8c1ad0b2..103eeca565 100644 --- a/node/src/ConsumerTypes.ts +++ b/node/src/ConsumerTypes.ts @@ -5,7 +5,7 @@ import { RtpCapabilities, RtpEncodingParameters, RtpParameters, -} from './RtpParameters'; +} from './rtpParametersTypes'; import { RtpStreamSendStats } from './RtpStream'; import { AppData } from './types'; diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index dfc5312bed..1a925c57b4 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -11,12 +11,10 @@ import { } from './DataConsumerTypes'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; -import { - SctpStreamParameters, - parseSctpStreamParameters, -} from './SctpParameters'; +import { SctpStreamParameters } from './sctpParametersTypes'; +import { parseSctpStreamParameters } from './sctpParametersFbsUtils'; import { AppData } from './types'; -import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import * as FbsTransport from './fbs/transport'; import * as FbsRequest from './fbs/request'; @@ -399,7 +397,7 @@ export class DataConsumerImpl response.body(data); // Update subchannels. - this.#subchannels = utils.parseVector(data, 'subchannels'); + this.#subchannels = fbsUtils.parseVector(data, 'subchannels'); } async addSubchannel(subchannel: number): Promise { @@ -425,7 +423,7 @@ export class DataConsumerImpl response.body(data); // Update subchannels. - this.#subchannels = utils.parseVector(data, 'subchannels'); + this.#subchannels = fbsUtils.parseVector(data, 'subchannels'); } async removeSubchannel(subchannel: number): Promise { @@ -451,7 +449,7 @@ export class DataConsumerImpl response.body(data); // Update subchannels. - this.#subchannels = utils.parseVector(data, 'subchannels'); + this.#subchannels = fbsUtils.parseVector(data, 'subchannels'); } private handleWorkerNotifications(): void { @@ -606,7 +604,7 @@ export function parseDataConsumerDumpResponse( bufferedAmountLowThreshold: data.bufferedAmountLowThreshold(), paused: data.paused(), dataProducerPaused: data.dataProducerPaused(), - subchannels: utils.parseVector(data, 'subchannels'), + subchannels: fbsUtils.parseVector(data, 'subchannels'), }; } diff --git a/node/src/DataConsumerTypes.ts b/node/src/DataConsumerTypes.ts index f3f1b175dc..1234873c91 100644 --- a/node/src/DataConsumerTypes.ts +++ b/node/src/DataConsumerTypes.ts @@ -1,5 +1,5 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { SctpStreamParameters } from './SctpParameters'; +import { SctpStreamParameters } from './sctpParametersTypes'; import { AppData } from './types'; export type DataConsumerOptions = diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index eb068aa0a9..2951d9e2a8 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -11,10 +11,8 @@ import { } from './DataProducerTypes'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; -import { - SctpStreamParameters, - parseSctpStreamParameters, -} from './SctpParameters'; +import { SctpStreamParameters } from './sctpParametersTypes'; +import { parseSctpStreamParameters } from './sctpParametersFbsUtils'; import { AppData } from './types'; import * as FbsTransport from './fbs/transport'; import * as FbsNotification from './fbs/notification'; diff --git a/node/src/DataProducerTypes.ts b/node/src/DataProducerTypes.ts index b0dd2eefa8..1690ecbc2d 100644 --- a/node/src/DataProducerTypes.ts +++ b/node/src/DataProducerTypes.ts @@ -1,5 +1,5 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { SctpStreamParameters } from './SctpParameters'; +import { SctpStreamParameters } from './sctpParametersTypes'; import { AppData } from './types'; export type DataProducerOptions = diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index abc7cd24e3..808523ebc4 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -16,7 +16,7 @@ import { parseBaseTransportStats, parseTransportTraceEventData, } from './Transport'; -import { SctpParameters } from './SctpParameters'; +import { SctpParameters } from './sctpParametersTypes'; import { AppData } from './types'; import { UnsupportedError } from './errors'; import { Event, Notification } from './fbs/notification'; diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index fc4f0e9ac4..614010266c 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -24,17 +24,17 @@ import { import { Producer } from './ProducerTypes'; import { Consumer, ConsumerType } from './ConsumerTypes'; import { ConsumerImpl } from './Consumer'; +import { RtpParameters } from './rtpParametersTypes'; import { - RtpParameters, serializeRtpEncodingParameters, serializeRtpParameters, -} from './RtpParameters'; -import { SctpParameters } from './SctpParameters'; +} from './rtpParametersFbsUtils'; +import { SctpParameters } from './sctpParametersTypes'; +import { SrtpParameters } from './srtpParametersTypes'; import { parseSrtpParameters, serializeSrtpParameters, - SrtpParameters, -} from './SrtpParameters'; +} from './srtpParametersFbsUtils'; import { AppData } from './types'; import { generateUUIDv4 } from './utils'; import { MediaKind as FbsMediaKind } from './fbs/rtp-parameters/media-kind'; diff --git a/node/src/PipeTransportTypes.ts b/node/src/PipeTransportTypes.ts index 351adaed1f..c0e18e2024 100644 --- a/node/src/PipeTransportTypes.ts +++ b/node/src/PipeTransportTypes.ts @@ -11,8 +11,8 @@ import { TransportObserverEvents, } from './TransportTypes'; import { Consumer } from './ConsumerTypes'; -import { SrtpParameters } from './SrtpParameters'; -import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { SrtpParameters } from './srtpParametersTypes'; +import { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; import { Either, AppData } from './types'; export type PipeTransportOptions< diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index 589cbe7415..6c57ff4947 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -19,12 +19,12 @@ import { parseBaseTransportStats, parseTransportTraceEventData, } from './Transport'; -import { SctpParameters } from './SctpParameters'; +import { SctpParameters } from './sctpParametersTypes'; +import { SrtpParameters } from './srtpParametersTypes'; import { parseSrtpParameters, serializeSrtpParameters, - SrtpParameters, -} from './SrtpParameters'; +} from './srtpParametersFbsUtils'; import { AppData } from './types'; import { Event, Notification } from './fbs/notification'; import * as FbsRequest from './fbs/request'; diff --git a/node/src/PlainTransportTypes.ts b/node/src/PlainTransportTypes.ts index d4a55833e9..04ef6aa76c 100644 --- a/node/src/PlainTransportTypes.ts +++ b/node/src/PlainTransportTypes.ts @@ -10,8 +10,8 @@ import { TransportEvents, TransportObserverEvents, } from './TransportTypes'; -import { SrtpParameters, SrtpCryptoSuite } from './SrtpParameters'; -import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { SrtpParameters, SrtpCryptoSuite } from './srtpParametersTypes'; +import { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; import { Either, AppData } from './types'; export type PlainTransportOptions< diff --git a/node/src/Producer.ts b/node/src/Producer.ts index 79ad9a8b34..07b1bba875 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -15,11 +15,12 @@ import { } from './ProducerTypes'; import { Channel } from './Channel'; import { TransportInternal } from './Transport'; -import { MediaKind, RtpParameters, parseRtpParameters } from './RtpParameters'; -import { Event, Notification } from './fbs/notification'; +import { MediaKind, RtpParameters } from './rtpParametersTypes'; +import { parseRtpParameters } from './rtpParametersFbsUtils'; import { parseRtpStreamRecvStats } from './RtpStream'; import { AppData } from './types'; -import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; +import { Event, Notification } from './fbs/notification'; import { TraceDirection as FbsTraceDirection } from './fbs/common'; import * as FbsNotification from './fbs/notification'; import * as FbsRequest from './fbs/request'; @@ -340,7 +341,7 @@ export class ProducerImpl data!.body(notification); - const score: ProducerScore[] = utils.parseVector( + const score: ProducerScore[] = fbsUtils.parseVector( notification, 'scores', parseProducerScore @@ -517,11 +518,11 @@ export function parseProducerDump( // TODO: Make flatbuffers TS return undefined instead of null. rtpStreams: data.rtpStreamsLength() > 0 - ? utils.parseVector(data, 'rtpStreams', (rtpStream: any) => + ? fbsUtils.parseVector(data, 'rtpStreams', (rtpStream: any) => rtpStream.unpack() ) : undefined, - traceEventTypes: utils.parseVector( + traceEventTypes: fbsUtils.parseVector( data, 'traceEventTypes', producerTraceEventTypeFromFbs @@ -533,7 +534,7 @@ export function parseProducerDump( function parseProducerStats( binary: FbsProducer.GetStatsResponse ): ProducerStat[] { - return utils.parseVector(binary, 'stats', parseRtpStreamRecvStats); + return fbsUtils.parseVector(binary, 'stats', parseRtpStreamRecvStats); } function parseProducerScore(binary: FbsProducer.Score): ProducerScore { diff --git a/node/src/ProducerTypes.ts b/node/src/ProducerTypes.ts index c6fbd1404e..9f74632a7a 100644 --- a/node/src/ProducerTypes.ts +++ b/node/src/ProducerTypes.ts @@ -1,5 +1,5 @@ import { EnhancedEventEmitter } from './enhancedEvents'; -import { MediaKind, RtpParameters } from './RtpParameters'; +import { MediaKind, RtpParameters } from './rtpParametersTypes'; import { RtpStreamRecvStats } from './RtpStream'; import { AppData } from './types'; diff --git a/node/src/Router.ts b/node/src/Router.ts index 8b0f572dea..988bee6e6b 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -60,16 +60,11 @@ import { AudioLevelObserverOptions, } from './AudioLevelObserverTypes'; import { AudioLevelObserverImpl } from './AudioLevelObserver'; -import { RtpCapabilities } from './RtpParameters'; -import { cryptoSuiteToFbs } from './SrtpParameters'; +import { RtpCapabilities } from './rtpParametersTypes'; +import { cryptoSuiteToFbs } from './srtpParametersFbsUtils'; import { AppData } from './types'; -import { - clone, - generateUUIDv4, - parseVector, - parseStringStringVector, - parseStringStringArrayVector, -} from './utils'; +import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; import * as FbsActiveSpeakerObserver from './fbs/active-speaker-observer'; import * as FbsAudioLevelObserver from './fbs/audio-level-observer'; import * as FbsRequest from './fbs/request'; @@ -382,7 +377,7 @@ export class RouterImpl } } - const transportId = generateUUIDv4(); + const transportId = utils.generateUUIDv4(); /* Build Request. */ let webRtcTransportListenServer: @@ -570,7 +565,7 @@ export class RouterImpl }; } - const transportId = generateUUIDv4(); + const transportId = utils.generateUUIDv4(); /* Build Request. */ const baseTransportOptions = new FbsTransport.OptionsT( @@ -723,7 +718,7 @@ export class RouterImpl }; } - const transportId = generateUUIDv4(); + const transportId = utils.generateUUIDv4(); /* Build Request. */ const baseTransportOptions = new FbsTransport.OptionsT( @@ -835,7 +830,7 @@ export class RouterImpl throw new TypeError('if given, appData must be an object'); } - const transportId = generateUUIDv4(); + const transportId = utils.generateUUIDv4(); /* Build Request. */ const baseTransportOptions = new FbsTransport.OptionsT( @@ -1223,7 +1218,7 @@ export class RouterImpl throw new TypeError('if given, appData must be an object'); } - const rtpObserverId = generateUUIDv4(); + const rtpObserverId = utils.generateUUIDv4(); /* Build Request. */ const activeRtpObserverOptions = @@ -1292,7 +1287,7 @@ export class RouterImpl throw new TypeError('if given, appData must be an object'); } - const rtpObserverId = generateUUIDv4(); + const rtpObserverId = utils.generateUUIDv4(); /* Build Request. */ const audioLevelObserverOptions = @@ -1353,7 +1348,7 @@ export class RouterImpl } // Clone given RTP capabilities to not modify input data. - const clonedRtpCapabilities = clone(rtpCapabilities); + const clonedRtpCapabilities = utils.clone(rtpCapabilities); try { return ortc.canConsume( @@ -1373,25 +1368,25 @@ export function parseRouterDumpResponse( ): RouterDump { return { id: binary.id()!, - transportIds: parseVector(binary, 'transportIds'), - rtpObserverIds: parseVector(binary, 'rtpObserverIds'), - mapProducerIdConsumerIds: parseStringStringArrayVector( + transportIds: fbsUtils.parseVector(binary, 'transportIds'), + rtpObserverIds: fbsUtils.parseVector(binary, 'rtpObserverIds'), + mapProducerIdConsumerIds: fbsUtils.parseStringStringArrayVector( binary, 'mapProducerIdConsumerIds' ), - mapConsumerIdProducerId: parseStringStringVector( + mapConsumerIdProducerId: fbsUtils.parseStringStringVector( binary, 'mapConsumerIdProducerId' ), - mapProducerIdObserverIds: parseStringStringArrayVector( + mapProducerIdObserverIds: fbsUtils.parseStringStringArrayVector( binary, 'mapProducerIdObserverIds' ), - mapDataProducerIdDataConsumerIds: parseStringStringArrayVector( + mapDataProducerIdDataConsumerIds: fbsUtils.parseStringStringArrayVector( binary, 'mapDataProducerIdDataConsumerIds' ), - mapDataConsumerIdDataProducerId: parseStringStringVector( + mapDataConsumerIdDataProducerId: fbsUtils.parseStringStringVector( binary, 'mapDataConsumerIdDataProducerId' ), diff --git a/node/src/RouterTypes.ts b/node/src/RouterTypes.ts index accbd51b11..c435d60041 100644 --- a/node/src/RouterTypes.ts +++ b/node/src/RouterTypes.ts @@ -27,8 +27,8 @@ import { AudioLevelObserver, AudioLevelObserverOptions, } from './AudioLevelObserverTypes'; -import { RtpCapabilities, RtpCodecCapability } from './RtpParameters'; -import { NumSctpStreams } from './SctpParameters'; +import { RtpCapabilities, RtpCodecCapability } from './rtpParametersTypes'; +import { NumSctpStreams } from './sctpParametersTypes'; import { Either, AppData } from './types'; export type RouterOptions = { diff --git a/node/src/Transport.ts b/node/src/Transport.ts index 8cba700abe..c90bf8b676 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -62,17 +62,19 @@ import { MediaKind, RtpCapabilities, RtpParameters, +} from './rtpParametersTypes'; +import { serializeRtpEncodingParameters, serializeRtpParameters, -} from './RtpParameters'; +} from './rtpParametersFbsUtils'; +import { SctpParameters, SctpStreamParameters } from './sctpParametersTypes'; import { parseSctpParametersDump, serializeSctpStreamParameters, - SctpParameters, - SctpStreamParameters, -} from './SctpParameters'; +} from './sctpParametersFbsUtils'; import { AppData } from './types'; import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; import { TraceDirection as FbsTraceDirection } from './fbs/common'; import * as FbsRequest from './fbs/request'; import { MediaKind as FbsMediaKind } from './fbs/rtp-parameters/media-kind'; @@ -1088,23 +1090,29 @@ export function parseBaseTransportDump( binary: FbsTransport.Dump ): BaseTransportDump { // Retrieve producerIds. - const producerIds = utils.parseVector(binary, 'producerIds'); + const producerIds = fbsUtils.parseVector(binary, 'producerIds'); // Retrieve consumerIds. - const consumerIds = utils.parseVector(binary, 'consumerIds'); + const consumerIds = fbsUtils.parseVector(binary, 'consumerIds'); // Retrieve map SSRC consumerId. - const mapSsrcConsumerId = utils.parseUint32StringVector( + const mapSsrcConsumerId = fbsUtils.parseUint32StringVector( binary, 'mapSsrcConsumerId' ); // Retrieve map RTX SSRC consumerId. - const mapRtxSsrcConsumerId = utils.parseUint32StringVector( + const mapRtxSsrcConsumerId = fbsUtils.parseUint32StringVector( binary, 'mapRtxSsrcConsumerId' ); // Retrieve dataProducerIds. - const dataProducerIds = utils.parseVector(binary, 'dataProducerIds'); + const dataProducerIds = fbsUtils.parseVector( + binary, + 'dataProducerIds' + ); // Retrieve dataConsumerIds. - const dataConsumerIds = utils.parseVector(binary, 'dataConsumerIds'); + const dataConsumerIds = fbsUtils.parseVector( + binary, + 'dataConsumerIds' + ); // Retrieve recvRtpHeaderExtesions. const recvRtpHeaderExtensions = parseRecvRtpHeaderExtensions( binary.recvRtpHeaderExtensions()! @@ -1132,7 +1140,7 @@ export function parseBaseTransportDump( : undefined; // Retrieve traceEventTypes. - const traceEventTypes = utils.parseVector( + const traceEventTypes = fbsUtils.parseVector( binary, 'traceEventTypes', transportTraceEventTypeFromFbs @@ -1557,11 +1565,11 @@ function parseRtpListenerDump( binary: FbsTransport.RtpListener ): RtpListenerDump { // Retrieve ssrcTable. - const ssrcTable = utils.parseUint32StringVector(binary, 'ssrcTable'); + const ssrcTable = fbsUtils.parseUint32StringVector(binary, 'ssrcTable'); // Retrieve midTable. - const midTable = utils.parseUint32StringVector(binary, 'midTable'); + const midTable = fbsUtils.parseUint32StringVector(binary, 'midTable'); // Retrieve ridTable. - const ridTable = utils.parseUint32StringVector(binary, 'ridTable'); + const ridTable = fbsUtils.parseUint32StringVector(binary, 'ridTable'); return { ssrcTable, @@ -1574,7 +1582,10 @@ function parseSctpListenerDump( binary: FbsTransport.SctpListener ): SctpListenerDump { // Retrieve streamIdTable. - const streamIdTable = utils.parseUint32StringVector(binary, 'streamIdTable'); + const streamIdTable = fbsUtils.parseUint32StringVector( + binary, + 'streamIdTable' + ); return { streamIdTable }; } diff --git a/node/src/TransportTypes.ts b/node/src/TransportTypes.ts index dc9ca99c2b..65a3c12200 100644 --- a/node/src/TransportTypes.ts +++ b/node/src/TransportTypes.ts @@ -3,7 +3,7 @@ import { Producer, ProducerOptions } from './ProducerTypes'; import { Consumer, ConsumerOptions } from './ConsumerTypes'; import { DataProducer, DataProducerOptions } from './DataProducerTypes'; import { DataConsumer, DataConsumerOptions } from './DataConsumerTypes'; -import { SctpParameters } from './SctpParameters'; +import { SctpParameters } from './sctpParametersTypes'; import { AppData } from './types'; export type TransportListenInfo = { diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index e623c77d8b..d389862508 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -13,7 +13,7 @@ import { } from './WebRtcServerTypes'; import { WebRtcTransport } from './WebRtcTransportTypes'; import { AppData } from './types'; -import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; import { Body as RequestBody, Method } from './fbs/request'; import * as FbsWorker from './fbs/worker'; import * as FbsWebRtcServer from './fbs/web-rtc-server'; @@ -209,14 +209,14 @@ function parseWebRtcServerDump( ): WebRtcServerDump { return { id: data.id()!, - udpSockets: utils.parseVector(data, 'udpSockets', parseIpPort), - tcpServers: utils.parseVector(data, 'tcpServers', parseIpPort), - webRtcTransportIds: utils.parseVector(data, 'webRtcTransportIds'), - localIceUsernameFragments: utils.parseVector( + udpSockets: fbsUtils.parseVector(data, 'udpSockets', parseIpPort), + tcpServers: fbsUtils.parseVector(data, 'tcpServers', parseIpPort), + webRtcTransportIds: fbsUtils.parseVector(data, 'webRtcTransportIds'), + localIceUsernameFragments: fbsUtils.parseVector( data, 'localIceUsernameFragments', parseIceUserNameFragment ), - tupleHashes: utils.parseVector(data, 'tupleHashes', parseTupleHash), + tupleHashes: fbsUtils.parseVector(data, 'tupleHashes', parseTupleHash), }; } diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index d216856df8..68acd22340 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -31,9 +31,9 @@ import { parseTransportTraceEventData, parseTuple, } from './Transport'; -import { SctpParameters } from './SctpParameters'; +import { SctpParameters } from './sctpParametersTypes'; import { AppData } from './types'; -import { parseVector } from './utils'; +import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import * as FbsRequest from './fbs/request'; import * as FbsTransport from './fbs/transport'; @@ -569,7 +569,7 @@ export function parseWebRtcTransportDumpResponse( // Retrieve BaseTransportDump. const baseTransportDump = parseBaseTransportDump(binary.base()!); // Retrieve ICE candidates. - const iceCandidates = parseVector( + const iceCandidates = fbsUtils.parseVector( binary, 'iceCandidates', parseIceCandidate diff --git a/node/src/WebRtcTransportTypes.ts b/node/src/WebRtcTransportTypes.ts index dbb38afd34..37fda80619 100644 --- a/node/src/WebRtcTransportTypes.ts +++ b/node/src/WebRtcTransportTypes.ts @@ -12,7 +12,7 @@ import { TransportObserverEvents, } from './TransportTypes'; import { WebRtcServer } from './WebRtcServerTypes'; -import { SctpParameters, NumSctpStreams } from './SctpParameters'; +import { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; import { Either, AppData } from './types'; export type WebRtcTransportOptions< diff --git a/node/src/Worker.ts b/node/src/Worker.ts index 95d63a0547..e6dfedd4ea 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -21,9 +21,10 @@ import { WebRtcServerImpl } from './WebRtcServer'; import { Router, RouterOptions } from './RouterTypes'; import { RouterImpl } from './Router'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; -import { RtpCodecCapability } from './RtpParameters'; -import { AppData } from './types'; +import { RtpCodecCapability } from './rtpParametersTypes'; import * as utils from './utils'; +import * as fbsUtils from './fbsUtils'; +import { AppData } from './types'; import { Event } from './fbs/notification'; import * as FbsRequest from './fbs/request'; import * as FbsWorker from './fbs/worker'; @@ -590,14 +591,14 @@ export function parseWorkerDumpResponse( ): WorkerDump { const dump: WorkerDump = { pid: binary.pid(), - webRtcServerIds: utils.parseVector(binary, 'webRtcServerIds'), - routerIds: utils.parseVector(binary, 'routerIds'), + webRtcServerIds: fbsUtils.parseVector(binary, 'webRtcServerIds'), + routerIds: fbsUtils.parseVector(binary, 'routerIds'), channelMessageHandlers: { - channelRequestHandlers: utils.parseVector( + channelRequestHandlers: fbsUtils.parseVector( binary.channelMessageHandlers()!, 'channelRequestHandlers' ), - channelNotificationHandlers: utils.parseVector( + channelNotificationHandlers: fbsUtils.parseVector( binary.channelMessageHandlers()!, 'channelNotificationHandlers' ), diff --git a/node/src/fbsUtils.ts b/node/src/fbsUtils.ts new file mode 100644 index 0000000000..ba3a369fe7 --- /dev/null +++ b/node/src/fbsUtils.ts @@ -0,0 +1,117 @@ +import { Type as FbsRtpParametersType } from './fbs/rtp-parameters'; + +/** + * Parse flatbuffers vector into an array of the given T. + */ +export function parseVector( + binary: any, + methodName: string, + parseFn?: (binary2: any) => T +): T[] { + const array: T[] = []; + + for (let i = 0; i < binary[`${methodName}Length`](); ++i) { + if (parseFn) { + array.push(parseFn(binary[methodName](i))); + } else { + array.push(binary[methodName](i) as T); + } + } + + return array; +} + +/** + * Parse flatbuffers vector of StringString into the corresponding array. + */ +export function parseStringStringVector( + binary: any, + methodName: string +): { key: string; value: string }[] { + const array: { key: string; value: string }[] = []; + + for (let i = 0; i < binary[`${methodName}Length`](); ++i) { + const kv = binary[methodName](i)!; + + array.push({ key: kv.key(), value: kv.value() }); + } + + return array; +} + +/** + * Parse flatbuffers vector of StringUint8 into the corresponding array. + */ +export function parseStringUint8Vector( + binary: any, + methodName: string +): { key: string; value: number }[] { + const array: { key: string; value: number }[] = []; + + for (let i = 0; i < binary[`${methodName}Length`](); ++i) { + const kv = binary[methodName](i)!; + + array.push({ key: kv.key(), value: kv.value() }); + } + + return array; +} + +/** + * Parse flatbuffers vector of Uint16String into the corresponding array. + */ +export function parseUint16StringVector( + binary: any, + methodName: string +): { key: number; value: string }[] { + const array: { key: number; value: string }[] = []; + + for (let i = 0; i < binary[`${methodName}Length`](); ++i) { + const kv = binary[methodName](i)!; + + array.push({ key: kv.key(), value: kv.value() }); + } + + return array; +} + +/** + * Parse flatbuffers vector of Uint32String into the corresponding array. + */ +export function parseUint32StringVector( + binary: any, + methodName: string +): { key: number; value: string }[] { + const array: { key: number; value: string }[] = []; + + for (let i = 0; i < binary[`${methodName}Length`](); ++i) { + const kv = binary[methodName](i)!; + + array.push({ key: kv.key(), value: kv.value() }); + } + + return array; +} + +/** + * Parse flatbuffers vector of StringStringArray into the corresponding array. + */ +export function parseStringStringArrayVector( + binary: any, + methodName: string +): { key: string; values: string[] }[] { + const array: { key: string; values: string[] }[] = []; + + for (let i = 0; i < binary[`${methodName}Length`](); ++i) { + const kv = binary[methodName](i)!; + const values: string[] = []; + + for (let i2 = 0; i2 < kv.valuesLength(); ++i2) { + values.push(kv.values(i2)! as string); + } + + array.push({ key: kv.key(), values }); + } + + return array; +} diff --git a/node/src/index.ts b/node/src/index.ts index bf3b13137b..5169c0bbef 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -4,8 +4,7 @@ import { Worker, WorkerSettings } from './WorkerTypes'; import { WorkerImpl, workerBin } from './Worker'; import * as utils from './utils'; import { supportedRtpCapabilities } from './supportedRtpCapabilities'; -import { RtpCapabilities } from './RtpParameters'; - +import { RtpCapabilities } from './rtpParametersTypes'; import * as types from './types'; /** diff --git a/node/src/ortc.ts b/node/src/ortc.ts index 3b36297493..cc3770bd4f 100644 --- a/node/src/ortc.ts +++ b/node/src/ortc.ts @@ -13,8 +13,8 @@ import { RtpEncodingParameters, RtpHeaderExtensionParameters, RtcpParameters, -} from './RtpParameters'; -import { SctpStreamParameters } from './SctpParameters'; +} from './rtpParametersTypes'; +import { SctpStreamParameters } from './sctpParametersTypes'; import * as utils from './utils'; import { UnsupportedError } from './errors'; import * as FbsRtpParameters from './fbs/rtp-parameters'; diff --git a/node/src/RtpParameters.ts b/node/src/rtpParametersFbsUtils.ts similarity index 55% rename from node/src/RtpParameters.ts rename to node/src/rtpParametersFbsUtils.ts index 4c1e7631dc..88656d1aaa 100644 --- a/node/src/RtpParameters.ts +++ b/node/src/rtpParametersFbsUtils.ts @@ -1,4 +1,14 @@ import * as flatbuffers from 'flatbuffers'; +import { + RtpParameters, + RtpCodecParameters, + RtcpFeedback, + RtpEncodingParameters, + RtpHeaderExtensionUri, + RtpHeaderExtensionParameters, + RtcpParameters, +} from './rtpParametersTypes'; +import * as fbsUtils from './fbsUtils'; import { Boolean as FbsBoolean, Double as FbsDouble, @@ -16,365 +26,6 @@ import { Rtx as FbsRtx, Value as FbsValue, } from './fbs/rtp-parameters'; -import * as utils from './utils'; - -/** - * The RTP capabilities define what mediasoup or an endpoint can receive at - * media level. - */ -export type RtpCapabilities = { - /** - * Supported media and RTX codecs. - */ - codecs?: RtpCodecCapability[]; - - /** - * Supported RTP header extensions. - */ - headerExtensions?: RtpHeaderExtension[]; -}; - -/** - * Media kind ('audio' or 'video'). - */ -export type MediaKind = 'audio' | 'video'; - -/** - * Provides information on the capabilities of a codec within the RTP - * capabilities. The list of media codecs supported by mediasoup and their - * settings is defined in the supportedRtpCapabilities.ts file. - * - * Exactly one RtpCodecCapability will be present for each supported combination - * of parameters that requires a distinct value of preferredPayloadType. For - * example: - * - * - Multiple H264 codecs, each with their own distinct 'packetization-mode' and - * 'profile-level-id' values. - * - Multiple VP9 codecs, each with their own distinct 'profile-id' value. - * - * RtpCodecCapability entries in the mediaCodecs array of RouterOptions do not - * require preferredPayloadType field (if unset, mediasoup will choose a random - * one). If given, make sure it's in the 96-127 range. - */ -export type RtpCodecCapability = { - /** - * Media kind. - */ - kind: MediaKind; - - /** - * The codec MIME media type/subtype (e.g. 'audio/opus', 'video/VP8'). - */ - mimeType: string; - - /** - * The preferred RTP payload type. - */ - preferredPayloadType?: number; - - /** - * Codec clock rate expressed in Hertz. - */ - clockRate: number; - - /** - * The number of channels supported (e.g. two for stereo). Just for audio. - * Default 1. - */ - channels?: number; - - /** - * Codec specific parameters. Some parameters (such as 'packetization-mode' - * and 'profile-level-id' in H264 or 'profile-id' in VP9) are critical for - * codec matching. - */ - parameters?: any; - - /** - * Transport layer and codec-specific feedback messages for this codec. - */ - rtcpFeedback?: RtcpFeedback[]; -}; - -/** - * Direction of RTP header extension. - */ -export type RtpHeaderExtensionDirection = - | 'sendrecv' - | 'sendonly' - | 'recvonly' - | 'inactive'; - -/** - * Provides information relating to supported header extensions. The list of - * RTP header extensions supported by mediasoup is defined in the - * supportedRtpCapabilities.ts file. - * - * mediasoup does not currently support encrypted RTP header extensions. The - * direction field is just present in mediasoup RTP capabilities (retrieved via - * router.rtpCapabilities or mediasoup.getSupportedRtpCapabilities()). It's - * ignored if present in endpoints' RTP capabilities. - */ -export type RtpHeaderExtension = { - /** - * Media kind. - */ - kind: MediaKind; - - /* - * The URI of the RTP header extension, as defined in RFC 5285. - */ - uri: RtpHeaderExtensionUri; - - /** - * The preferred numeric identifier that goes in the RTP packet. Must be - * unique. - */ - preferredId: number; - - /** - * If true, it is preferred that the value in the header be encrypted as per - * RFC 6904. Default false. - */ - preferredEncrypt?: boolean; - - /** - * If 'sendrecv', mediasoup supports sending and receiving this RTP extension. - * 'sendonly' means that mediasoup can send (but not receive) it. 'recvonly' - * means that mediasoup can receive (but not send) it. - */ - direction?: RtpHeaderExtensionDirection; -}; - -/** - * The RTP send parameters describe a media stream received by mediasoup from - * an endpoint through its corresponding mediasoup Producer. These parameters - * may include a mid value that the mediasoup transport will use to match - * received RTP packets based on their MID RTP extension value. - * - * mediasoup allows RTP send parameters with a single encoding and with multiple - * encodings (simulcast). In the latter case, each entry in the encodings array - * must include a ssrc field or a rid field (the RID RTP extension value). Check - * the Simulcast and SVC sections for more information. - * - * The RTP receive parameters describe a media stream as sent by mediasoup to - * an endpoint through its corresponding mediasoup Consumer. The mid value is - * unset (mediasoup does not include the MID RTP extension into RTP packets - * being sent to endpoints). - * - * There is a single entry in the encodings array (even if the corresponding - * producer uses simulcast). The consumer sends a single and continuous RTP - * stream to the endpoint and spatial/temporal layer selection is possible via - * consumer.setPreferredLayers(). - * - * As an exception, previous bullet is not true when consuming a stream over a - * PipeTransport, in which all RTP streams from the associated producer are - * forwarded verbatim through the consumer. - * - * The RTP receive parameters will always have their ssrc values randomly - * generated for all of its encodings (and optional rtx: { ssrc: XXXX } if the - * endpoint supports RTX), regardless of the original RTP send parameters in - * the associated producer. This applies even if the producer's encodings have - * rid set. - */ -export type RtpParameters = { - /** - * The MID RTP extension value as defined in the BUNDLE specification. - */ - mid?: string; - - /** - * Media and RTX codecs in use. - */ - codecs: RtpCodecParameters[]; - - /** - * RTP header extensions in use. - */ - headerExtensions?: RtpHeaderExtensionParameters[]; - - /** - * Transmitted RTP streams and their settings. - */ - encodings?: RtpEncodingParameters[]; - - /** - * Parameters used for RTCP. - */ - rtcp?: RtcpParameters; -}; - -/** - * Provides information on codec settings within the RTP parameters. The list - * of media codecs supported by mediasoup and their settings is defined in the - * supportedRtpCapabilities.ts file. - */ -export type RtpCodecParameters = { - /** - * The codec MIME media type/subtype (e.g. 'audio/opus', 'video/VP8'). - */ - mimeType: string; - - /** - * The value that goes in the RTP Payload Type Field. Must be unique. - */ - payloadType: number; - - /** - * Codec clock rate expressed in Hertz. - */ - clockRate: number; - - /** - * The number of channels supported (e.g. two for stereo). Just for audio. - * Default 1. - */ - channels?: number; - - /** - * Codec-specific parameters available for signaling. Some parameters (such - * as 'packetization-mode' and 'profile-level-id' in H264 or 'profile-id' in - * VP9) are critical for codec matching. - */ - parameters?: any; - - /** - * Transport layer and codec-specific feedback messages for this codec. - */ - rtcpFeedback?: RtcpFeedback[]; -}; - -/** - * Provides information on RTCP feedback messages for a specific codec. Those - * messages can be transport layer feedback messages or codec-specific feedback - * messages. The list of RTCP feedbacks supported by mediasoup is defined in the - * supportedRtpCapabilities.ts file. - */ -export type RtcpFeedback = { - /** - * RTCP feedback type. - */ - type: string; - - /** - * RTCP feedback parameter. - */ - parameter?: string; -}; - -/** - * Provides information relating to an encoding, which represents a media RTP - * stream and its associated RTX stream (if any). - */ -export type RtpEncodingParameters = { - /** - * The media SSRC. - */ - ssrc?: number; - - /** - * The RID RTP extension value. Must be unique. - */ - rid?: string; - - /** - * Codec payload type this encoding affects. If unset, first media codec is - * chosen. - */ - codecPayloadType?: number; - - /** - * RTX stream information. It must contain a numeric ssrc field indicating - * the RTX SSRC. - */ - rtx?: { ssrc: number }; - - /** - * It indicates whether discontinuous RTP transmission will be used. Useful - * for audio (if the codec supports it) and for video screen sharing (when - * static content is being transmitted, this option disables the RTP - * inactivity checks in mediasoup). Default false. - */ - dtx?: boolean; - - /** - * Number of spatial and temporal layers in the RTP stream (e.g. 'L1T3'). - * See webrtc-svc. - */ - scalabilityMode?: string; - - /** - * Others. - */ - scaleResolutionDownBy?: number; - maxBitrate?: number; -}; - -export type RtpHeaderExtensionUri = - | 'urn:ietf:params:rtp-hdrext:sdes:mid' - | 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id' - | 'urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id' - | 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07' - | 'urn:ietf:params:rtp-hdrext:framemarking' - | 'urn:ietf:params:rtp-hdrext:ssrc-audio-level' - | 'urn:3gpp:video-orientation' - | 'urn:ietf:params:rtp-hdrext:toffset' - | 'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01' - | 'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time' - | 'http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time' - | 'http://www.webrtc.org/experiments/rtp-hdrext/playout-delay'; - -/** - * Defines a RTP header extension within the RTP parameters. The list of RTP - * header extensions supported by mediasoup is defined in the - * supportedRtpCapabilities.ts file. - * - * mediasoup does not currently support encrypted RTP header extensions and no - * parameters are currently considered. - */ -export type RtpHeaderExtensionParameters = { - /** - * The URI of the RTP header extension, as defined in RFC 5285. - */ - uri: RtpHeaderExtensionUri; - - /** - * The numeric identifier that goes in the RTP packet. Must be unique. - */ - id: number; - - /** - * If true, the value in the header is encrypted as per RFC 6904. Default false. - */ - encrypt?: boolean; - - /** - * Configuration parameters for the header extension. - */ - parameters?: any; -}; - -/** - * Provides information on RTCP settings within the RTP parameters. - * - * If no cname is given in a producer's RTP parameters, the mediasoup transport - * will choose a random one that will be used into RTCP SDES messages sent to - * all its associated consumers. - * - * mediasoup assumes reducedSize to always be true. - */ -export type RtcpParameters = { - /** - * The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages). - */ - cname?: string; - - /** - * Whether reduced size RTCP RFC 5506 is configured (if true) or compound RTCP - * as specified in RFC 3550 (if false). Default true. - */ - reducedSize?: boolean; -}; export function serializeRtpParameters( builder: flatbuffers.Builder, @@ -694,7 +345,11 @@ export function parseRtpCodecParameters( let rtcpFeedback: RtcpFeedback[] = []; if (data.rtcpFeedbackLength() > 0) { - rtcpFeedback = utils.parseVector(data, 'rtcpFeedback', parseRtcpFeedback); + rtcpFeedback = fbsUtils.parseVector( + data, + 'rtcpFeedback', + parseRtcpFeedback + ); } return { @@ -846,12 +501,12 @@ export function parseRtpEncodingParameters( } export function parseRtpParameters(data: FbsRtpParameters): RtpParameters { - const codecs = utils.parseVector(data, 'codecs', parseRtpCodecParameters); + const codecs = fbsUtils.parseVector(data, 'codecs', parseRtpCodecParameters); let headerExtensions: RtpHeaderExtensionParameters[] = []; if (data.headerExtensionsLength() > 0) { - headerExtensions = utils.parseVector( + headerExtensions = fbsUtils.parseVector( data, 'headerExtensions', parseRtpHeaderExtensionParameters @@ -861,7 +516,7 @@ export function parseRtpParameters(data: FbsRtpParameters): RtpParameters { let encodings: RtpEncodingParameters[] = []; if (data.encodingsLength() > 0) { - encodings = utils.parseVector( + encodings = fbsUtils.parseVector( data, 'encodings', parseRtpEncodingParameters diff --git a/node/src/rtpParametersTypes.ts b/node/src/rtpParametersTypes.ts new file mode 100644 index 0000000000..fa7e618863 --- /dev/null +++ b/node/src/rtpParametersTypes.ts @@ -0,0 +1,357 @@ +/** + * The RTP capabilities define what mediasoup or an endpoint can receive at + * media level. + */ +export type RtpCapabilities = { + /** + * Supported media and RTX codecs. + */ + codecs?: RtpCodecCapability[]; + + /** + * Supported RTP header extensions. + */ + headerExtensions?: RtpHeaderExtension[]; +}; + +/** + * Media kind ('audio' or 'video'). + */ +export type MediaKind = 'audio' | 'video'; + +/** + * Provides information on the capabilities of a codec within the RTP + * capabilities. The list of media codecs supported by mediasoup and their + * settings is defined in the supportedRtpCapabilities.ts file. + * + * Exactly one RtpCodecCapability will be present for each supported combination + * of parameters that requires a distinct value of preferredPayloadType. For + * example: + * + * - Multiple H264 codecs, each with their own distinct 'packetization-mode' and + * 'profile-level-id' values. + * - Multiple VP9 codecs, each with their own distinct 'profile-id' value. + * + * RtpCodecCapability entries in the mediaCodecs array of RouterOptions do not + * require preferredPayloadType field (if unset, mediasoup will choose a random + * one). If given, make sure it's in the 96-127 range. + */ +export type RtpCodecCapability = { + /** + * Media kind. + */ + kind: MediaKind; + + /** + * The codec MIME media type/subtype (e.g. 'audio/opus', 'video/VP8'). + */ + mimeType: string; + + /** + * The preferred RTP payload type. + */ + preferredPayloadType?: number; + + /** + * Codec clock rate expressed in Hertz. + */ + clockRate: number; + + /** + * The number of channels supported (e.g. two for stereo). Just for audio. + * Default 1. + */ + channels?: number; + + /** + * Codec specific parameters. Some parameters (such as 'packetization-mode' + * and 'profile-level-id' in H264 or 'profile-id' in VP9) are critical for + * codec matching. + */ + parameters?: any; + + /** + * Transport layer and codec-specific feedback messages for this codec. + */ + rtcpFeedback?: RtcpFeedback[]; +}; + +/** + * Direction of RTP header extension. + */ +export type RtpHeaderExtensionDirection = + | 'sendrecv' + | 'sendonly' + | 'recvonly' + | 'inactive'; + +/** + * Provides information relating to supported header extensions. The list of + * RTP header extensions supported by mediasoup is defined in the + * supportedRtpCapabilities.ts file. + * + * mediasoup does not currently support encrypted RTP header extensions. The + * direction field is just present in mediasoup RTP capabilities (retrieved via + * router.rtpCapabilities or mediasoup.getSupportedRtpCapabilities()). It's + * ignored if present in endpoints' RTP capabilities. + */ +export type RtpHeaderExtension = { + /** + * Media kind. + */ + kind: MediaKind; + + /* + * The URI of the RTP header extension, as defined in RFC 5285. + */ + uri: RtpHeaderExtensionUri; + + /** + * The preferred numeric identifier that goes in the RTP packet. Must be + * unique. + */ + preferredId: number; + + /** + * If true, it is preferred that the value in the header be encrypted as per + * RFC 6904. Default false. + */ + preferredEncrypt?: boolean; + + /** + * If 'sendrecv', mediasoup supports sending and receiving this RTP extension. + * 'sendonly' means that mediasoup can send (but not receive) it. 'recvonly' + * means that mediasoup can receive (but not send) it. + */ + direction?: RtpHeaderExtensionDirection; +}; + +/** + * The RTP send parameters describe a media stream received by mediasoup from + * an endpoint through its corresponding mediasoup Producer. These parameters + * may include a mid value that the mediasoup transport will use to match + * received RTP packets based on their MID RTP extension value. + * + * mediasoup allows RTP send parameters with a single encoding and with multiple + * encodings (simulcast). In the latter case, each entry in the encodings array + * must include a ssrc field or a rid field (the RID RTP extension value). Check + * the Simulcast and SVC sections for more information. + * + * The RTP receive parameters describe a media stream as sent by mediasoup to + * an endpoint through its corresponding mediasoup Consumer. The mid value is + * unset (mediasoup does not include the MID RTP extension into RTP packets + * being sent to endpoints). + * + * There is a single entry in the encodings array (even if the corresponding + * producer uses simulcast). The consumer sends a single and continuous RTP + * stream to the endpoint and spatial/temporal layer selection is possible via + * consumer.setPreferredLayers(). + * + * As an exception, previous bullet is not true when consuming a stream over a + * PipeTransport, in which all RTP streams from the associated producer are + * forwarded verbatim through the consumer. + * + * The RTP receive parameters will always have their ssrc values randomly + * generated for all of its encodings (and optional rtx: { ssrc: XXXX } if the + * endpoint supports RTX), regardless of the original RTP send parameters in + * the associated producer. This applies even if the producer's encodings have + * rid set. + */ +export type RtpParameters = { + /** + * The MID RTP extension value as defined in the BUNDLE specification. + */ + mid?: string; + + /** + * Media and RTX codecs in use. + */ + codecs: RtpCodecParameters[]; + + /** + * RTP header extensions in use. + */ + headerExtensions?: RtpHeaderExtensionParameters[]; + + /** + * Transmitted RTP streams and their settings. + */ + encodings?: RtpEncodingParameters[]; + + /** + * Parameters used for RTCP. + */ + rtcp?: RtcpParameters; +}; + +/** + * Provides information on codec settings within the RTP parameters. The list + * of media codecs supported by mediasoup and their settings is defined in the + * supportedRtpCapabilities.ts file. + */ +export type RtpCodecParameters = { + /** + * The codec MIME media type/subtype (e.g. 'audio/opus', 'video/VP8'). + */ + mimeType: string; + + /** + * The value that goes in the RTP Payload Type Field. Must be unique. + */ + payloadType: number; + + /** + * Codec clock rate expressed in Hertz. + */ + clockRate: number; + + /** + * The number of channels supported (e.g. two for stereo). Just for audio. + * Default 1. + */ + channels?: number; + + /** + * Codec-specific parameters available for signaling. Some parameters (such + * as 'packetization-mode' and 'profile-level-id' in H264 or 'profile-id' in + * VP9) are critical for codec matching. + */ + parameters?: any; + + /** + * Transport layer and codec-specific feedback messages for this codec. + */ + rtcpFeedback?: RtcpFeedback[]; +}; + +/** + * Provides information on RTCP feedback messages for a specific codec. Those + * messages can be transport layer feedback messages or codec-specific feedback + * messages. The list of RTCP feedbacks supported by mediasoup is defined in the + * supportedRtpCapabilities.ts file. + */ +export type RtcpFeedback = { + /** + * RTCP feedback type. + */ + type: string; + + /** + * RTCP feedback parameter. + */ + parameter?: string; +}; + +/** + * Provides information relating to an encoding, which represents a media RTP + * stream and its associated RTX stream (if any). + */ +export type RtpEncodingParameters = { + /** + * The media SSRC. + */ + ssrc?: number; + + /** + * The RID RTP extension value. Must be unique. + */ + rid?: string; + + /** + * Codec payload type this encoding affects. If unset, first media codec is + * chosen. + */ + codecPayloadType?: number; + + /** + * RTX stream information. It must contain a numeric ssrc field indicating + * the RTX SSRC. + */ + rtx?: { ssrc: number }; + + /** + * It indicates whether discontinuous RTP transmission will be used. Useful + * for audio (if the codec supports it) and for video screen sharing (when + * static content is being transmitted, this option disables the RTP + * inactivity checks in mediasoup). Default false. + */ + dtx?: boolean; + + /** + * Number of spatial and temporal layers in the RTP stream (e.g. 'L1T3'). + * See webrtc-svc. + */ + scalabilityMode?: string; + + /** + * Others. + */ + scaleResolutionDownBy?: number; + maxBitrate?: number; +}; + +export type RtpHeaderExtensionUri = + | 'urn:ietf:params:rtp-hdrext:sdes:mid' + | 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id' + | 'urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id' + | 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07' + | 'urn:ietf:params:rtp-hdrext:framemarking' + | 'urn:ietf:params:rtp-hdrext:ssrc-audio-level' + | 'urn:3gpp:video-orientation' + | 'urn:ietf:params:rtp-hdrext:toffset' + | 'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01' + | 'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time' + | 'http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time' + | 'http://www.webrtc.org/experiments/rtp-hdrext/playout-delay'; + +/** + * Defines a RTP header extension within the RTP parameters. The list of RTP + * header extensions supported by mediasoup is defined in the + * supportedRtpCapabilities.ts file. + * + * mediasoup does not currently support encrypted RTP header extensions and no + * parameters are currently considered. + */ +export type RtpHeaderExtensionParameters = { + /** + * The URI of the RTP header extension, as defined in RFC 5285. + */ + uri: RtpHeaderExtensionUri; + + /** + * The numeric identifier that goes in the RTP packet. Must be unique. + */ + id: number; + + /** + * If true, the value in the header is encrypted as per RFC 6904. Default false. + */ + encrypt?: boolean; + + /** + * Configuration parameters for the header extension. + */ + parameters?: any; +}; + +/** + * Provides information on RTCP settings within the RTP parameters. + * + * If no cname is given in a producer's RTP parameters, the mediasoup transport + * will choose a random one that will be used into RTCP SDES messages sent to + * all its associated consumers. + * + * mediasoup assumes reducedSize to always be true. + */ +export type RtcpParameters = { + /** + * The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages). + */ + cname?: string; + + /** + * Whether reduced size RTCP RFC 5506 is configured (if true) or compound RTCP + * as specified in RFC 3550 (if false). Default true. + */ + reducedSize?: boolean; +}; diff --git a/node/src/sctpParametersFbsUtils.ts b/node/src/sctpParametersFbsUtils.ts new file mode 100644 index 0000000000..b8b5375c51 --- /dev/null +++ b/node/src/sctpParametersFbsUtils.ts @@ -0,0 +1,54 @@ +import * as flatbuffers from 'flatbuffers'; +import { + SctpStreamParameters, + SctpParametersDump, +} from './sctpParametersTypes'; +import * as FbsSctpParameters from './fbs/sctp-parameters'; + +export function parseSctpParametersDump( + binary: FbsSctpParameters.SctpParameters +): SctpParametersDump { + return { + port: binary.port(), + OS: binary.os(), + MIS: binary.mis(), + maxMessageSize: binary.maxMessageSize(), + sendBufferSize: binary.sendBufferSize(), + sctpBufferedAmount: binary.sctpBufferedAmount(), + isDataChannel: binary.isDataChannel(), + }; +} + +export function serializeSctpStreamParameters( + builder: flatbuffers.Builder, + parameters: SctpStreamParameters +): number { + return FbsSctpParameters.SctpStreamParameters.createSctpStreamParameters( + builder, + parameters.streamId, + parameters.ordered!, + typeof parameters.maxPacketLifeTime === 'number' + ? parameters.maxPacketLifeTime + : null, + typeof parameters.maxRetransmits === 'number' + ? parameters.maxRetransmits + : null + ); +} + +export function parseSctpStreamParameters( + parameters: FbsSctpParameters.SctpStreamParameters +): SctpStreamParameters { + return { + streamId: parameters.streamId(), + ordered: parameters.ordered()!, + maxPacketLifeTime: + parameters.maxPacketLifeTime() !== null + ? parameters.maxPacketLifeTime()! + : undefined, + maxRetransmits: + parameters.maxRetransmits() !== null + ? parameters.maxRetransmits()! + : undefined, + }; +} diff --git a/node/src/SctpParameters.ts b/node/src/sctpParametersTypes.ts similarity index 67% rename from node/src/SctpParameters.ts rename to node/src/sctpParametersTypes.ts index 849ff20143..3e8803408a 100644 --- a/node/src/SctpParameters.ts +++ b/node/src/sctpParametersTypes.ts @@ -1,6 +1,3 @@ -import * as flatbuffers from 'flatbuffers'; -import * as FbsSctpParameters from './fbs/sctp-parameters'; - export type SctpCapabilities = { numStreams: NumSctpStreams; }; @@ -102,51 +99,3 @@ export type SctpParametersDump = { sctpBufferedAmount: number; isDataChannel: boolean; }; - -export function parseSctpParametersDump( - binary: FbsSctpParameters.SctpParameters -): SctpParametersDump { - return { - port: binary.port(), - OS: binary.os(), - MIS: binary.mis(), - maxMessageSize: binary.maxMessageSize(), - sendBufferSize: binary.sendBufferSize(), - sctpBufferedAmount: binary.sctpBufferedAmount(), - isDataChannel: binary.isDataChannel(), - }; -} - -export function serializeSctpStreamParameters( - builder: flatbuffers.Builder, - parameters: SctpStreamParameters -): number { - return FbsSctpParameters.SctpStreamParameters.createSctpStreamParameters( - builder, - parameters.streamId, - parameters.ordered!, - typeof parameters.maxPacketLifeTime === 'number' - ? parameters.maxPacketLifeTime - : null, - typeof parameters.maxRetransmits === 'number' - ? parameters.maxRetransmits - : null - ); -} - -export function parseSctpStreamParameters( - parameters: FbsSctpParameters.SctpStreamParameters -): SctpStreamParameters { - return { - streamId: parameters.streamId(), - ordered: parameters.ordered()!, - maxPacketLifeTime: - parameters.maxPacketLifeTime() !== null - ? parameters.maxPacketLifeTime()! - : undefined, - maxRetransmits: - parameters.maxRetransmits() !== null - ? parameters.maxRetransmits()! - : undefined, - }; -} diff --git a/node/src/SrtpParameters.ts b/node/src/srtpParametersFbsUtils.ts similarity index 81% rename from node/src/SrtpParameters.ts rename to node/src/srtpParametersFbsUtils.ts index 1077ed5207..3cc69fd480 100644 --- a/node/src/SrtpParameters.ts +++ b/node/src/srtpParametersFbsUtils.ts @@ -1,30 +1,7 @@ import * as flatbuffers from 'flatbuffers'; +import { SrtpParameters, SrtpCryptoSuite } from './srtpParametersTypes'; import * as FbsSrtpParameters from './fbs/srtp-parameters'; -/** - * SRTP parameters. - */ -export type SrtpParameters = { - /** - * Encryption and authentication transforms to be used. - */ - cryptoSuite: SrtpCryptoSuite; - - /** - * SRTP keying material (master key and salt) in Base64. - */ - keyBase64: string; -}; - -/** - * SRTP crypto suite. - */ -export type SrtpCryptoSuite = - | 'AEAD_AES_256_GCM' - | 'AEAD_AES_128_GCM' - | 'AES_CM_128_HMAC_SHA1_80' - | 'AES_CM_128_HMAC_SHA1_32'; - export function cryptoSuiteFromFbs( binary: FbsSrtpParameters.SrtpCryptoSuite ): SrtpCryptoSuite { diff --git a/node/src/srtpParametersTypes.ts b/node/src/srtpParametersTypes.ts new file mode 100644 index 0000000000..d9150bbeb3 --- /dev/null +++ b/node/src/srtpParametersTypes.ts @@ -0,0 +1,23 @@ +/** + * SRTP parameters. + */ +export type SrtpParameters = { + /** + * Encryption and authentication transforms to be used. + */ + cryptoSuite: SrtpCryptoSuite; + + /** + * SRTP keying material (master key and salt) in Base64. + */ + keyBase64: string; +}; + +/** + * SRTP crypto suite. + */ +export type SrtpCryptoSuite = + | 'AEAD_AES_256_GCM' + | 'AEAD_AES_128_GCM' + | 'AES_CM_128_HMAC_SHA1_80' + | 'AES_CM_128_HMAC_SHA1_32'; diff --git a/node/src/supportedRtpCapabilities.ts b/node/src/supportedRtpCapabilities.ts index 042e2746cb..a0f413b71c 100644 --- a/node/src/supportedRtpCapabilities.ts +++ b/node/src/supportedRtpCapabilities.ts @@ -1,4 +1,4 @@ -import { RtpCapabilities } from './RtpParameters'; +import { RtpCapabilities } from './rtpParametersTypes'; const supportedRtpCapabilities: RtpCapabilities = { codecs: [ diff --git a/node/src/types.ts b/node/src/types.ts index 032f6c5690..002adb8328 100644 --- a/node/src/types.ts +++ b/node/src/types.ts @@ -14,9 +14,9 @@ export type * from './DataConsumerTypes'; export type * from './RtpObserverTypes'; export type * from './ActiveSpeakerObserverTypes'; export type * from './AudioLevelObserverTypes'; -export type * from './RtpParameters'; -export type * from './SctpParameters'; -export type * from './SrtpParameters'; +export type * from './rtpParametersTypes'; +export type * from './sctpParametersTypes'; +export type * from './srtpParametersTypes'; export type * from './scalabilityModes'; // TODO: Here we are exporting real classes rather than types. This should diff --git a/node/src/utils.ts b/node/src/utils.ts index 7ecfcc2e67..e3cba37a8f 100644 --- a/node/src/utils.ts +++ b/node/src/utils.ts @@ -1,6 +1,4 @@ import { randomUUID, randomInt } from 'node:crypto'; -import { ProducerType } from './ProducerTypes'; -import { Type as FbsRtpParametersType } from './fbs/rtp-parameters'; /** * Clones the given value. @@ -32,148 +30,6 @@ export function generateRandomNumber(): number { return randomInt(100_000_000, 999_999_999); } -/** - * Get the flatbuffers RtpParameters type for a given Producer. - */ -export function getRtpParametersType( - producerType: ProducerType, - pipe: boolean -): FbsRtpParametersType { - if (pipe) { - return FbsRtpParametersType.PIPE; - } - - switch (producerType) { - case 'simple': { - return FbsRtpParametersType.SIMPLE; - } - - case 'simulcast': { - return FbsRtpParametersType.SIMULCAST; - } - - case 'svc': { - return FbsRtpParametersType.SVC; - } - } -} - -/** - * Parse flatbuffers vector into an array of the given type. - */ -export function parseVector( - binary: any, - methodName: string, - parseFn?: (binary2: any) => Type -): Type[] { - const array: Type[] = []; - - for (let i = 0; i < binary[`${methodName}Length`](); ++i) { - if (parseFn) { - array.push(parseFn(binary[methodName](i))); - } else { - array.push(binary[methodName](i) as Type); - } - } - - return array; -} - -/** - * Parse flatbuffers vector of StringString into the corresponding array. - */ -export function parseStringStringVector( - binary: any, - methodName: string -): { key: string; value: string }[] { - const array: { key: string; value: string }[] = []; - - for (let i = 0; i < binary[`${methodName}Length`](); ++i) { - const kv = binary[methodName](i)!; - - array.push({ key: kv.key(), value: kv.value() }); - } - - return array; -} - -/** - * Parse flatbuffers vector of StringUint8 into the corresponding array. - */ -export function parseStringUint8Vector( - binary: any, - methodName: string -): { key: string; value: number }[] { - const array: { key: string; value: number }[] = []; - - for (let i = 0; i < binary[`${methodName}Length`](); ++i) { - const kv = binary[methodName](i)!; - - array.push({ key: kv.key(), value: kv.value() }); - } - - return array; -} - -/** - * Parse flatbuffers vector of Uint16String into the corresponding array. - */ -export function parseUint16StringVector( - binary: any, - methodName: string -): { key: number; value: string }[] { - const array: { key: number; value: string }[] = []; - - for (let i = 0; i < binary[`${methodName}Length`](); ++i) { - const kv = binary[methodName](i)!; - - array.push({ key: kv.key(), value: kv.value() }); - } - - return array; -} - -/** - * Parse flatbuffers vector of Uint32String into the corresponding array. - */ -export function parseUint32StringVector( - binary: any, - methodName: string -): { key: number; value: string }[] { - const array: { key: number; value: string }[] = []; - - for (let i = 0; i < binary[`${methodName}Length`](); ++i) { - const kv = binary[methodName](i)!; - - array.push({ key: kv.key(), value: kv.value() }); - } - - return array; -} - -/** - * Parse flatbuffers vector of StringStringArray into the corresponding array. - */ -export function parseStringStringArrayVector( - binary: any, - methodName: string -): { key: string; values: string[] }[] { - const array: { key: string; values: string[] }[] = []; - - for (let i = 0; i < binary[`${methodName}Length`](); ++i) { - const kv = binary[methodName](i)!; - const values: string[] = []; - - for (let i2 = 0; i2 < kv.valuesLength(); ++i2) { - values.push(kv.values(i2)! as string); - } - - array.push({ key: kv.key(), values }); - } - - return array; -} - /** * Make an object or array recursively immutable. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze. From a4ee487e2b45c7114b27398fc85e9f1bedbda6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sat, 9 Nov 2024 00:50:39 +0100 Subject: [PATCH 07/14] Use `import type` when possible --- node/src/ActiveSpeakerObserver.ts | 6 ++-- node/src/ActiveSpeakerObserverTypes.ts | 8 ++--- node/src/AudioLevelObserver.ts | 8 ++--- node/src/AudioLevelObserverTypes.ts | 8 ++--- node/src/Consumer.ts | 10 +++--- node/src/ConsumerTypes.ts | 10 +++--- node/src/DataConsumer.ts | 8 ++--- node/src/DataConsumerTypes.ts | 6 ++-- node/src/DataProducer.ts | 8 ++--- node/src/DataProducerTypes.ts | 6 ++-- node/src/DirectTransport.ts | 8 ++--- node/src/DirectTransportTypes.ts | 6 ++-- node/src/PipeTransport.ts | 16 +++++----- node/src/PipeTransportTypes.ts | 12 +++---- node/src/PlainTransport.ts | 10 +++--- node/src/PlainTransportTypes.ts | 10 +++--- node/src/Producer.ts | 8 ++--- node/src/ProducerTypes.ts | 8 ++--- node/src/Router.ts | 35 +++++++++++---------- node/src/RouterTypes.ts | 35 +++++++++++---------- node/src/RtpObserver.ts | 13 +++++--- node/src/RtpObserverTypes.ts | 6 ++-- node/src/Transport.ts | 31 +++++++++--------- node/src/TransportTypes.ts | 14 ++++----- node/src/WebRtcServer.ts | 8 ++--- node/src/WebRtcServerTypes.ts | 8 ++--- node/src/WebRtcTransport.ts | 8 ++--- node/src/WebRtcTransportTypes.ts | 10 +++--- node/src/Worker.ts | 10 +++--- node/src/WorkerTypes.ts | 8 ++--- node/src/fbsUtils.ts | 2 +- node/src/index.ts | 6 ++-- node/src/ortc.ts | 4 +-- node/src/rtpParametersFbsUtils.ts | 2 +- node/src/sctpParametersFbsUtils.ts | 2 +- node/src/srtpParametersFbsUtils.ts | 2 +- node/src/supportedRtpCapabilities.ts | 2 +- node/src/test/test-ActiveSpeakerObserver.ts | 2 +- node/src/test/test-AudioLevelObserver.ts | 2 +- node/src/test/test-Consumer.ts | 4 +-- node/src/test/test-DataConsumer.ts | 2 +- node/src/test/test-DataProducer.ts | 2 +- node/src/test/test-DirectTransport.ts | 4 +-- node/src/test/test-PipeTransport.ts | 2 +- node/src/test/test-PlainTransport.ts | 2 +- node/src/test/test-Producer.ts | 4 +-- node/src/test/test-Router.ts | 4 +-- node/src/test/test-WebRtcServer.ts | 8 ++--- node/src/test/test-WebRtcTransport.ts | 6 ++-- node/src/test/test-Worker.ts | 2 +- node/src/test/test-mediasoup.ts | 2 +- node/src/test/test-multiopus.ts | 2 +- node/src/test/test-node-sctp.ts | 2 +- 53 files changed, 212 insertions(+), 200 deletions(-) diff --git a/node/src/ActiveSpeakerObserver.ts b/node/src/ActiveSpeakerObserver.ts index a78d54ed0c..47ee299fd8 100644 --- a/node/src/ActiveSpeakerObserver.ts +++ b/node/src/ActiveSpeakerObserver.ts @@ -1,15 +1,15 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { ActiveSpeakerObserver, ActiveSpeakerObserverDominantSpeaker, ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver, ActiveSpeakerObserverObserverEvents, } from './ActiveSpeakerObserverTypes'; -import { RtpObserver } from './RtpObserverTypes'; +import type { RtpObserver } from './RtpObserverTypes'; import { RtpObserverImpl, RtpObserverConstructorOptions } from './RtpObserver'; -import { AppData } from './types'; +import type { AppData } from './types'; import { Event, Notification } from './fbs/notification'; import * as FbsActiveSpeakerObserver from './fbs/active-speaker-observer'; diff --git a/node/src/ActiveSpeakerObserverTypes.ts b/node/src/ActiveSpeakerObserverTypes.ts index cd6822053a..18ae847822 100644 --- a/node/src/ActiveSpeakerObserverTypes.ts +++ b/node/src/ActiveSpeakerObserverTypes.ts @@ -1,11 +1,11 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { RtpObserver, RtpObserverEvents, RtpObserverObserverEvents, } from './RtpObserverTypes'; -import { Producer } from './ProducerTypes'; -import { AppData } from './types'; +import type { Producer } from './ProducerTypes'; +import type { AppData } from './types'; export type ActiveSpeakerObserverOptions< ActiveSpeakerObserverAppData extends AppData = AppData, diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index accf6caf27..46b4d41f76 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -1,16 +1,16 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { AudioLevelObserver, AudioLevelObserverVolume, AudioLevelObserverEvents, AudioLevelObserverObserver, AudioLevelObserverObserverEvents, } from './AudioLevelObserverTypes'; -import { RtpObserver } from './RtpObserverTypes'; +import type { RtpObserver } from './RtpObserverTypes'; import { RtpObserverImpl, RtpObserverConstructorOptions } from './RtpObserver'; -import { Producer } from './ProducerTypes'; -import { AppData } from './types'; +import type { Producer } from './ProducerTypes'; +import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import * as FbsAudioLevelObserver from './fbs/audio-level-observer'; diff --git a/node/src/AudioLevelObserverTypes.ts b/node/src/AudioLevelObserverTypes.ts index ddff9fb985..a318db3609 100644 --- a/node/src/AudioLevelObserverTypes.ts +++ b/node/src/AudioLevelObserverTypes.ts @@ -1,11 +1,11 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { RtpObserver, RtpObserverEvents, RtpObserverObserverEvents, } from './RtpObserverTypes'; -import { Producer } from './ProducerTypes'; -import { AppData } from './types'; +import type { Producer } from './ProducerTypes'; +import type { AppData } from './types'; export type AudioLevelObserverOptions< AudioLevelObserverAppData extends AppData = AppData, diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index 020fa92a82..02f331ad9b 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -1,6 +1,6 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { Consumer, ConsumerType, ConsumerScore, @@ -23,15 +23,15 @@ import { ConsumerObserverEvents, } from './ConsumerTypes'; import { Channel } from './Channel'; -import { TransportInternal } from './Transport'; -import { ProducerStat } from './ProducerTypes'; -import { MediaKind, RtpParameters } from './rtpParametersTypes'; +import type { TransportInternal } from './Transport'; +import type { ProducerStat } from './ProducerTypes'; +import type { MediaKind, RtpParameters } from './rtpParametersTypes'; import { parseRtpEncodingParameters, parseRtpParameters, } from './rtpParametersFbsUtils'; import { parseRtpStreamStats } from './RtpStream'; -import { AppData } from './types'; +import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import { TraceDirection as FbsTraceDirection } from './fbs/common'; diff --git a/node/src/ConsumerTypes.ts b/node/src/ConsumerTypes.ts index 103eeca565..94c21db96c 100644 --- a/node/src/ConsumerTypes.ts +++ b/node/src/ConsumerTypes.ts @@ -1,13 +1,13 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { ProducerStat } from './ProducerTypes'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { ProducerStat } from './ProducerTypes'; +import type { MediaKind, RtpCapabilities, RtpEncodingParameters, RtpParameters, } from './rtpParametersTypes'; -import { RtpStreamSendStats } from './RtpStream'; -import { AppData } from './types'; +import type { RtpStreamSendStats } from './RtpStream'; +import type { AppData } from './types'; export type ConsumerOptions = { /** diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index 1a925c57b4..95feca2a43 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -1,6 +1,6 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { DataConsumer, DataConsumerType, DataConsumerDump, @@ -10,10 +10,10 @@ import { DataConsumerObserverEvents, } from './DataConsumerTypes'; import { Channel } from './Channel'; -import { TransportInternal } from './Transport'; -import { SctpStreamParameters } from './sctpParametersTypes'; +import type { TransportInternal } from './Transport'; +import type { SctpStreamParameters } from './sctpParametersTypes'; import { parseSctpStreamParameters } from './sctpParametersFbsUtils'; -import { AppData } from './types'; +import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import * as FbsTransport from './fbs/transport'; diff --git a/node/src/DataConsumerTypes.ts b/node/src/DataConsumerTypes.ts index 1234873c91..5f0d06815c 100644 --- a/node/src/DataConsumerTypes.ts +++ b/node/src/DataConsumerTypes.ts @@ -1,6 +1,6 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { SctpStreamParameters } from './sctpParametersTypes'; -import { AppData } from './types'; +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { SctpStreamParameters } from './sctpParametersTypes'; +import type { AppData } from './types'; export type DataConsumerOptions = { diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index 2951d9e2a8..d64a53b05e 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -1,6 +1,6 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { DataProducer, DataProducerType, DataProducerDump, @@ -10,10 +10,10 @@ import { DataProducerObserverEvents, } from './DataProducerTypes'; import { Channel } from './Channel'; -import { TransportInternal } from './Transport'; -import { SctpStreamParameters } from './sctpParametersTypes'; +import type { TransportInternal } from './Transport'; +import type { SctpStreamParameters } from './sctpParametersTypes'; import { parseSctpStreamParameters } from './sctpParametersFbsUtils'; -import { AppData } from './types'; +import type { AppData } from './types'; import * as FbsTransport from './fbs/transport'; import * as FbsNotification from './fbs/notification'; import * as FbsRequest from './fbs/request'; diff --git a/node/src/DataProducerTypes.ts b/node/src/DataProducerTypes.ts index 1690ecbc2d..efb64d35bf 100644 --- a/node/src/DataProducerTypes.ts +++ b/node/src/DataProducerTypes.ts @@ -1,6 +1,6 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { SctpStreamParameters } from './sctpParametersTypes'; -import { AppData } from './types'; +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { SctpStreamParameters } from './sctpParametersTypes'; +import type { AppData } from './types'; export type DataProducerOptions = { diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index 808523ebc4..69dd3b3bb4 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -1,6 +1,6 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { DirectTransport, DirectTransportDump, DirectTransportStat, @@ -8,7 +8,7 @@ import { DirectTransportObserver, DirectTransportObserverEvents, } from './DirectTransportTypes'; -import { Transport, BaseTransportDump } from './TransportTypes'; +import type { Transport, BaseTransportDump } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -16,8 +16,8 @@ import { parseBaseTransportStats, parseTransportTraceEventData, } from './Transport'; -import { SctpParameters } from './sctpParametersTypes'; -import { AppData } from './types'; +import type { SctpParameters } from './sctpParametersTypes'; +import type { AppData } from './types'; import { UnsupportedError } from './errors'; import { Event, Notification } from './fbs/notification'; import * as FbsDirectTransport from './fbs/direct-transport'; diff --git a/node/src/DirectTransportTypes.ts b/node/src/DirectTransportTypes.ts index 97d7c63b90..fd9c23fc91 100644 --- a/node/src/DirectTransportTypes.ts +++ b/node/src/DirectTransportTypes.ts @@ -1,12 +1,12 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { Transport, BaseTransportDump, BaseTransportStats, TransportEvents, TransportObserverEvents, } from './TransportTypes'; -import { AppData } from './types'; +import type { AppData } from './types'; export type DirectTransportOptions< DirectTransportAppData extends AppData = AppData, diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index 614010266c..76af3acb1a 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -2,7 +2,7 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; -import { +import type { PipeTransport, PipeConsumerOptions, PipeTransportDump, @@ -11,7 +11,7 @@ import { PipeTransportObserver, PipeTransportObserverEvents, } from './PipeTransportTypes'; -import { Transport, TransportTuple, SctpState } from './TransportTypes'; +import type { Transport, TransportTuple, SctpState } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -21,21 +21,21 @@ import { parseTuple, parseTransportTraceEventData, } from './Transport'; -import { Producer } from './ProducerTypes'; -import { Consumer, ConsumerType } from './ConsumerTypes'; +import type { Producer } from './ProducerTypes'; +import type { Consumer, ConsumerType } from './ConsumerTypes'; import { ConsumerImpl } from './Consumer'; -import { RtpParameters } from './rtpParametersTypes'; +import type { RtpParameters } from './rtpParametersTypes'; import { serializeRtpEncodingParameters, serializeRtpParameters, } from './rtpParametersFbsUtils'; -import { SctpParameters } from './sctpParametersTypes'; -import { SrtpParameters } from './srtpParametersTypes'; +import type { SctpParameters } from './sctpParametersTypes'; +import type { SrtpParameters } from './srtpParametersTypes'; import { parseSrtpParameters, serializeSrtpParameters, } from './srtpParametersFbsUtils'; -import { AppData } from './types'; +import type { AppData } from './types'; import { generateUUIDv4 } from './utils'; import { MediaKind as FbsMediaKind } from './fbs/rtp-parameters/media-kind'; import * as FbsRtpParameters from './fbs/rtp-parameters'; diff --git a/node/src/PipeTransportTypes.ts b/node/src/PipeTransportTypes.ts index c0e18e2024..705a4a7c04 100644 --- a/node/src/PipeTransportTypes.ts +++ b/node/src/PipeTransportTypes.ts @@ -1,5 +1,5 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { Transport, TransportListenInfo, TransportListenIp, @@ -10,10 +10,10 @@ import { TransportEvents, TransportObserverEvents, } from './TransportTypes'; -import { Consumer } from './ConsumerTypes'; -import { SrtpParameters } from './srtpParametersTypes'; -import { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; -import { Either, AppData } from './types'; +import type { Consumer } from './ConsumerTypes'; +import type { SrtpParameters } from './srtpParametersTypes'; +import type { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; +import type { Either, AppData } from './types'; export type PipeTransportOptions< PipeTransportAppData extends AppData = AppData, diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index 6c57ff4947..e1e9138838 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -1,7 +1,7 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { PlainTransport, PlainTransportDump, PlainTransportStat, @@ -9,7 +9,7 @@ import { PlainTransportObserver, PlainTransportObserverEvents, } from './PlainTransportTypes'; -import { Transport, TransportTuple, SctpState } from './TransportTypes'; +import type { Transport, TransportTuple, SctpState } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -19,13 +19,13 @@ import { parseBaseTransportStats, parseTransportTraceEventData, } from './Transport'; -import { SctpParameters } from './sctpParametersTypes'; -import { SrtpParameters } from './srtpParametersTypes'; +import type { SctpParameters } from './sctpParametersTypes'; +import type { SrtpParameters } from './srtpParametersTypes'; import { parseSrtpParameters, serializeSrtpParameters, } from './srtpParametersFbsUtils'; -import { AppData } from './types'; +import type { AppData } from './types'; import { Event, Notification } from './fbs/notification'; import * as FbsRequest from './fbs/request'; import * as FbsTransport from './fbs/transport'; diff --git a/node/src/PlainTransportTypes.ts b/node/src/PlainTransportTypes.ts index 04ef6aa76c..ab65d2b6b5 100644 --- a/node/src/PlainTransportTypes.ts +++ b/node/src/PlainTransportTypes.ts @@ -1,5 +1,5 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { Transport, TransportListenInfo, TransportListenIp, @@ -10,9 +10,9 @@ import { TransportEvents, TransportObserverEvents, } from './TransportTypes'; -import { SrtpParameters, SrtpCryptoSuite } from './srtpParametersTypes'; -import { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; -import { Either, AppData } from './types'; +import type { SrtpParameters, SrtpCryptoSuite } from './srtpParametersTypes'; +import type { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; +import type { Either, AppData } from './types'; export type PlainTransportOptions< PlainTransportAppData extends AppData = AppData, diff --git a/node/src/Producer.ts b/node/src/Producer.ts index 07b1bba875..f7e5770057 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -1,6 +1,6 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { Producer, ProducerType, ProducerScore, @@ -14,11 +14,11 @@ import { ProducerObserverEvents, } from './ProducerTypes'; import { Channel } from './Channel'; -import { TransportInternal } from './Transport'; -import { MediaKind, RtpParameters } from './rtpParametersTypes'; +import type { TransportInternal } from './Transport'; +import type { MediaKind, RtpParameters } from './rtpParametersTypes'; import { parseRtpParameters } from './rtpParametersFbsUtils'; import { parseRtpStreamRecvStats } from './RtpStream'; -import { AppData } from './types'; +import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import { TraceDirection as FbsTraceDirection } from './fbs/common'; diff --git a/node/src/ProducerTypes.ts b/node/src/ProducerTypes.ts index 9f74632a7a..8a49d3e14f 100644 --- a/node/src/ProducerTypes.ts +++ b/node/src/ProducerTypes.ts @@ -1,7 +1,7 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { MediaKind, RtpParameters } from './rtpParametersTypes'; -import { RtpStreamRecvStats } from './RtpStream'; -import { AppData } from './types'; +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { MediaKind, RtpParameters } from './rtpParametersTypes'; +import type { RtpStreamRecvStats } from './RtpStream'; +import type { AppData } from './types'; export type ProducerOptions = { /** diff --git a/node/src/Router.ts b/node/src/Router.ts index 988bee6e6b..d80244a0fb 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -2,8 +2,8 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; import { InvalidStateError } from './errors'; -import { Channel } from './Channel'; -import { +import type { Channel } from './Channel'; +import type { Router, PipeToRouterOptions, PipeToRouterResult, @@ -13,13 +13,13 @@ import { RouterObserver, RouterObserverEvents, } from './RouterTypes'; -import { +import type { Transport, TransportListenIp, TransportProtocol, } from './TransportTypes'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; -import { +import type { WebRtcTransport, WebRtcTransportOptions, } from './WebRtcTransportTypes'; @@ -27,17 +27,20 @@ import { WebRtcTransportImpl, parseWebRtcTransportDumpResponse, } from './WebRtcTransport'; -import { PlainTransport, PlainTransportOptions } from './PlainTransportTypes'; +import type { + PlainTransport, + PlainTransportOptions, +} from './PlainTransportTypes'; import { PlainTransportImpl, parsePlainTransportDumpResponse, } from './PlainTransport'; -import { PipeTransport, PipeTransportOptions } from './PipeTransportTypes'; +import type { PipeTransport, PipeTransportOptions } from './PipeTransportTypes'; import { PipeTransportImpl, parsePipeTransportDumpResponse, } from './PipeTransport'; -import { +import type { DirectTransport, DirectTransportOptions, } from './DirectTransportTypes'; @@ -45,24 +48,24 @@ import { DirectTransportImpl, parseDirectTransportDumpResponse, } from './DirectTransport'; -import { Producer } from './ProducerTypes'; -import { Consumer } from './ConsumerTypes'; -import { DataProducer } from './DataProducerTypes'; -import { DataConsumer } from './DataConsumerTypes'; -import { RtpObserver } from './RtpObserverTypes'; -import { +import type { Producer } from './ProducerTypes'; +import type { Consumer } from './ConsumerTypes'; +import type { DataProducer } from './DataProducerTypes'; +import type { DataConsumer } from './DataConsumerTypes'; +import type { RtpObserver } from './RtpObserverTypes'; +import type { ActiveSpeakerObserver, ActiveSpeakerObserverOptions, } from './ActiveSpeakerObserverTypes'; import { ActiveSpeakerObserverImpl } from './ActiveSpeakerObserver'; -import { +import type { AudioLevelObserver, AudioLevelObserverOptions, } from './AudioLevelObserverTypes'; import { AudioLevelObserverImpl } from './AudioLevelObserver'; -import { RtpCapabilities } from './rtpParametersTypes'; +import type { RtpCapabilities } from './rtpParametersTypes'; import { cryptoSuiteToFbs } from './srtpParametersFbsUtils'; -import { AppData } from './types'; +import type { AppData } from './types'; import * as utils from './utils'; import * as fbsUtils from './fbsUtils'; import * as FbsActiveSpeakerObserver from './fbs/active-speaker-observer'; diff --git a/node/src/RouterTypes.ts b/node/src/RouterTypes.ts index c435d60041..5a7db9be1e 100644 --- a/node/src/RouterTypes.ts +++ b/node/src/RouterTypes.ts @@ -1,35 +1,38 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { Transport, TransportListenInfo, TransportListenIp, } from './TransportTypes'; -import { +import type { WebRtcTransport, WebRtcTransportOptions, } from './WebRtcTransportTypes'; -import { PlainTransport, PlainTransportOptions } from './PlainTransportTypes'; -import { PipeTransport, PipeTransportOptions } from './PipeTransportTypes'; -import { +import type { + PlainTransport, + PlainTransportOptions, +} from './PlainTransportTypes'; +import type { PipeTransport, PipeTransportOptions } from './PipeTransportTypes'; +import type { DirectTransport, DirectTransportOptions, } from './DirectTransportTypes'; -import { Producer } from './ProducerTypes'; -import { Consumer } from './ConsumerTypes'; -import { DataProducer } from './DataProducerTypes'; -import { DataConsumer } from './DataConsumerTypes'; -import { RtpObserver } from './RtpObserverTypes'; -import { +import type { Producer } from './ProducerTypes'; +import type { Consumer } from './ConsumerTypes'; +import type { DataProducer } from './DataProducerTypes'; +import type { DataConsumer } from './DataConsumerTypes'; +import type { RtpObserver } from './RtpObserverTypes'; +import type { ActiveSpeakerObserver, ActiveSpeakerObserverOptions, } from './ActiveSpeakerObserverTypes'; -import { +import type { AudioLevelObserver, AudioLevelObserverOptions, } from './AudioLevelObserverTypes'; -import { RtpCapabilities, RtpCodecCapability } from './rtpParametersTypes'; -import { NumSctpStreams } from './sctpParametersTypes'; -import { Either, AppData } from './types'; +import type { RtpCapabilities, RtpCodecCapability } from './rtpParametersTypes'; +import type { NumSctpStreams } from './sctpParametersTypes'; +import type { Either, AppData } from './types'; export type RouterOptions = { /** diff --git a/node/src/RtpObserver.ts b/node/src/RtpObserver.ts index 9b04126899..ec42cedc6d 100644 --- a/node/src/RtpObserver.ts +++ b/node/src/RtpObserver.ts @@ -1,10 +1,13 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { RtpObserverEvents, RtpObserverObserver } from './RtpObserverTypes'; -import { Channel } from './Channel'; -import { RouterInternal } from './Router'; -import { Producer } from './ProducerTypes'; -import { AppData } from './types'; +import type { + RtpObserverEvents, + RtpObserverObserver, +} from './RtpObserverTypes'; +import type { Channel } from './Channel'; +import type { RouterInternal } from './Router'; +import type { Producer } from './ProducerTypes'; +import type { AppData } from './types'; import * as FbsRequest from './fbs/request'; import * as FbsRouter from './fbs/router'; import * as FbsRtpObserver from './fbs/rtp-observer'; diff --git a/node/src/RtpObserverTypes.ts b/node/src/RtpObserverTypes.ts index 15a6bcdad5..48d064e6ef 100644 --- a/node/src/RtpObserverTypes.ts +++ b/node/src/RtpObserverTypes.ts @@ -1,6 +1,6 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { Producer } from './ProducerTypes'; -import { AppData } from './types'; +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { Producer } from './ProducerTypes'; +import type { AppData } from './types'; export type RtpObserverEvents = { routerclose: []; diff --git a/node/src/Transport.ts b/node/src/Transport.ts index c90bf8b676..64a79b5e65 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -2,7 +2,7 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; -import { +import type { Transport, TransportProtocol, TransportPortRange, @@ -19,26 +19,26 @@ import { TransportEvents, TransportObserver, } from './TransportTypes'; -import { Channel } from './Channel'; -import { RouterInternal } from './Router'; -import { WebRtcTransportData } from './WebRtcTransport'; -import { PlainTransportData } from './PlainTransport'; -import { PipeTransportData } from './PipeTransport'; -import { DirectTransportData } from './DirectTransport'; -import { Producer, ProducerOptions } from './ProducerTypes'; +import type { Channel } from './Channel'; +import type { RouterInternal } from './Router'; +import type { WebRtcTransportData } from './WebRtcTransport'; +import type { PlainTransportData } from './PlainTransport'; +import type { PipeTransportData } from './PipeTransport'; +import type { DirectTransportData } from './DirectTransport'; +import type { Producer, ProducerOptions } from './ProducerTypes'; import { ProducerImpl, producerTypeFromFbs, producerTypeToFbs, } from './Producer'; -import { +import type { Consumer, ConsumerOptions, ConsumerType, ConsumerLayers, } from './ConsumerTypes'; import { ConsumerImpl } from './Consumer'; -import { +import type { DataProducer, DataProducerOptions, DataProducerType, @@ -48,7 +48,7 @@ import { dataProducerTypeToFbs, parseDataProducerDumpResponse, } from './DataProducer'; -import { +import type { DataConsumer, DataConsumerOptions, DataConsumerType, @@ -58,7 +58,7 @@ import { dataConsumerTypeToFbs, parseDataConsumerDumpResponse, } from './DataConsumer'; -import { +import type { MediaKind, RtpCapabilities, RtpParameters, @@ -67,12 +67,15 @@ import { serializeRtpEncodingParameters, serializeRtpParameters, } from './rtpParametersFbsUtils'; -import { SctpParameters, SctpStreamParameters } from './sctpParametersTypes'; +import type { + SctpParameters, + SctpStreamParameters, +} from './sctpParametersTypes'; import { parseSctpParametersDump, serializeSctpStreamParameters, } from './sctpParametersFbsUtils'; -import { AppData } from './types'; +import type { AppData } from './types'; import * as utils from './utils'; import * as fbsUtils from './fbsUtils'; import { TraceDirection as FbsTraceDirection } from './fbs/common'; diff --git a/node/src/TransportTypes.ts b/node/src/TransportTypes.ts index 65a3c12200..ea7d4d7214 100644 --- a/node/src/TransportTypes.ts +++ b/node/src/TransportTypes.ts @@ -1,10 +1,10 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { Producer, ProducerOptions } from './ProducerTypes'; -import { Consumer, ConsumerOptions } from './ConsumerTypes'; -import { DataProducer, DataProducerOptions } from './DataProducerTypes'; -import { DataConsumer, DataConsumerOptions } from './DataConsumerTypes'; -import { SctpParameters } from './sctpParametersTypes'; -import { AppData } from './types'; +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { Producer, ProducerOptions } from './ProducerTypes'; +import type { Consumer, ConsumerOptions } from './ConsumerTypes'; +import type { DataProducer, DataProducerOptions } from './DataProducerTypes'; +import type { DataConsumer, DataConsumerOptions } from './DataConsumerTypes'; +import type { SctpParameters } from './sctpParametersTypes'; +import type { AppData } from './types'; export type TransportListenInfo = { /** diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index d389862508..329009f110 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -1,7 +1,7 @@ import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { Channel } from './Channel'; -import { +import type { Channel } from './Channel'; +import type { WebRtcServer, IpPort, IceUserNameFragment, @@ -11,8 +11,8 @@ import { WebRtcServerObserver, WebRtcServerObserverEvents, } from './WebRtcServerTypes'; -import { WebRtcTransport } from './WebRtcTransportTypes'; -import { AppData } from './types'; +import type { WebRtcTransport } from './WebRtcTransportTypes'; +import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Body as RequestBody, Method } from './fbs/request'; import * as FbsWorker from './fbs/worker'; diff --git a/node/src/WebRtcServerTypes.ts b/node/src/WebRtcServerTypes.ts index 122c79c404..936e4af7cd 100644 --- a/node/src/WebRtcServerTypes.ts +++ b/node/src/WebRtcServerTypes.ts @@ -1,7 +1,7 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { TransportListenInfo } from './TransportTypes'; -import { WebRtcTransport } from './WebRtcTransportTypes'; -import { AppData } from './types'; +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { TransportListenInfo } from './TransportTypes'; +import type { WebRtcTransport } from './WebRtcTransportTypes'; +import type { AppData } from './types'; export type WebRtcServerOptions = { diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index 68acd22340..f5cc4caf9d 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -1,7 +1,7 @@ import * as flatbuffers from 'flatbuffers'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { WebRtcTransport, IceParameters, IceCandidate, @@ -20,7 +20,7 @@ import { WebRtcTransportObserver, WebRtcTransportObserverEvents, } from './WebRtcTransportTypes'; -import { Transport, TransportTuple, SctpState } from './TransportTypes'; +import type { Transport, TransportTuple, SctpState } from './TransportTypes'; import { TransportImpl, TransportConstructorOptions, @@ -31,8 +31,8 @@ import { parseTransportTraceEventData, parseTuple, } from './Transport'; -import { SctpParameters } from './sctpParametersTypes'; -import { AppData } from './types'; +import type { SctpParameters } from './sctpParametersTypes'; +import type { AppData } from './types'; import * as fbsUtils from './fbsUtils'; import { Event, Notification } from './fbs/notification'; import * as FbsRequest from './fbs/request'; diff --git a/node/src/WebRtcTransportTypes.ts b/node/src/WebRtcTransportTypes.ts index 37fda80619..382af7fb24 100644 --- a/node/src/WebRtcTransportTypes.ts +++ b/node/src/WebRtcTransportTypes.ts @@ -1,5 +1,5 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { Transport, TransportListenInfo, TransportListenIp, @@ -11,9 +11,9 @@ import { TransportEvents, TransportObserverEvents, } from './TransportTypes'; -import { WebRtcServer } from './WebRtcServerTypes'; -import { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; -import { Either, AppData } from './types'; +import type { WebRtcServer } from './WebRtcServerTypes'; +import type { SctpParameters, NumSctpStreams } from './sctpParametersTypes'; +import type { Either, AppData } from './types'; export type WebRtcTransportOptions< WebRtcTransportAppData extends AppData = AppData, diff --git a/node/src/Worker.ts b/node/src/Worker.ts index e6dfedd4ea..d144c8815f 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -5,7 +5,7 @@ import { version } from './'; import { Logger } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; -import { +import type { Worker, WorkerSettings, WorkerUpdateableSettings, @@ -16,15 +16,15 @@ import { WorkerObserverEvents, } from './WorkerTypes'; import { Channel } from './Channel'; -import { WebRtcServer, WebRtcServerOptions } from './WebRtcServerTypes'; +import type { WebRtcServer, WebRtcServerOptions } from './WebRtcServerTypes'; import { WebRtcServerImpl } from './WebRtcServer'; -import { Router, RouterOptions } from './RouterTypes'; +import type { Router, RouterOptions } from './RouterTypes'; import { RouterImpl } from './Router'; import { portRangeToFbs, socketFlagsToFbs } from './Transport'; -import { RtpCodecCapability } from './rtpParametersTypes'; +import type { RtpCodecCapability } from './rtpParametersTypes'; import * as utils from './utils'; import * as fbsUtils from './fbsUtils'; -import { AppData } from './types'; +import type { AppData } from './types'; import { Event } from './fbs/notification'; import * as FbsRequest from './fbs/request'; import * as FbsWorker from './fbs/worker'; diff --git a/node/src/WorkerTypes.ts b/node/src/WorkerTypes.ts index 15e7a32b34..337b0c4ea8 100644 --- a/node/src/WorkerTypes.ts +++ b/node/src/WorkerTypes.ts @@ -1,7 +1,7 @@ -import { EnhancedEventEmitter } from './enhancedEvents'; -import { WebRtcServer, WebRtcServerOptions } from './WebRtcServerTypes'; -import { Router, RouterOptions } from './RouterTypes'; -import { AppData } from './types'; +import type { EnhancedEventEmitter } from './enhancedEvents'; +import type { WebRtcServer, WebRtcServerOptions } from './WebRtcServerTypes'; +import type { Router, RouterOptions } from './RouterTypes'; +import type { AppData } from './types'; export type WorkerLogLevel = 'debug' | 'warn' | 'error' | 'none'; diff --git a/node/src/fbsUtils.ts b/node/src/fbsUtils.ts index ba3a369fe7..56e55c73c1 100644 --- a/node/src/fbsUtils.ts +++ b/node/src/fbsUtils.ts @@ -1,4 +1,4 @@ -import { Type as FbsRtpParametersType } from './fbs/rtp-parameters'; +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 5169c0bbef..3a82941f34 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -1,11 +1,11 @@ import { Logger, LoggerEmitter } from './Logger'; import { EnhancedEventEmitter } from './enhancedEvents'; -import { Worker, WorkerSettings } from './WorkerTypes'; +import type { Worker, WorkerSettings } from './WorkerTypes'; import { WorkerImpl, workerBin } from './Worker'; import * as utils from './utils'; import { supportedRtpCapabilities } from './supportedRtpCapabilities'; -import { RtpCapabilities } from './rtpParametersTypes'; -import * as types from './types'; +import type { RtpCapabilities } from './rtpParametersTypes'; +import type * as types from './types'; /** * Expose all types. diff --git a/node/src/ortc.ts b/node/src/ortc.ts index cc3770bd4f..1a03faa30f 100644 --- a/node/src/ortc.ts +++ b/node/src/ortc.ts @@ -2,7 +2,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 { +import type { RtpCapabilities, MediaKind, RtpCodecCapability, @@ -14,7 +14,7 @@ import { RtpHeaderExtensionParameters, RtcpParameters, } from './rtpParametersTypes'; -import { SctpStreamParameters } from './sctpParametersTypes'; +import type { SctpStreamParameters } from './sctpParametersTypes'; import * as utils from './utils'; import { UnsupportedError } from './errors'; import * as FbsRtpParameters from './fbs/rtp-parameters'; diff --git a/node/src/rtpParametersFbsUtils.ts b/node/src/rtpParametersFbsUtils.ts index 88656d1aaa..727eb1cd1e 100644 --- a/node/src/rtpParametersFbsUtils.ts +++ b/node/src/rtpParametersFbsUtils.ts @@ -1,5 +1,5 @@ import * as flatbuffers from 'flatbuffers'; -import { +import type { RtpParameters, RtpCodecParameters, RtcpFeedback, diff --git a/node/src/sctpParametersFbsUtils.ts b/node/src/sctpParametersFbsUtils.ts index b8b5375c51..a99f86d88b 100644 --- a/node/src/sctpParametersFbsUtils.ts +++ b/node/src/sctpParametersFbsUtils.ts @@ -1,5 +1,5 @@ import * as flatbuffers from 'flatbuffers'; -import { +import type { SctpStreamParameters, SctpParametersDump, } from './sctpParametersTypes'; diff --git a/node/src/srtpParametersFbsUtils.ts b/node/src/srtpParametersFbsUtils.ts index 3cc69fd480..b7b5f0dc48 100644 --- a/node/src/srtpParametersFbsUtils.ts +++ b/node/src/srtpParametersFbsUtils.ts @@ -1,5 +1,5 @@ import * as flatbuffers from 'flatbuffers'; -import { SrtpParameters, SrtpCryptoSuite } from './srtpParametersTypes'; +import type { SrtpParameters, SrtpCryptoSuite } from './srtpParametersTypes'; import * as FbsSrtpParameters from './fbs/srtp-parameters'; export function cryptoSuiteFromFbs( diff --git a/node/src/supportedRtpCapabilities.ts b/node/src/supportedRtpCapabilities.ts index a0f413b71c..2a0d1f5788 100644 --- a/node/src/supportedRtpCapabilities.ts +++ b/node/src/supportedRtpCapabilities.ts @@ -1,4 +1,4 @@ -import { RtpCapabilities } from './rtpParametersTypes'; +import type { RtpCapabilities } from './rtpParametersTypes'; const supportedRtpCapabilities: RtpCapabilities = { codecs: [ diff --git a/node/src/test/test-ActiveSpeakerObserver.ts b/node/src/test/test-ActiveSpeakerObserver.ts index 51a8d59190..2389ad9f2b 100644 --- a/node/src/test/test-ActiveSpeakerObserver.ts +++ b/node/src/test/test-ActiveSpeakerObserver.ts @@ -1,6 +1,6 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, ActiveSpeakerObserverEvents } from '../types'; +import type { WorkerEvents, ActiveSpeakerObserverEvents } from '../types'; import * as utils from '../utils'; type TestContext = { diff --git a/node/src/test/test-AudioLevelObserver.ts b/node/src/test/test-AudioLevelObserver.ts index f1a1a5fb17..33c45a19e9 100644 --- a/node/src/test/test-AudioLevelObserver.ts +++ b/node/src/test/test-AudioLevelObserver.ts @@ -1,6 +1,6 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, AudioLevelObserverEvents } from '../types'; +import type { WorkerEvents, AudioLevelObserverEvents } from '../types'; import * as utils from '../utils'; type TestContext = { diff --git a/node/src/test/test-Consumer.ts b/node/src/test/test-Consumer.ts index cc69554cd4..286076c27a 100644 --- a/node/src/test/test-Consumer.ts +++ b/node/src/test/test-Consumer.ts @@ -1,8 +1,8 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, ConsumerEvents } from '../types'; -import { ConsumerImpl } from '../Consumer'; +import type { WorkerEvents, ConsumerEvents } from '../types'; +import type { ConsumerImpl } from '../Consumer'; import { UnsupportedError } from '../errors'; import * as utils from '../utils'; import { diff --git a/node/src/test/test-DataConsumer.ts b/node/src/test/test-DataConsumer.ts index f61bb8291c..d8e800855b 100644 --- a/node/src/test/test-DataConsumer.ts +++ b/node/src/test/test-DataConsumer.ts @@ -1,6 +1,6 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, DataConsumerEvents } from '../types'; +import type { WorkerEvents, DataConsumerEvents } from '../types'; import * as utils from '../utils'; type TestContext = { diff --git a/node/src/test/test-DataProducer.ts b/node/src/test/test-DataProducer.ts index 4f490792ce..1dbd8691e7 100644 --- a/node/src/test/test-DataProducer.ts +++ b/node/src/test/test-DataProducer.ts @@ -1,6 +1,6 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, DataProducerEvents } from '../types'; +import type { WorkerEvents, DataProducerEvents } from '../types'; import * as utils from '../utils'; type TestContext = { diff --git a/node/src/test/test-DirectTransport.ts b/node/src/test/test-DirectTransport.ts index a9f773220d..1f6e95e47d 100644 --- a/node/src/test/test-DirectTransport.ts +++ b/node/src/test/test-DirectTransport.ts @@ -1,7 +1,7 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { DirectTransportEvents } from '../DirectTransportTypes'; -import { WorkerEvents } from '../types'; +import type { DirectTransportEvents } from '../DirectTransportTypes'; +import type { WorkerEvents } from '../types'; type TestContext = { worker?: mediasoup.types.Worker; diff --git a/node/src/test/test-PipeTransport.ts b/node/src/test/test-PipeTransport.ts index 1d7534ac04..19910e1e48 100644 --- a/node/src/test/test-PipeTransport.ts +++ b/node/src/test/test-PipeTransport.ts @@ -1,7 +1,7 @@ import { pickPort } from 'pick-port'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { +import type { WorkerEvents, ConsumerEvents, ProducerObserverEvents, diff --git a/node/src/test/test-PlainTransport.ts b/node/src/test/test-PlainTransport.ts index abd7c326b9..c8b8ded96b 100644 --- a/node/src/test/test-PlainTransport.ts +++ b/node/src/test/test-PlainTransport.ts @@ -2,7 +2,7 @@ import * as os from 'node:os'; import { pickPort } from 'pick-port'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, PlainTransportEvents } from '../types'; +import type { WorkerEvents, PlainTransportEvents } from '../types'; import * as utils from '../utils'; const IS_WINDOWS = os.platform() === 'win32'; diff --git a/node/src/test/test-Producer.ts b/node/src/test/test-Producer.ts index 3cdeae6ffb..38ad33607f 100644 --- a/node/src/test/test-Producer.ts +++ b/node/src/test/test-Producer.ts @@ -1,8 +1,8 @@ import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, ProducerEvents } from '../types'; -import { ProducerImpl } from '../Producer'; +import type { WorkerEvents, ProducerEvents } from '../types'; +import type { ProducerImpl } from '../Producer'; import { UnsupportedError } from '../errors'; import * as utils from '../utils'; import { diff --git a/node/src/test/test-Router.ts b/node/src/test/test-Router.ts index bc79574d9b..0affb75ef6 100644 --- a/node/src/test/test-Router.ts +++ b/node/src/test/test-Router.ts @@ -1,7 +1,7 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerImpl } from '../Worker'; -import { WorkerEvents, RouterEvents } from '../types'; +import type { WorkerImpl } from '../Worker'; +import type { WorkerEvents, RouterEvents } from '../types'; import { InvalidStateError } from '../errors'; import * as utils from '../utils'; diff --git a/node/src/test/test-WebRtcServer.ts b/node/src/test/test-WebRtcServer.ts index 2376e6569d..669e8ab8ef 100644 --- a/node/src/test/test-WebRtcServer.ts +++ b/node/src/test/test-WebRtcServer.ts @@ -1,10 +1,10 @@ import { pickPort } from 'pick-port'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerImpl } from '../Worker'; -import { WorkerEvents, WebRtcServerEvents } from '../types'; -import { WebRtcServerImpl } from '../WebRtcServer'; -import { RouterImpl } from '../Router'; +import type { WorkerImpl } from '../Worker'; +import type { WorkerEvents, WebRtcServerEvents } from '../types'; +import type { WebRtcServerImpl } from '../WebRtcServer'; +import type { RouterImpl } from '../Router'; import { InvalidStateError } from '../errors'; type TestContext = { diff --git a/node/src/test/test-WebRtcTransport.ts b/node/src/test/test-WebRtcTransport.ts index 8fad39909e..99cad042b1 100644 --- a/node/src/test/test-WebRtcTransport.ts +++ b/node/src/test/test-WebRtcTransport.ts @@ -2,9 +2,9 @@ import { pickPort } from 'pick-port'; import * as flatbuffers from 'flatbuffers'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents, WebRtcTransportEvents } from '../types'; -import { WebRtcTransportImpl } from '../WebRtcTransport'; -import { TransportTuple } from '../TransportTypes'; +import type { WorkerEvents, WebRtcTransportEvents } from '../types'; +import type { WebRtcTransportImpl } from '../WebRtcTransport'; +import type { TransportTuple } from '../TransportTypes'; import { serializeProtocol } from '../Transport'; import * as utils from '../utils'; import { diff --git a/node/src/test/test-Worker.ts b/node/src/test/test-Worker.ts index a00ba79fb0..ecf6210059 100644 --- a/node/src/test/test-Worker.ts +++ b/node/src/test/test-Worker.ts @@ -3,7 +3,7 @@ import * as process from 'node:process'; import * as path from 'node:path'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents } from '../types'; +import type { WorkerEvents } from '../types'; import { InvalidStateError } from '../errors'; test('Worker.workerBin matches mediasoup-worker absolute path', () => { diff --git a/node/src/test/test-mediasoup.ts b/node/src/test/test-mediasoup.ts index bfafad5f7f..98dad17115 100644 --- a/node/src/test/test-mediasoup.ts +++ b/node/src/test/test-mediasoup.ts @@ -2,7 +2,7 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; import { enhancedOnce } from '../enhancedEvents'; import * as mediasoup from '../'; -import { WorkerEvents } from '../types'; +import type { WorkerEvents } from '../types'; const PKG = JSON.parse( fs.readFileSync(path.join(__dirname, '..', '..', '..', 'package.json'), { diff --git a/node/src/test/test-multiopus.ts b/node/src/test/test-multiopus.ts index 4b8ab50450..e1925fe7a1 100644 --- a/node/src/test/test-multiopus.ts +++ b/node/src/test/test-multiopus.ts @@ -1,6 +1,6 @@ import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents } from '../types'; +import type { WorkerEvents } from '../types'; import { UnsupportedError } from '../errors'; import * as utils from '../utils'; diff --git a/node/src/test/test-node-sctp.ts b/node/src/test/test-node-sctp.ts index e344c1a484..87a79cbcc6 100644 --- a/node/src/test/test-node-sctp.ts +++ b/node/src/test/test-node-sctp.ts @@ -3,7 +3,7 @@ import * as dgram from 'node:dgram'; import * as sctp from 'sctp'; import * as mediasoup from '../'; import { enhancedOnce } from '../enhancedEvents'; -import { WorkerEvents } from '../types'; +import type { WorkerEvents } from '../types'; type TestContext = { worker?: mediasoup.types.Worker; 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 08/14] 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. From dc614c184c0882b3cb3a14cf4111846ea87e4f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sat, 9 Nov 2024 01:52:51 +0100 Subject: [PATCH 09/14] Remove Logger from EnhancedEventEmitter --- eslint.config.mjs | 1 + node/src/ActiveSpeakerObserver.ts | 10 ++++++++++ node/src/AudioLevelObserver.ts | 10 ++++++++++ node/src/Consumer.ts | 10 ++++++++++ node/src/DataConsumer.ts | 10 ++++++++++ node/src/DataProducer.ts | 10 ++++++++++ node/src/DirectTransport.ts | 10 ++++++++++ node/src/Logger.ts | 2 +- node/src/PipeTransport.ts | 10 ++++++++++ node/src/PlainTransport.ts | 10 ++++++++++ node/src/Producer.ts | 10 ++++++++++ node/src/Router.ts | 11 +++++++++++ node/src/Transport.ts | 2 +- node/src/WebRtcServer.ts | 11 +++++++++++ node/src/WebRtcTransport.ts | 10 ++++++++++ node/src/Worker.ts | 11 +++++++++++ node/src/enhancedEvents.ts | 9 +-------- node/src/ortc.ts | 11 +++++------ 18 files changed, 142 insertions(+), 16 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 858191d02c..110f1f7bb3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -90,6 +90,7 @@ const config = tsEslint.config( 2, { vars: 'all', args: 'after-used', caughtErrors: 'none' }, ], + 'no-unused-private-class-members': 2, 'no-use-before-define': 0, 'no-useless-call': 2, 'no-useless-computed-key': 2, diff --git a/node/src/ActiveSpeakerObserver.ts b/node/src/ActiveSpeakerObserver.ts index 47ee299fd8..2c5ccb741e 100644 --- a/node/src/ActiveSpeakerObserver.ts +++ b/node/src/ActiveSpeakerObserver.ts @@ -40,6 +40,7 @@ export class ActiveSpeakerObserverImpl< super(options, observer); this.handleWorkerNotifications(); + this.handleListenerError(); } /** @@ -85,4 +86,13 @@ export class ActiveSpeakerObserverImpl< } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index 46b4d41f76..4c0c6bed8d 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -42,6 +42,7 @@ export class AudioLevelObserverImpl< super(options, observer); this.handleWorkerNotifications(); + this.handleListenerError(); } /** @@ -108,6 +109,15 @@ export class AudioLevelObserverImpl< } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } function parseVolume(binary: FbsAudioLevelObserver.Volume): { diff --git a/node/src/Consumer.ts b/node/src/Consumer.ts index fe8c2fa924..ac092a5d2f 100644 --- a/node/src/Consumer.ts +++ b/node/src/Consumer.ts @@ -131,6 +131,7 @@ export class ConsumerImpl this.#appData = appData ?? ({} as ConsumerAppData); this.handleWorkerNotifications(); + this.handleListenerError(); } get id(): string { @@ -598,6 +599,15 @@ export class ConsumerImpl } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function parseTraceEventData( diff --git a/node/src/DataConsumer.ts b/node/src/DataConsumer.ts index 95feca2a43..3bcc932069 100644 --- a/node/src/DataConsumer.ts +++ b/node/src/DataConsumer.ts @@ -98,6 +98,7 @@ export class DataConsumerImpl this.#appData = appData ?? ({} as DataConsumerAppData); this.handleWorkerNotifications(); + this.handleListenerError(); } get id(): string { @@ -554,6 +555,15 @@ export class DataConsumerImpl } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function dataConsumerTypeToFbs( diff --git a/node/src/DataProducer.ts b/node/src/DataProducer.ts index d64a53b05e..e1c2c0f6e1 100644 --- a/node/src/DataProducer.ts +++ b/node/src/DataProducer.ts @@ -82,6 +82,7 @@ export class DataProducerImpl this.#appData = appData ?? ({} as DataProducerAppData); this.handleWorkerNotifications(); + this.handleListenerError(); } get id(): string { @@ -333,6 +334,15 @@ export class DataProducerImpl private handleWorkerNotifications(): void { // No need to subscribe to any event. } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function dataProducerTypeToFbs( diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index 69dd3b3bb4..432cca6299 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -65,6 +65,7 @@ export class DirectTransportImpl< }; this.handleWorkerNotifications(); + this.handleListenerError(); } get observer(): DirectTransportObserver { @@ -214,6 +215,15 @@ export class DirectTransportImpl< } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function parseDirectTransportDumpResponse( diff --git a/node/src/Logger.ts b/node/src/Logger.ts index 66b5456c0c..1dd0b30a75 100644 --- a/node/src/Logger.ts +++ b/node/src/Logger.ts @@ -1,5 +1,5 @@ import debug from 'debug'; -import { EnhancedEventEmitter } from './enhancedEvents'; +import type { EnhancedEventEmitter } from './enhancedEvents'; const APP_NAME = 'mediasoup'; diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index 76af3acb1a..36dcda04a2 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -89,6 +89,7 @@ export class PipeTransportImpl }; this.handleWorkerNotifications(); + this.handleListenerError(); } get observer(): PipeTransportObserver { @@ -328,6 +329,15 @@ export class PipeTransportImpl } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } /* diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index e1e9138838..fbfd8083e4 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -82,6 +82,7 @@ export class PlainTransportImpl }; this.handleWorkerNotifications(); + this.handleListenerError(); } get observer(): PlainTransportObserver { @@ -294,6 +295,15 @@ export class PlainTransportImpl } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function parsePlainTransportDumpResponse( diff --git a/node/src/Producer.ts b/node/src/Producer.ts index 732fc47728..9420b8f8eb 100644 --- a/node/src/Producer.ts +++ b/node/src/Producer.ts @@ -95,6 +95,7 @@ export class ProducerImpl this.#appData = appData ?? ({} as ProducerAppData); this.handleWorkerNotifications(); + this.handleListenerError(); } get id(): string { @@ -397,6 +398,15 @@ export class ProducerImpl } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function producerTypeFromFbs(type: FbsRtpParameters.Type): ProducerType { diff --git a/node/src/Router.ts b/node/src/Router.ts index d80244a0fb..ebe6a3f1a7 100644 --- a/node/src/Router.ts +++ b/node/src/Router.ts @@ -152,6 +152,8 @@ export class RouterImpl this.#data = data; this.#channel = channel; this.#appData = appData ?? ({} as RouterAppData); + + this.handleListenerError(); } get id(): string { @@ -1364,6 +1366,15 @@ export class RouterImpl return false; } } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function parseRouterDumpResponse( diff --git a/node/src/Transport.ts b/node/src/Transport.ts index 64a79b5e65..f9d3495cb7 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -1421,7 +1421,7 @@ function createProduceRequest({ producerId: string; kind: MediaKind; rtpParameters: RtpParameters; - rtpMapping: ortc.RtpMapping; + rtpMapping: ortc.RtpCodecsEncodingsMapping; keyFrameRequestDelay?: number; paused: boolean; }): number { diff --git a/node/src/WebRtcServer.ts b/node/src/WebRtcServer.ts index 329009f110..1a04379e2a 100644 --- a/node/src/WebRtcServer.ts +++ b/node/src/WebRtcServer.ts @@ -63,6 +63,8 @@ export class WebRtcServerImpl this.#internal = internal; this.#channel = channel; this.#appData = appData ?? ({} as WebRtcServerAppData); + + this.handleListenerError(); } get id(): string { @@ -179,6 +181,15 @@ export class WebRtcServerImpl this.#observer.safeEmit('webrtctransportunhandled', webRtcTransport); }); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } function parseIpPort(binary: FbsWebRtcServer.IpPort): IpPort { diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index f5cc4caf9d..a2b25c32d5 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -108,6 +108,7 @@ export class WebRtcTransportImpl< }; this.handleWorkerNotifications(); + this.handleListenerError(); } get observer(): WebRtcTransportObserver { @@ -395,6 +396,15 @@ export class WebRtcTransportImpl< } ); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } function iceStateFromFbs(fbsIceState: FbsIceState): IceState { diff --git a/node/src/Worker.ts b/node/src/Worker.ts index d144c8815f..b30c5d70ba 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -299,6 +299,8 @@ export class WorkerImpl } } }); + + this.handleListenerError(); } get pid(): number { @@ -584,6 +586,15 @@ export class WorkerImpl // Emit observer event. this.#observer.safeEmit('close'); } + + private handleListenerError(): void { + this.on('listenererror', (eventName, error) => { + logger.error( + `event listener threw an error [eventName:${eventName}]:`, + error + ); + }); + } } export function parseWorkerDumpResponse( diff --git a/node/src/enhancedEvents.ts b/node/src/enhancedEvents.ts index a0fbfba558..8f7a5eb59a 100644 --- a/node/src/enhancedEvents.ts +++ b/node/src/enhancedEvents.ts @@ -1,7 +1,4 @@ import { EventEmitter, once } from 'node:events'; -import { Logger } from './Logger'; - -const enhancedEventEmitterLogger = new Logger('EnhancedEventEmitter'); type Events = Record; @@ -10,6 +7,7 @@ export class EnhancedEventEmitter< > extends EventEmitter { constructor() { super(); + this.setMaxListeners(Infinity); } @@ -24,11 +22,6 @@ export class EnhancedEventEmitter< try { return super.emit(eventName, ...args); } catch (error) { - enhancedEventEmitterLogger.error( - `safeEmit() | event listener threw an error [eventName:${eventName}]:`, - error as Error - ); - try { super.emit('listenererror', eventName, error); } catch (error2) { diff --git a/node/src/ortc.ts b/node/src/ortc.ts index 3fa66de16f..be79bab7c2 100644 --- a/node/src/ortc.ts +++ b/node/src/ortc.ts @@ -19,12 +19,11 @@ import * as utils from './utils'; import { UnsupportedError } from './errors'; import * as FbsRtpParameters from './fbs/rtp-parameters'; -export type RtpMapping = { +export type RtpCodecsEncodingsMapping = { codecs: { payloadType: number; mappedPayloadType: number; }[]; - encodings: { ssrc?: number; rid?: string; @@ -309,8 +308,8 @@ export function generateRouterRtpCapabilities( export function getProducerRtpParametersMapping( params: RtpParameters, caps: RtpCapabilities -): RtpMapping { - const rtpMapping: RtpMapping = { +): RtpCodecsEncodingsMapping { + const rtpMapping: RtpCodecsEncodingsMapping = { codecs: [], encodings: [], }; @@ -415,7 +414,7 @@ export function getConsumableRtpParameters( kind: string, params: RtpParameters, caps: RtpCapabilities, - rtpMapping: RtpMapping + rtpMapping: RtpCodecsEncodingsMapping ): RtpParameters { const consumableParams: RtpParameters = { codecs: [], @@ -915,7 +914,7 @@ function matchCodecs( export function serializeRtpMapping( builder: flatbuffers.Builder, - rtpMapping: RtpMapping + rtpMapping: RtpCodecsEncodingsMapping ): number { const codecs: number[] = []; From aa5853cfe194580417adb2761deef96ed11620b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 11 Nov 2024 12:01:20 +0100 Subject: [PATCH 10/14] Add new `transport.type` getter than returns `'webrtc' | 'plain' | 'pipe' | 'direct'` --- eslint.config.mjs | 1 + node/src/DirectTransport.ts | 4 ++++ node/src/DirectTransportTypes.ts | 7 +++++++ node/src/PipeTransport.ts | 4 ++++ node/src/PipeTransportTypes.ts | 7 +++++++ node/src/PlainTransport.ts | 4 ++++ node/src/PlainTransportTypes.ts | 7 +++++++ node/src/Transport.ts | 13 ++++++------- node/src/TransportTypes.ts | 15 ++++++++++++++- node/src/WebRtcTransport.ts | 4 ++++ node/src/WebRtcTransportTypes.ts | 7 +++++++ node/src/test/test-DirectTransport.ts | 2 +- node/src/test/test-PipeTransport.ts | 2 ++ node/src/test/test-PlainTransport.ts | 5 ++--- node/src/test/test-WebRtcTransport.ts | 2 +- 15 files changed, 71 insertions(+), 13 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 110f1f7bb3..1e596554d8 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -128,6 +128,7 @@ const config = tsEslint.config( }, }, rules: { + '@typescript-eslint/class-literal-property-style': [2, 'getters'], '@typescript-eslint/consistent-generic-constructors': [ 2, 'type-annotation', diff --git a/node/src/DirectTransport.ts b/node/src/DirectTransport.ts index 432cca6299..a75d4b18bb 100644 --- a/node/src/DirectTransport.ts +++ b/node/src/DirectTransport.ts @@ -68,6 +68,10 @@ export class DirectTransportImpl< this.handleListenerError(); } + get type(): 'direct' { + return 'direct'; + } + get observer(): DirectTransportObserver { return super.observer; } diff --git a/node/src/DirectTransportTypes.ts b/node/src/DirectTransportTypes.ts index fd9c23fc91..85bb824341 100644 --- a/node/src/DirectTransportTypes.ts +++ b/node/src/DirectTransportTypes.ts @@ -47,6 +47,13 @@ export interface DirectTransport< DirectTransportEvents, DirectTransportObserver > { + /** + * Transport type. + * + * @override + */ + get type(): 'direct'; + /** * Observer. * diff --git a/node/src/PipeTransport.ts b/node/src/PipeTransport.ts index 36dcda04a2..266c0d50d4 100644 --- a/node/src/PipeTransport.ts +++ b/node/src/PipeTransport.ts @@ -92,6 +92,10 @@ export class PipeTransportImpl this.handleListenerError(); } + get type(): 'pipe' { + return 'pipe'; + } + get observer(): PipeTransportObserver { return super.observer; } diff --git a/node/src/PipeTransportTypes.ts b/node/src/PipeTransportTypes.ts index 705a4a7c04..4bc9734eb8 100644 --- a/node/src/PipeTransportTypes.ts +++ b/node/src/PipeTransportTypes.ts @@ -125,6 +125,13 @@ export interface PipeTransport PipeTransportEvents, PipeTransportObserver > { + /** + * Transport type. + * + * @override + */ + get type(): 'pipe'; + /** * Observer. * diff --git a/node/src/PlainTransport.ts b/node/src/PlainTransport.ts index fbfd8083e4..5e595152c1 100644 --- a/node/src/PlainTransport.ts +++ b/node/src/PlainTransport.ts @@ -85,6 +85,10 @@ export class PlainTransportImpl this.handleListenerError(); } + get type(): 'plain' { + return 'plain'; + } + get observer(): PlainTransportObserver { return super.observer; } diff --git a/node/src/PlainTransportTypes.ts b/node/src/PlainTransportTypes.ts index ab65d2b6b5..383a29c04a 100644 --- a/node/src/PlainTransportTypes.ts +++ b/node/src/PlainTransportTypes.ts @@ -137,6 +137,13 @@ export interface PlainTransport PlainTransportEvents, PlainTransportObserver > { + /** + * Transport type. + * + * @override + */ + get type(): 'plain'; + /** * Observer. * diff --git a/node/src/Transport.ts b/node/src/Transport.ts index f9d3495cb7..7bbc28f4dd 100644 --- a/node/src/Transport.ts +++ b/node/src/Transport.ts @@ -4,6 +4,7 @@ import { EnhancedEventEmitter } from './enhancedEvents'; import * as ortc from './ortc'; import type { Transport, + TransportType, TransportProtocol, TransportPortRange, TransportSocketFlags, @@ -208,6 +209,8 @@ export abstract class TransportImpl< return this.#closed; } + abstract get type(): TransportType; + get appData(): TransportAppData { return this.#appData; } @@ -481,8 +484,7 @@ export abstract class TransportImpl< // Don't do this in PipeTransports since there we must keep CNAME value in // each Producer. - // TODO: This is error prune if we rename the class name. - if (this.constructor.name !== 'PipeTransportImpl') { + if (this.type !== 'pipe') { // If CNAME is given and we don't have yet a CNAME for Producers in this // Transport, take it. if (!this.#cnameForProducers && clonedRtpParameters.rtcp?.cname) { @@ -724,8 +726,7 @@ export abstract class TransportImpl< >(sctpStreamParameters); // If this is not a DirectTransport, sctpStreamParameters are required. - // TODO: This is error prune if we rename the class name. - if (this.constructor.name !== 'DirectTransportImpl') { + if (this.type !== 'direct') { type = 'sctp'; // This may throw. @@ -831,8 +832,7 @@ export abstract class TransportImpl< // If this is not a DirectTransport, use sctpStreamParameters from the // DataProducer (if type 'sctp') unless they are given in method parameters. - // TODO: This is error prune if we rename the class name. - if (this.constructor.name !== 'DirectTransportImpl') { + if (this.type !== 'direct') { type = 'sctp'; sctpStreamParameters = @@ -1151,7 +1151,6 @@ export function parseBaseTransportDump( return { id: binary.id()!, - direct: binary.direct(), producerIds: producerIds, consumerIds: consumerIds, mapSsrcConsumerId: mapSsrcConsumerId, diff --git a/node/src/TransportTypes.ts b/node/src/TransportTypes.ts index ea7d4d7214..26aac8cbd5 100644 --- a/node/src/TransportTypes.ts +++ b/node/src/TransportTypes.ts @@ -6,6 +6,11 @@ import type { DataConsumer, DataConsumerOptions } from './DataConsumerTypes'; import type { SctpParameters } from './sctpParametersTypes'; import type { AppData } from './types'; +/** + * Transport type. + */ +export type TransportType = 'webrtc' | 'plain' | 'pipe' | 'direct'; + export type TransportListenInfo = { /** * Network protocol. @@ -145,7 +150,6 @@ export type RecvRtpHeaderExtensions = { export type BaseTransportDump = { id: string; - direct: boolean; producerIds: string[]; consumerIds: string[]; mapSsrcConsumerId: { key: number; value: string }[]; @@ -258,6 +262,15 @@ export interface Transport< */ get closed(): boolean; + /** + * Transport type. + * + * @virtual + * @privateRemarks + * - It's marked as virtual getter since each Transport class overrides it. + */ + get type(): TransportType; + /** * App custom data. */ diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index a2b25c32d5..e58e8756e1 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -111,6 +111,10 @@ export class WebRtcTransportImpl< this.handleListenerError(); } + get type(): 'webrtc' { + return 'webrtc'; + } + get observer(): WebRtcTransportObserver { return super.observer; } diff --git a/node/src/WebRtcTransportTypes.ts b/node/src/WebRtcTransportTypes.ts index 382af7fb24..b466da87e1 100644 --- a/node/src/WebRtcTransportTypes.ts +++ b/node/src/WebRtcTransportTypes.ts @@ -223,6 +223,13 @@ export interface WebRtcTransport< WebRtcTransportEvents, WebRtcTransportObserver > { + /** + * Transport type. + * + * @override + */ + get type(): 'webrtc'; + /** * Observer. * diff --git a/node/src/test/test-DirectTransport.ts b/node/src/test/test-DirectTransport.ts index 1f6e95e47d..a552e78b39 100644 --- a/node/src/test/test-DirectTransport.ts +++ b/node/src/test/test-DirectTransport.ts @@ -40,13 +40,13 @@ test('router.createDirectTransport() succeeds', async () => { expect(onObserverNewTransport).toHaveBeenCalledTimes(1); expect(onObserverNewTransport).toHaveBeenCalledWith(directTransport); expect(typeof directTransport.id).toBe('string'); + expect(directTransport.type).toBe('direct'); expect(directTransport.closed).toBe(false); expect(directTransport.appData).toEqual({ foo: 'bar' }); const dump = await directTransport.dump(); expect(dump.id).toBe(directTransport.id); - expect(dump.direct).toBe(true); expect(dump.producerIds).toEqual([]); expect(dump.consumerIds).toEqual([]); expect(dump.dataProducerIds).toEqual([]); diff --git a/node/src/test/test-PipeTransport.ts b/node/src/test/test-PipeTransport.ts index 19910e1e48..2bffccc5a8 100644 --- a/node/src/test/test-PipeTransport.ts +++ b/node/src/test/test-PipeTransport.ts @@ -524,6 +524,8 @@ test('router.createPipeTransport() with enableRtx succeeds', async () => { enableRtx: true, }); + expect(pipeTransport.type).toBe('pipe'); + const pipeConsumer = await pipeTransport.consume({ producerId: ctx.videoProducer!.id, }); diff --git a/node/src/test/test-PlainTransport.ts b/node/src/test/test-PlainTransport.ts index c8b8ded96b..9fd58564a6 100644 --- a/node/src/test/test-PlainTransport.ts +++ b/node/src/test/test-PlainTransport.ts @@ -91,6 +91,7 @@ test('router.createPlainTransport() succeeds', async () => { expect(onObserverNewTransport).toHaveBeenCalledWith(plainTransport2); expect(typeof plainTransport2.id).toBe('string'); expect(plainTransport2.closed).toBe(false); + expect(plainTransport2.type).toBe('plain'); expect(plainTransport2.appData).toEqual({ foo: 'bar' }); expect(typeof plainTransport2.tuple).toBe('object'); // @deprecated Use tuple.localAddress instead. @@ -111,7 +112,6 @@ test('router.createPlainTransport() succeeds', async () => { const dump1 = await plainTransport2.dump(); expect(dump1.id).toBe(plainTransport2.id); - expect(dump1.direct).toBe(false); expect(dump1.producerIds).toEqual([]); expect(dump1.consumerIds).toEqual([]); expect(dump1.tuple).toEqual(plainTransport2.tuple); @@ -166,7 +166,6 @@ test('router.createPlainTransport() succeeds', async () => { const dump2 = await transport2.dump(); expect(dump2.id).toBe(transport2.id); - expect(dump2.direct).toBe(false); expect(dump2.tuple).toEqual(transport2.tuple); expect(dump2.rtcpTuple).toEqual(transport2.rtcpTuple); expect(dump2.sctpState).toBeUndefined(); @@ -196,7 +195,7 @@ test('router.createPlainTransport() with wrong arguments rejects with TypeError' ).rejects.toThrow(TypeError); await expect( - ctx.router!.createPipeTransport({ + ctx.router!.createPlainTransport({ listenInfo: { protocol: 'tcp', ip: '127.0.0.1' }, }) ).rejects.toThrow(TypeError); diff --git a/node/src/test/test-WebRtcTransport.ts b/node/src/test/test-WebRtcTransport.ts index 99cad042b1..a241bcf2f7 100644 --- a/node/src/test/test-WebRtcTransport.ts +++ b/node/src/test/test-WebRtcTransport.ts @@ -125,6 +125,7 @@ test('router.createWebRtcTransport() succeeds', async () => { expect(onObserverNewTransport).toHaveBeenCalledWith(webRtcTransport); expect(typeof webRtcTransport.id).toBe('string'); expect(webRtcTransport.closed).toBe(false); + expect(webRtcTransport.type).toBe('webrtc'); expect(webRtcTransport.appData).toEqual({ foo: 'bar' }); expect(webRtcTransport.iceRole).toBe('controlled'); expect(typeof webRtcTransport.iceParameters).toBe('object'); @@ -184,7 +185,6 @@ test('router.createWebRtcTransport() succeeds', async () => { const dump = await webRtcTransport.dump(); expect(dump.id).toBe(webRtcTransport.id); - expect(dump.direct).toBe(false); expect(dump.producerIds).toEqual([]); expect(dump.consumerIds).toEqual([]); expect(dump.iceRole).toBe(webRtcTransport.iceRole); From 9e2b2bcba597eb530199dfb6f38056117ea3a002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 11 Nov 2024 12:03:47 +0100 Subject: [PATCH 11/14] more CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69b07bb4fc..9cbe7141d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### NEXT - Node: Add TypeScript interfaces for all exported classes ([PR #1463](https://github.com/versatica/mediasoup/pull/1463)). +- Node: Add new `transport.type` getter than returns `'webrtc' | 'plain' | 'pipe' | 'direct'` ([PR #1463](https://github.com/versatica/mediasoup/pull/1463)). ### 3.14.16 From b882b2c7402f244ef8668d494a1038c7af876359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 11 Nov 2024 12:44:55 +0100 Subject: [PATCH 12/14] Add new `rtpObserver.type` getter than returns `'activespeaker' | 'audiolevel'` --- node/src/ActiveSpeakerObserver.ts | 12 ++++-------- node/src/ActiveSpeakerObserverTypes.ts | 7 +++++++ node/src/AudioLevelObserver.ts | 12 ++++-------- node/src/AudioLevelObserverTypes.ts | 7 +++++++ node/src/RtpObserverTypes.ts | 14 ++++++++++++++ node/src/test/test-ActiveSpeakerObserver.ts | 1 + node/src/test/test-AudioLevelObserver.ts | 1 + 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/node/src/ActiveSpeakerObserver.ts b/node/src/ActiveSpeakerObserver.ts index 2c5ccb741e..a46ac16ab4 100644 --- a/node/src/ActiveSpeakerObserver.ts +++ b/node/src/ActiveSpeakerObserver.ts @@ -28,9 +28,6 @@ export class ActiveSpeakerObserverImpl< > implements RtpObserver, ActiveSpeakerObserver { - /** - * @private - */ constructor( options: RtpObserverObserverConstructorOptions ) { @@ -43,11 +40,10 @@ export class ActiveSpeakerObserverImpl< this.handleListenerError(); } - /** - * Observer. - * - * @override - */ + get type(): 'activespeaker' { + return 'activespeaker'; + } + get observer(): ActiveSpeakerObserverObserver { return super.observer; } diff --git a/node/src/ActiveSpeakerObserverTypes.ts b/node/src/ActiveSpeakerObserverTypes.ts index 18ae847822..9d00005697 100644 --- a/node/src/ActiveSpeakerObserverTypes.ts +++ b/node/src/ActiveSpeakerObserverTypes.ts @@ -43,6 +43,13 @@ export interface ActiveSpeakerObserver< ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver > { + /** + * RtpObserver type. + * + * @override + */ + get type(): 'activespeaker'; + /** * Observer. * diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index 4c0c6bed8d..5890956fdb 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -30,9 +30,6 @@ export class AudioLevelObserverImpl< > implements RtpObserver, AudioLevelObserver { - /** - * @private - */ constructor( options: AudioLevelObserverConstructorOptions ) { @@ -45,11 +42,10 @@ export class AudioLevelObserverImpl< this.handleListenerError(); } - /** - * Observer. - * - * @override - */ + get type(): 'audiolevel' { + return 'audiolevel'; + } + get observer(): AudioLevelObserverObserver { return super.observer; } diff --git a/node/src/AudioLevelObserverTypes.ts b/node/src/AudioLevelObserverTypes.ts index a318db3609..dca5b0e568 100644 --- a/node/src/AudioLevelObserverTypes.ts +++ b/node/src/AudioLevelObserverTypes.ts @@ -65,6 +65,13 @@ export interface AudioLevelObserver< AudioLevelObserverEvents, AudioLevelObserverObserver > { + /** + * RtpObserver type. + * + * @override + */ + get type(): 'audiolevel'; + /** * Observer. * diff --git a/node/src/RtpObserverTypes.ts b/node/src/RtpObserverTypes.ts index 48d064e6ef..4e04f9d056 100644 --- a/node/src/RtpObserverTypes.ts +++ b/node/src/RtpObserverTypes.ts @@ -2,6 +2,11 @@ import type { EnhancedEventEmitter } from './enhancedEvents'; import type { Producer } from './ProducerTypes'; import type { AppData } from './types'; +/** + * RtpObserver type. + */ +export type RtpObserverType = 'audiolevel' | 'activespeaker'; + export type RtpObserverEvents = { routerclose: []; listenererror: [string, Error]; @@ -35,6 +40,15 @@ export interface RtpObserver< */ get closed(): boolean; + /** + * RtpObserver type. + * + * @virtual + * @privateRemarks + * - It's marked as virtual getter since each RtpObserver class overrides it. + */ + get type(): RtpObserverType; + /** * Whether the RtpObserver is paused. */ diff --git a/node/src/test/test-ActiveSpeakerObserver.ts b/node/src/test/test-ActiveSpeakerObserver.ts index 2389ad9f2b..7467dac16a 100644 --- a/node/src/test/test-ActiveSpeakerObserver.ts +++ b/node/src/test/test-ActiveSpeakerObserver.ts @@ -48,6 +48,7 @@ test('router.createActiveSpeakerObserver() succeeds', async () => { expect(onObserverNewRtpObserver).toHaveBeenCalledWith(activeSpeakerObserver); expect(typeof activeSpeakerObserver.id).toBe('string'); expect(activeSpeakerObserver.closed).toBe(false); + expect(activeSpeakerObserver.type).toBe('activespeaker'); expect(activeSpeakerObserver.paused).toBe(false); expect(activeSpeakerObserver.appData).toEqual({}); diff --git a/node/src/test/test-AudioLevelObserver.ts b/node/src/test/test-AudioLevelObserver.ts index 33c45a19e9..e10d1245a8 100644 --- a/node/src/test/test-AudioLevelObserver.ts +++ b/node/src/test/test-AudioLevelObserver.ts @@ -48,6 +48,7 @@ test('router.createAudioLevelObserver() succeeds', async () => { expect(onObserverNewRtpObserver).toHaveBeenCalledWith(audioLevelObserver); expect(typeof audioLevelObserver.id).toBe('string'); expect(audioLevelObserver.closed).toBe(false); + expect(audioLevelObserver.type).toBe('audiolevel'); expect(audioLevelObserver.paused).toBe(false); expect(audioLevelObserver.appData).toEqual({}); From 02a84e839a00f3f0bb904a99acf604a44c14715f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 11 Nov 2024 12:55:08 +0100 Subject: [PATCH 13/14] cosmetic --- node/src/Channel.ts | 9 --------- node/src/WebRtcTransport.ts | 3 --- 2 files changed, 12 deletions(-) diff --git a/node/src/Channel.ts b/node/src/Channel.ts index 97ec868bdb..6621d1e188 100644 --- a/node/src/Channel.ts +++ b/node/src/Channel.ts @@ -53,9 +53,6 @@ export class Channel extends EnhancedEventEmitter { // flatbuffers builder. #bufferBuilder: flatbuffers.Builder = new flatbuffers.Builder(1024); - /** - * @private - */ constructor({ producerSocket, consumerSocket, @@ -200,9 +197,6 @@ export class Channel extends EnhancedEventEmitter { return this.#bufferBuilder; } - /** - * @private - */ close(): void { if (this.#closed) { return; @@ -236,9 +230,6 @@ export class Channel extends EnhancedEventEmitter { } catch (error) {} } - /** - * @private - */ notify( event: Event, bodyType?: NotificationBody, diff --git a/node/src/WebRtcTransport.ts b/node/src/WebRtcTransport.ts index e58e8756e1..522882cd65 100644 --- a/node/src/WebRtcTransport.ts +++ b/node/src/WebRtcTransport.ts @@ -79,9 +79,6 @@ export class WebRtcTransportImpl< // WebRtcTransport data. readonly #data: WebRtcTransportData; - /** - * @private - */ constructor( options: WebRtcTransportConstructorOptions ) { From 207db89a17ea7e03eacc540c6ee185a7c92deab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 11 Nov 2024 12:56:03 +0100 Subject: [PATCH 14/14] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cbe7141d3..aadea8be76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Node: Add TypeScript interfaces for all exported classes ([PR #1463](https://github.com/versatica/mediasoup/pull/1463)). - Node: Add new `transport.type` getter than returns `'webrtc' | 'plain' | 'pipe' | 'direct'` ([PR #1463](https://github.com/versatica/mediasoup/pull/1463)). +- Node: Add new `rtpObserver.type` getter than returns `'activespeaker' | 'audiolevel'` ([PR #1463](https://github.com/versatica/mediasoup/pull/1463)). ### 3.14.16