From efced18bc3ce3fc37dec3d1b3d41bdbce78a57d6 Mon Sep 17 00:00:00 2001 From: Bryce Tham Date: Wed, 1 Feb 2023 10:27:52 -0500 Subject: [PATCH] feat: support applying music mode constraints --- src/device/device-management.ts | 3 +++ src/media/local-track.spec.ts | 10 ++++++++++ src/media/local-track.ts | 29 ++++++++++++++++++++++++++++ src/mocks/media-stream-track-stub.ts | 8 ++++++++ src/util/test-utils.ts | 6 ++++++ 5 files changed, 56 insertions(+) diff --git a/src/device/device-management.ts b/src/device/device-management.ts index 10d6033..b36624b 100644 --- a/src/device/device-management.ts +++ b/src/device/device-management.ts @@ -31,6 +31,9 @@ export class WcmeError { export type AudioDeviceConstraints = { deviceId?: string; + autoGainControl?: boolean; + echoCancellation?: boolean; + noiseSuppression?: boolean; }; export type VideoDeviceConstraints = { diff --git a/src/media/local-track.spec.ts b/src/media/local-track.spec.ts index 731021d..fa4ad61 100644 --- a/src/media/local-track.spec.ts +++ b/src/media/local-track.spec.ts @@ -51,4 +51,14 @@ describe('LocalTrack', () => { expect(emitted).toBe(true); }); + + it('should apply and get underlying track constraints', () => { + expect.assertions(1); + + localTrack.applyConstraints({ autoGainControl: true }); + + const constraints = localTrack.getConstraints(); + + expect(constraints).toStrictEqual({ autoGainControl: true }); + }); }); diff --git a/src/media/local-track.ts b/src/media/local-track.ts index b596f6e..f65c936 100644 --- a/src/media/local-track.ts +++ b/src/media/local-track.ts @@ -267,4 +267,33 @@ export abstract class LocalTrack extends EventEmitter { this.emit(LocalTrackEvents.UnderlyingTrackChange); } } + + /** + * Apply constraints to the track. + * + * @param constraints - The constraints to apply to the track. + * @returns A promise which resolves when the constraints have been successfully applied. + */ + async applyConstraints(constraints?: MediaTrackConstraints): Promise { + logger.log(`Applying constraints to local track:`, constraints); + return this.underlyingTrack.applyConstraints(constraints); + } + + /** + * Get the current constraints of the track. + * + * @returns The constraints of the track. + */ + getConstraints(): MediaTrackConstraints { + return this.underlyingTrack.getConstraints(); + } + + /** + * Get the current settings of the track. + * + * @returns The settings of the track. + */ + getSettings(): MediaTrackSettings { + return this.underlyingTrack.getSettings(); + } } diff --git a/src/mocks/media-stream-track-stub.ts b/src/mocks/media-stream-track-stub.ts index e927c26..ac36659 100644 --- a/src/mocks/media-stream-track-stub.ts +++ b/src/mocks/media-stream-track-stub.ts @@ -12,6 +12,8 @@ class MediaStreamTrackStub { // be fine. eventListeners: Map = new Map(); + constraints: MediaTrackConstraints = {}; + kind?: MediaStreamTrackKind; /** @@ -24,6 +26,12 @@ class MediaStreamTrackStub { */ stop(): void {} + applyConstraints(constraints?: MediaTrackConstraints): void {} + + getConstraints(): MediaTrackConstraints { + return {} as MediaTrackConstraints; + } + getSettings(): MediaTrackSettings { return {} as MediaTrackSettings; } diff --git a/src/util/test-utils.ts b/src/util/test-utils.ts index 9532533..d650422 100644 --- a/src/util/test-utils.ts +++ b/src/util/test-utils.ts @@ -30,6 +30,12 @@ export const createMockedStreamWithSize = (width: number, height: number): Media width, aspectRatio: width / height, }); + track.applyConstraints.mockImplementation((constraints?: MediaTrackConstraints) => { + track.constraints = constraints || {}; + }); + track.getConstraints.mockImplementation(() => { + return track.constraints; + }); mockStream.getVideoTracks.mockReturnValue([track as unknown as MediaStreamTrack]); mockStream.getTracks.mockReturnValue([track as unknown as MediaStreamTrack]); return mockStream as unknown as MediaStream;