Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TS Observers type #1430

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Worker: Test, fix buffer overflow ([PR #1419](https://github.com/versatica/mediasoup/pull/1419)).
- Bump up Meson from 1.3.0 to 1.5.0 ([PR #1424](https://github.com/versatica/mediasoup/pull/1424)).
- Node: Export new `WorkerObserver`, `ProducerObserver`, etc. TypeScript types ([PR #1430](https://github.com/versatica/mediasoup/pull/1430)).

### 3.14.8

Expand Down
15 changes: 12 additions & 3 deletions node/src/ActiveSpeakerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export type ActiveSpeakerObserverEvents = RtpObserverEvents & {
dominantspeaker: [ActiveSpeakerObserverDominantSpeaker];
};

export type ActiveSpeakerObserverObserver =
EnhancedEventEmitter<ActiveSpeakerObserverObserverEvents>;

export type ActiveSpeakerObserverObserverEvents = RtpObserverObserverEvents & {
dominantspeaker: [ActiveSpeakerObserverDominantSpeaker];
};
Expand All @@ -46,23 +49,29 @@ export class ActiveSpeakerObserver<
ActiveSpeakerObserverAppData extends AppData = AppData,
> extends RtpObserver<
ActiveSpeakerObserverAppData,
ActiveSpeakerObserverEvents
ActiveSpeakerObserverEvents,
ActiveSpeakerObserverObserver
> {
/**
* @private
*/
constructor(
options: RtpObserverObserverConstructorOptions<ActiveSpeakerObserverAppData>
) {
super(options);
const observer: ActiveSpeakerObserverObserver =
new EnhancedEventEmitter<ActiveSpeakerObserverObserverEvents>();

super(options, observer);

this.handleWorkerNotifications();
}

/**
* Observer.
*
* @override
*/
get observer(): EnhancedEventEmitter<ActiveSpeakerObserverObserverEvents> {
get observer(): ActiveSpeakerObserverObserver {
return super.observer;
}

Expand Down
18 changes: 15 additions & 3 deletions node/src/AudioLevelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export type AudioLevelObserverEvents = RtpObserverEvents & {
silence: [];
};

export type AudioLevelObserverObserver =
EnhancedEventEmitter<AudioLevelObserverObserverEvents>;

export type AudioLevelObserverObserverEvents = RtpObserverObserverEvents & {
volumes: [AudioLevelObserverVolume[]];
silence: [];
Expand All @@ -67,22 +70,31 @@ const logger = new Logger('AudioLevelObserver');

export class AudioLevelObserver<
AudioLevelObserverAppData extends AppData = AppData,
> extends RtpObserver<AudioLevelObserverAppData, AudioLevelObserverEvents> {
> extends RtpObserver<
AudioLevelObserverAppData,
AudioLevelObserverEvents,
AudioLevelObserverObserver
> {
/**
* @private
*/
constructor(
options: AudioLevelObserverConstructorOptions<AudioLevelObserverAppData>
) {
super(options);
const observer: AudioLevelObserverObserver =
new EnhancedEventEmitter<AudioLevelObserverObserverEvents>();

super(options, observer);

this.handleWorkerNotifications();
}

/**
* Observer.
*
* @override
*/
get observer(): EnhancedEventEmitter<AudioLevelObserverObserverEvents> {
get observer(): AudioLevelObserverObserver {
return super.observer;
}

Expand Down
7 changes: 5 additions & 2 deletions node/src/Consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ export type ConsumerEvents = {
'@producerclose': [];
};

export type ConsumerObserver = EnhancedEventEmitter<ConsumerObserverEvents>;

export type ConsumerObserverEvents = {
close: [];
pause: [];
Expand Down Expand Up @@ -318,7 +320,8 @@ export class Consumer<
#currentLayers?: ConsumerLayers;

// Observer instance.
readonly #observer = new EnhancedEventEmitter<ConsumerObserverEvents>();
readonly #observer: ConsumerObserver =
new EnhancedEventEmitter<ConsumerObserverEvents>();

/**
* @private
Expand Down Expand Up @@ -459,7 +462,7 @@ export class Consumer<
/**
* Observer.
*/
get observer(): EnhancedEventEmitter<ConsumerObserverEvents> {
get observer(): ConsumerObserver {
return this.#observer;
}

Expand Down
8 changes: 6 additions & 2 deletions node/src/DataConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export type DataConsumerEvents = {
'@dataproducerclose': [];
};

export type DataConsumerObserver =
EnhancedEventEmitter<DataConsumerObserverEvents>;

export type DataConsumerObserverEvents = {
close: [];
pause: [];
Expand Down Expand Up @@ -148,7 +151,8 @@ export class DataConsumer<
#appData: DataConsumerAppData;

// Observer instance.
readonly #observer = new EnhancedEventEmitter<DataConsumerObserverEvents>();
readonly #observer: DataConsumerObserver =
new EnhancedEventEmitter<DataConsumerObserverEvents>();

/**
* @private
Expand Down Expand Up @@ -272,7 +276,7 @@ export class DataConsumer<
/**
* Observer.
*/
get observer(): EnhancedEventEmitter<DataConsumerObserverEvents> {
get observer(): DataConsumerObserver {
return this.#observer;
}

Expand Down
8 changes: 6 additions & 2 deletions node/src/DataProducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export type DataProducerEvents = {
'@close': [];
};

export type DataProducerObserver =
EnhancedEventEmitter<DataProducerObserverEvents>;

export type DataProducerObserverEvents = {
close: [];
pause: [];
Expand Down Expand Up @@ -113,7 +116,8 @@ export class DataProducer<
#appData: DataProducerAppData;

// Observer instance.
readonly #observer = new EnhancedEventEmitter<DataProducerObserverEvents>();
readonly #observer: DataProducerObserver =
new EnhancedEventEmitter<DataProducerObserverEvents>();

/**
* @private
Expand Down Expand Up @@ -210,7 +214,7 @@ export class DataProducer<
/**
* Observer.
*/
get observer(): EnhancedEventEmitter<DataProducerObserverEvents> {
get observer(): DataProducerObserver {
return this.#observer;
}

Expand Down
20 changes: 18 additions & 2 deletions node/src/DirectTransport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Logger } from './Logger';
import { EnhancedEventEmitter } from './enhancedEvents';
import { UnsupportedError } from './errors';
import {
BaseTransportDump,
Expand Down Expand Up @@ -44,6 +45,9 @@ export type DirectTransportEvents = TransportEvents & {
rtcp: [Buffer];
};

export type DirectTransportObserver =
EnhancedEventEmitter<DirectTransportObserverEvents>;

export type DirectTransportObserverEvents = TransportObserverEvents & {
rtcp: [Buffer];
};
Expand All @@ -64,7 +68,7 @@ export class DirectTransport<
> extends Transport<
DirectTransportAppData,
DirectTransportEvents,
DirectTransportObserverEvents
DirectTransportObserver
> {
// DirectTransport data.
readonly #data: DirectTransportData;
Expand All @@ -75,7 +79,10 @@ export class DirectTransport<
constructor(
options: DirectTransportConstructorOptions<DirectTransportAppData>
) {
super(options);
const observer: DirectTransportObserver =
new EnhancedEventEmitter<DirectTransportObserverEvents>();

super(options, observer);

logger.debug('constructor()');

Expand All @@ -86,6 +93,15 @@ export class DirectTransport<
this.handleWorkerNotifications();
}

/**
* Observer.
*
* @override
*/
get observer(): DirectTransportObserver {
return super.observer;
}

/**
* Close the DirectTransport.
*
Expand Down
20 changes: 18 additions & 2 deletions node/src/PipeTransport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as flatbuffers from 'flatbuffers';
import { Logger } from './Logger';
import { EnhancedEventEmitter } from './enhancedEvents';
import * as ortc from './ortc';
import {
BaseTransportDump,
Expand Down Expand Up @@ -131,6 +132,9 @@ export type PipeTransportEvents = TransportEvents & {
sctpstatechange: [SctpState];
};

export type PipeTransportObserver =
EnhancedEventEmitter<PipeTransportObserverEvents>;

export type PipeTransportObserverEvents = TransportObserverEvents & {
sctpstatechange: [SctpState];
};
Expand Down Expand Up @@ -161,7 +165,7 @@ export class PipeTransport<
> extends Transport<
PipeTransportAppData,
PipeTransportEvents,
PipeTransportObserverEvents
PipeTransportObserver
> {
// PipeTransport data.
readonly #data: PipeTransportData;
Expand All @@ -170,7 +174,10 @@ export class PipeTransport<
* @private
*/
constructor(options: PipeTransportConstructorOptions<PipeTransportAppData>) {
super(options);
const observer: PipeTransportObserver =
new EnhancedEventEmitter<PipeTransportObserverEvents>();

super(options, observer);

logger.debug('constructor()');

Expand All @@ -187,6 +194,15 @@ export class PipeTransport<
this.handleWorkerNotifications();
}

/**
* Observer.
*
* @override
*/
get observer(): PipeTransportObserver {
return super.observer;
}

/**
* Transport tuple.
*/
Expand Down
20 changes: 18 additions & 2 deletions node/src/PlainTransport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as flatbuffers from 'flatbuffers';
import { Logger } from './Logger';
import { EnhancedEventEmitter } from './enhancedEvents';
import {
parseSctpState,
BaseTransportDump,
Expand Down Expand Up @@ -130,6 +131,9 @@ export type PlainTransportEvents = TransportEvents & {
sctpstatechange: [SctpState];
};

export type PlainTransportObserver =
EnhancedEventEmitter<PlainTransportObserverEvents>;

export type PlainTransportObserverEvents = TransportObserverEvents & {
tuple: [TransportTuple];
rtcptuple: [TransportTuple];
Expand Down Expand Up @@ -166,7 +170,7 @@ export class PlainTransport<
> extends Transport<
PlainTransportAppData,
PlainTransportEvents,
PlainTransportObserverEvents
PlainTransportObserver
> {
// PlainTransport data.
readonly #data: PlainTransportData;
Expand All @@ -177,7 +181,10 @@ export class PlainTransport<
constructor(
options: PlainTransportConstructorOptions<PlainTransportAppData>
) {
super(options);
const observer: PlainTransportObserver =
new EnhancedEventEmitter<PlainTransportObserverEvents>();

super(options, observer);

logger.debug('constructor()');

Expand All @@ -196,6 +203,15 @@ export class PlainTransport<
this.handleWorkerNotifications();
}

/**
* Observer.
*
* @override
*/
get observer(): PlainTransportObserver {
return super.observer;
}

/**
* Transport tuple.
*/
Expand Down
7 changes: 5 additions & 2 deletions node/src/Producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export type ProducerEvents = {
'@close': [];
};

export type ProducerObserver = EnhancedEventEmitter<ProducerObserverEvents>;

export type ProducerObserverEvents = {
close: [];
pause: [];
Expand Down Expand Up @@ -198,7 +200,8 @@ export class Producer<
#score: ProducerScore[] = [];

// Observer instance.
readonly #observer = new EnhancedEventEmitter<ProducerObserverEvents>();
readonly #observer: ProducerObserver =
new EnhancedEventEmitter<ProducerObserverEvents>();

/**
* @private
Expand Down Expand Up @@ -304,7 +307,7 @@ export class Producer<
/**
* Observer.
*/
get observer(): EnhancedEventEmitter<ProducerObserverEvents> {
get observer(): ProducerObserver {
return this.#observer;
}

Expand Down
7 changes: 5 additions & 2 deletions node/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export type RouterEvents = {
'@close': [];
};

export type RouterObserver = EnhancedEventEmitter<RouterObserverEvents>;

export type RouterObserverEvents = {
close: [];
newtransport: [Transport];
Expand Down Expand Up @@ -252,7 +254,8 @@ export class Router<
> = new Map();

// Observer instance.
readonly #observer = new EnhancedEventEmitter<RouterObserverEvents>();
readonly #observer: RouterObserver =
new EnhancedEventEmitter<RouterObserverEvents>();

/**
* @private
Expand Down Expand Up @@ -316,7 +319,7 @@ export class Router<
/**
* Observer.
*/
get observer(): EnhancedEventEmitter<RouterObserverEvents> {
get observer(): RouterObserver {
return this.#observer;
}

Expand Down
Loading
Loading