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: explicitly allow event handlers to be asynchronous #64

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
12 changes: 8 additions & 4 deletions src/media/local-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export enum LocalStreamEventNames {
}

interface LocalStreamEvents {
[LocalStreamEventNames.ConstraintsChange]: TypedEvent<() => void>;
[LocalStreamEventNames.OutputTrackChange]: TypedEvent<(track: MediaStreamTrack) => void>;
[LocalStreamEventNames.ConstraintsChange]: TypedEvent<() => void | Promise<void>>;
[LocalStreamEventNames.OutputTrackChange]: TypedEvent<
(track: MediaStreamTrack) => void | Promise<void>
>;
}

export type TrackEffect = BaseEffect;
Expand All @@ -20,9 +22,11 @@ type EffectItem = { name: string; effect: TrackEffect };
* A stream which originates on the local device.
*/
abstract class _LocalStream extends Stream {
[LocalStreamEventNames.ConstraintsChange] = new TypedEvent<() => void>();
[LocalStreamEventNames.ConstraintsChange] = new TypedEvent<() => void | Promise<void>>();

[LocalStreamEventNames.OutputTrackChange] = new TypedEvent<(track: MediaStreamTrack) => void>();
[LocalStreamEventNames.OutputTrackChange] = new TypedEvent<
(track: MediaStreamTrack) => void | Promise<void>
>();

private effects: EffectItem[] = [];

Expand Down
8 changes: 4 additions & 4 deletions src/media/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export enum StreamEventNames {
}

interface StreamEvents {
[StreamEventNames.MuteStateChange]: TypedEvent<(muted: boolean) => void>;
[StreamEventNames.Ended]: TypedEvent<() => void>;
[StreamEventNames.MuteStateChange]: TypedEvent<(muted: boolean) => void | Promise<void>>;
[StreamEventNames.Ended]: TypedEvent<() => void | Promise<void>>;
}

/**
Expand All @@ -19,9 +19,9 @@ abstract class _Stream {

// TODO: these should be protected, but we need the helper type in ts-events
// to hide the 'emit' method from TypedEvent.
[StreamEventNames.MuteStateChange] = new TypedEvent<(muted: boolean) => void>();
[StreamEventNames.MuteStateChange] = new TypedEvent<(muted: boolean) => void | Promise<void>>();

[StreamEventNames.Ended] = new TypedEvent<() => void>();
[StreamEventNames.Ended] = new TypedEvent<() => void | Promise<void>>();

/**
* Create a Stream from the given values.
Expand Down