Skip to content

Commit

Permalink
improve typings of event emitters for Transport, Producer, Consumer, …
Browse files Browse the repository at this point in the history
…DataProducer, DataConsumer
  • Loading branch information
unao committed Feb 23, 2022
1 parent 1fb4248 commit 75e7b86
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 47 deletions.
18 changes: 15 additions & 3 deletions lib/Consumer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ export declare type ConsumerOptions = {
rtpParameters: RtpParameters;
appData?: any;
};
export declare class Consumer extends EnhancedEventEmitter {
export declare type ConsumerEvents = {
transportclose: [];
trackended: [];
};
export declare type ConsumerObserverEvents = {
close: [];
pause: [];
resume: [];
trackended: [];
};
export declare class Consumer extends EnhancedEventEmitter<ConsumerEvents> {
private readonly _id;
private readonly _localId;
private readonly _producerId;
Expand All @@ -17,7 +27,9 @@ export declare class Consumer extends EnhancedEventEmitter {
private readonly _rtpParameters;
private _paused;
private readonly _appData;
protected readonly _observer: EnhancedEventEmitter;
protected readonly _observer: EnhancedEventEmitter<ConsumerObserverEvents, ConsumerObserverEvents & {
[x: `@${string}`]: any[];
}>;
/**
* @emits transportclose
* @emits trackended
Expand Down Expand Up @@ -87,7 +99,7 @@ export declare class Consumer extends EnhancedEventEmitter {
* @emits resume
* @emits trackended
*/
get observer(): EnhancedEventEmitter;
get observer(): EnhancedEventEmitter<ConsumerObserverEvents>;
/**
* Closes the Consumer.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Consumer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions lib/DataConsumer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@ export declare type DataConsumerOptions = {
protocol?: string;
appData?: any;
};
export declare class DataConsumer extends EnhancedEventEmitter {
export declare type DataConsumerEvents = {
transportclose: [];
open: [];
error: [Error];
close: [];
message: [string | Blob | ArrayBuffer];
};
export declare type DataConsumerObserverEvents = {
close: [];
};
export declare class DataConsumer extends EnhancedEventEmitter<DataConsumerEvents> {
private readonly _id;
private readonly _dataProducerId;
private readonly _dataChannel;
private _closed;
private readonly _sctpStreamParameters;
private readonly _appData;
protected readonly _observer: EnhancedEventEmitter;
protected readonly _observer: EnhancedEventEmitter<DataConsumerObserverEvents, DataConsumerObserverEvents & {
[x: `@${string}`]: any[];
}>;
/**
* @emits transportclose
* @emits open
Expand Down Expand Up @@ -80,7 +92,7 @@ export declare class DataConsumer extends EnhancedEventEmitter {
*
* @emits close
*/
get observer(): EnhancedEventEmitter;
get observer(): EnhancedEventEmitter<DataConsumerObserverEvents>;
/**
* Closes the DataConsumer.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/DataConsumer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions lib/DataProducer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ export declare type DataProducerOptions = {
protocol?: string;
appData?: any;
};
export declare class DataProducer extends EnhancedEventEmitter {
export declare type DataProducerEvents = {
transportclose: [];
open: [];
error: [Error];
close: [];
bufferedamountlow: [];
};
export declare type DataProducerObserverEvents = {
close: [];
};
export declare class DataProducer extends EnhancedEventEmitter<DataProducerEvents> {
private readonly _id;
private readonly _dataChannel;
private _closed;
private readonly _sctpStreamParameters;
private readonly _appData;
protected readonly _observer: EnhancedEventEmitter;
protected readonly _observer: EnhancedEventEmitter<DataProducerObserverEvents, DataProducerObserverEvents & {
[x: `@${string}`]: any[];
}>;
/**
* @emits transportclose
* @emits open
Expand Down Expand Up @@ -78,7 +90,7 @@ export declare class DataProducer extends EnhancedEventEmitter {
*
* @emits close
*/
get observer(): EnhancedEventEmitter;
get observer(): EnhancedEventEmitter<DataProducerObserverEvents>;
/**
* Closes the DataProducer.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/DataProducer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lib/Device.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export declare class Device {
private _recvRtpCapabilities?;
private readonly _canProduceByKind;
private _sctpCapabilities?;
protected readonly _observer: EnhancedEventEmitter;
protected readonly _observer: EnhancedEventEmitter<{
[x: string]: any[];
}, {
[x: string]: any[];
} & {
[x: `@${string}`]: any[];
}>;
/**
* Create a new Device to connect to mediasoup server.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Device.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions lib/EnhancedEventEmitter.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
export declare class EnhancedEventEmitter extends EventEmitter {
declare type Events = Record<string, any[]>;
declare type InternalEvents = Record<`@${string}`, any[]>;
export declare class EnhancedEventEmitter<PublicEvents extends Events = Events, E extends PublicEvents = PublicEvents & InternalEvents> extends EventEmitter {
constructor();
safeEmit(event: string, ...args: any[]): boolean;
safeEmitAsPromise(event: string, ...args: any[]): Promise<any>;
safeEmit<K extends keyof E & string>(event: K, ...args: E[K]): boolean;
safeEmitAsPromise<K extends keyof E & string>(event: K, ...args: [
] extends E[K] ? unknown[] : [E[K][0]]): Promise<any>;
on<K extends keyof E & string>(event: K, listener: (...args: E[K]) => void): this;
off<K extends keyof E & string>(event: K, listener: (...args: E[K]) => void): this;
addListener<K extends keyof E & string>(event: K, listener: (...args: E[K]) => void): this;
prependListener<K extends keyof E & string>(event: K, listener: (...args: E[K]) => void): this;
once<K extends keyof E & string>(event: K, listener: (...args: E[K]) => void): this;
prependOnceListener<K extends keyof E & string>(event: K, listener: (...args: E[K]) => void): this;
removeListener<K extends keyof E & string>(event: K, listener: (...args: E[K]) => void): this;
}
export {};
//# sourceMappingURL=EnhancedEventEmitter.d.ts.map
Loading

0 comments on commit 75e7b86

Please sign in to comment.