Skip to content

Commit

Permalink
feat: support applying music mode constraints (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: Bryce Tham <[email protected]>
  • Loading branch information
brycetham and Bryce Tham authored Mar 4, 2023
1 parent 1c0e973 commit 081b8b2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/device/device-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class WcmeError {

export type AudioDeviceConstraints = {
deviceId?: string;
autoGainControl?: boolean;
echoCancellation?: boolean;
noiseSuppression?: boolean;
};

export type VideoDeviceConstraints = {
Expand Down
10 changes: 10 additions & 0 deletions src/media/local-track.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
});
29 changes: 29 additions & 0 deletions src/media/local-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,33 @@ export abstract class LocalTrack extends EventEmitter<TrackEvents> {
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<void> {
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();
}
}
8 changes: 8 additions & 0 deletions src/mocks/media-stream-track-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class MediaStreamTrackStub {
// be fine.
eventListeners: Map<string, any> = new Map();

constraints: MediaTrackConstraints = {};

kind?: MediaStreamTrackKind;

/**
Expand All @@ -24,6 +26,12 @@ class MediaStreamTrackStub {
*/
stop(): void {}

applyConstraints(constraints?: MediaTrackConstraints): void {}

getConstraints(): MediaTrackConstraints {
return {} as MediaTrackConstraints;
}

getSettings(): MediaTrackSettings {
return {} as MediaTrackSettings;
}
Expand Down
6 changes: 6 additions & 0 deletions src/util/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 081b8b2

Please sign in to comment.