From b882b2c7402f244ef8668d494a1038c7af876359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 11 Nov 2024 12:44:55 +0100 Subject: [PATCH] Add new `rtpObserver.type` getter than returns `'activespeaker' | 'audiolevel'` --- node/src/ActiveSpeakerObserver.ts | 12 ++++-------- node/src/ActiveSpeakerObserverTypes.ts | 7 +++++++ node/src/AudioLevelObserver.ts | 12 ++++-------- node/src/AudioLevelObserverTypes.ts | 7 +++++++ node/src/RtpObserverTypes.ts | 14 ++++++++++++++ node/src/test/test-ActiveSpeakerObserver.ts | 1 + node/src/test/test-AudioLevelObserver.ts | 1 + 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/node/src/ActiveSpeakerObserver.ts b/node/src/ActiveSpeakerObserver.ts index 2c5ccb741e..a46ac16ab4 100644 --- a/node/src/ActiveSpeakerObserver.ts +++ b/node/src/ActiveSpeakerObserver.ts @@ -28,9 +28,6 @@ export class ActiveSpeakerObserverImpl< > implements RtpObserver, ActiveSpeakerObserver { - /** - * @private - */ constructor( options: RtpObserverObserverConstructorOptions ) { @@ -43,11 +40,10 @@ export class ActiveSpeakerObserverImpl< this.handleListenerError(); } - /** - * Observer. - * - * @override - */ + get type(): 'activespeaker' { + return 'activespeaker'; + } + get observer(): ActiveSpeakerObserverObserver { return super.observer; } diff --git a/node/src/ActiveSpeakerObserverTypes.ts b/node/src/ActiveSpeakerObserverTypes.ts index 18ae847822..9d00005697 100644 --- a/node/src/ActiveSpeakerObserverTypes.ts +++ b/node/src/ActiveSpeakerObserverTypes.ts @@ -43,6 +43,13 @@ export interface ActiveSpeakerObserver< ActiveSpeakerObserverEvents, ActiveSpeakerObserverObserver > { + /** + * RtpObserver type. + * + * @override + */ + get type(): 'activespeaker'; + /** * Observer. * diff --git a/node/src/AudioLevelObserver.ts b/node/src/AudioLevelObserver.ts index 4c0c6bed8d..5890956fdb 100644 --- a/node/src/AudioLevelObserver.ts +++ b/node/src/AudioLevelObserver.ts @@ -30,9 +30,6 @@ export class AudioLevelObserverImpl< > implements RtpObserver, AudioLevelObserver { - /** - * @private - */ constructor( options: AudioLevelObserverConstructorOptions ) { @@ -45,11 +42,10 @@ export class AudioLevelObserverImpl< this.handleListenerError(); } - /** - * Observer. - * - * @override - */ + get type(): 'audiolevel' { + return 'audiolevel'; + } + get observer(): AudioLevelObserverObserver { return super.observer; } diff --git a/node/src/AudioLevelObserverTypes.ts b/node/src/AudioLevelObserverTypes.ts index a318db3609..dca5b0e568 100644 --- a/node/src/AudioLevelObserverTypes.ts +++ b/node/src/AudioLevelObserverTypes.ts @@ -65,6 +65,13 @@ export interface AudioLevelObserver< AudioLevelObserverEvents, AudioLevelObserverObserver > { + /** + * RtpObserver type. + * + * @override + */ + get type(): 'audiolevel'; + /** * Observer. * diff --git a/node/src/RtpObserverTypes.ts b/node/src/RtpObserverTypes.ts index 48d064e6ef..4e04f9d056 100644 --- a/node/src/RtpObserverTypes.ts +++ b/node/src/RtpObserverTypes.ts @@ -2,6 +2,11 @@ import type { EnhancedEventEmitter } from './enhancedEvents'; import type { Producer } from './ProducerTypes'; import type { AppData } from './types'; +/** + * RtpObserver type. + */ +export type RtpObserverType = 'audiolevel' | 'activespeaker'; + export type RtpObserverEvents = { routerclose: []; listenererror: [string, Error]; @@ -35,6 +40,15 @@ export interface RtpObserver< */ get closed(): boolean; + /** + * RtpObserver type. + * + * @virtual + * @privateRemarks + * - It's marked as virtual getter since each RtpObserver class overrides it. + */ + get type(): RtpObserverType; + /** * Whether the RtpObserver is paused. */ diff --git a/node/src/test/test-ActiveSpeakerObserver.ts b/node/src/test/test-ActiveSpeakerObserver.ts index 2389ad9f2b..7467dac16a 100644 --- a/node/src/test/test-ActiveSpeakerObserver.ts +++ b/node/src/test/test-ActiveSpeakerObserver.ts @@ -48,6 +48,7 @@ test('router.createActiveSpeakerObserver() succeeds', async () => { expect(onObserverNewRtpObserver).toHaveBeenCalledWith(activeSpeakerObserver); expect(typeof activeSpeakerObserver.id).toBe('string'); expect(activeSpeakerObserver.closed).toBe(false); + expect(activeSpeakerObserver.type).toBe('activespeaker'); expect(activeSpeakerObserver.paused).toBe(false); expect(activeSpeakerObserver.appData).toEqual({}); diff --git a/node/src/test/test-AudioLevelObserver.ts b/node/src/test/test-AudioLevelObserver.ts index 33c45a19e9..e10d1245a8 100644 --- a/node/src/test/test-AudioLevelObserver.ts +++ b/node/src/test/test-AudioLevelObserver.ts @@ -48,6 +48,7 @@ test('router.createAudioLevelObserver() succeeds', async () => { expect(onObserverNewRtpObserver).toHaveBeenCalledWith(audioLevelObserver); expect(typeof audioLevelObserver.id).toBe('string'); expect(audioLevelObserver.closed).toBe(false); + expect(audioLevelObserver.type).toBe('audiolevel'); expect(audioLevelObserver.paused).toBe(false); expect(audioLevelObserver.appData).toEqual({});