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>;