Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support applying music mode constraints #27

Merged
merged 1 commit into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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