From 0eedde2dc6237340a99a9141929329a9ce5b992f Mon Sep 17 00:00:00 2001 From: Bryce Tham Date: Fri, 1 Dec 2023 14:55:35 -0500 Subject: [PATCH] fix: explicitly allow event handlers to be asynchronous --- src/media/local-stream.ts | 12 ++++++++---- src/media/stream.ts | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/media/local-stream.ts b/src/media/local-stream.ts index de0c844..266c7cd 100644 --- a/src/media/local-stream.ts +++ b/src/media/local-stream.ts @@ -8,8 +8,10 @@ export enum LocalStreamEventNames { } interface LocalStreamEvents { - [LocalStreamEventNames.ConstraintsChange]: TypedEvent<() => void>; - [LocalStreamEventNames.OutputTrackChange]: TypedEvent<(track: MediaStreamTrack) => void>; + [LocalStreamEventNames.ConstraintsChange]: TypedEvent<() => void | Promise>; + [LocalStreamEventNames.OutputTrackChange]: TypedEvent< + (track: MediaStreamTrack) => void | Promise + >; } export type TrackEffect = BaseEffect; @@ -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>(); - [LocalStreamEventNames.OutputTrackChange] = new TypedEvent<(track: MediaStreamTrack) => void>(); + [LocalStreamEventNames.OutputTrackChange] = new TypedEvent< + (track: MediaStreamTrack) => void | Promise + >(); private effects: EffectItem[] = []; diff --git a/src/media/stream.ts b/src/media/stream.ts index 826870c..c043264 100644 --- a/src/media/stream.ts +++ b/src/media/stream.ts @@ -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>; + [StreamEventNames.Ended]: TypedEvent<() => void | Promise>; } /** @@ -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>(); - [StreamEventNames.Ended] = new TypedEvent<() => void>(); + [StreamEventNames.Ended] = new TypedEvent<() => void | Promise>(); /** * Create a Stream from the given values.