Skip to content

Commit

Permalink
Add new rtpObserver.type getter than returns `'activespeaker' | 'au…
Browse files Browse the repository at this point in the history
…diolevel'`
  • Loading branch information
ibc committed Nov 11, 2024
1 parent 9e2b2bc commit b882b2c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
12 changes: 4 additions & 8 deletions node/src/ActiveSpeakerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export class ActiveSpeakerObserverImpl<
>
implements RtpObserver, ActiveSpeakerObserver
{
/**
* @private
*/
constructor(
options: RtpObserverObserverConstructorOptions<ActiveSpeakerObserverAppData>
) {
Expand All @@ -43,11 +40,10 @@ export class ActiveSpeakerObserverImpl<
this.handleListenerError();
}

/**
* Observer.
*
* @override
*/
get type(): 'activespeaker' {
return 'activespeaker';
}

get observer(): ActiveSpeakerObserverObserver {
return super.observer;
}
Expand Down
7 changes: 7 additions & 0 deletions node/src/ActiveSpeakerObserverTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export interface ActiveSpeakerObserver<
ActiveSpeakerObserverEvents,
ActiveSpeakerObserverObserver
> {
/**
* RtpObserver type.
*
* @override
*/
get type(): 'activespeaker';

/**
* Observer.
*
Expand Down
12 changes: 4 additions & 8 deletions node/src/AudioLevelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export class AudioLevelObserverImpl<
>
implements RtpObserver, AudioLevelObserver
{
/**
* @private
*/
constructor(
options: AudioLevelObserverConstructorOptions<AudioLevelObserverAppData>
) {
Expand All @@ -45,11 +42,10 @@ export class AudioLevelObserverImpl<
this.handleListenerError();
}

/**
* Observer.
*
* @override
*/
get type(): 'audiolevel' {
return 'audiolevel';
}

get observer(): AudioLevelObserverObserver {
return super.observer;
}
Expand Down
7 changes: 7 additions & 0 deletions node/src/AudioLevelObserverTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export interface AudioLevelObserver<
AudioLevelObserverEvents,
AudioLevelObserverObserver
> {
/**
* RtpObserver type.
*
* @override
*/
get type(): 'audiolevel';

/**
* Observer.
*
Expand Down
14 changes: 14 additions & 0 deletions node/src/RtpObserverTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions node/src/test/test-ActiveSpeakerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});

Expand Down
1 change: 1 addition & 0 deletions node/src/test/test-AudioLevelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});

Expand Down

0 comments on commit b882b2c

Please sign in to comment.