Skip to content

Commit

Permalink
fix: explicitly allow event handlers to be asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
brycetham committed Dec 1, 2023
1 parent 59909b4 commit 0eedde2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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

0 comments on commit 0eedde2

Please sign in to comment.