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

Improve typings for event emitters #200

Closed
wants to merge 1 commit into from
Closed
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
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?: Record<string, unknown>;
};
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?: Record<string, unknown>;
};
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?: Record<string, unknown>;
};
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.

6 changes: 1 addition & 5 deletions lib/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
/* global RTCRtpTransceiver */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand Down
Loading