Skip to content

Commit

Permalink
feat: limit appliable constraints (#56)
Browse files Browse the repository at this point in the history
* feat: limit appliable constraints

* refactor: pick VideoDeviceConstraints from MediaTrackConstraints

---------

Co-authored-by: Bryce Tham <[email protected]>
  • Loading branch information
brycetham and Bryce Tham authored Jun 30, 2023
1 parent a792397 commit b92e5af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"language": "en",
"words": [
"Alboe",
"appliable",
"bitauth",
"bitjson",
"cimg",
Expand Down Expand Up @@ -32,8 +33,8 @@
"transpiled",
"typedoc",
"untracked",
"WCME",
"Wcme",
"WCME",
"webex",
"webrtc"
],
Expand Down
12 changes: 4 additions & 8 deletions src/device/device-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ export type AudioDeviceConstraints = Pick<
| 'suppressLocalAudioPlayback'
>;

export type VideoDeviceConstraints = {
deviceId?: ConstrainDOMString;
width?: ConstrainULong;
height?: ConstrainULong;
aspectRatio?: ConstrainDouble;
frameRate?: ConstrainDouble;
facingMode?: ConstrainDOMString;
};
export type VideoDeviceConstraints = Pick<
MediaTrackConstraints,
'aspectRatio' | 'deviceId' | 'facingMode' | 'frameRate' | 'height' | 'width'
>;

/**
* Creates a camera stream. Please note that the constraint params in second getUserMedia call would NOT take effect when:
Expand Down
18 changes: 4 additions & 14 deletions src/media/local-audio-stream.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { logger } from '../util/logger';
import { LocalStream, LocalStreamEventNames } from './local-stream';

// TODO: for applyConstraints, we only support things which can be changed on the
// track itself. This would not include 'deviceId', and maybe more of these values.
// Might need to define one AudioConstraints for use with getUserMedia, and refine
// it even further for applyConstraints here.
export type AudioConstraints = Pick<
// These are the audio constraints that can be applied via applyConstraints.
export type AppliableAudioConstraints = Pick<
MediaTrackConstraints,
| 'autoGainControl'
| 'channelCount'
| 'deviceId'
| 'echoCancellation'
| 'noiseSuppression'
| 'sampleRate'
| 'sampleSize'
| 'suppressLocalAudioPlayback'
'autoGainControl' | 'echoCancellation' | 'noiseSuppression' | 'suppressLocalAudioPlayback'
>;

/**
Expand All @@ -27,7 +17,7 @@ export class LocalAudioStream extends LocalStream {
* @param constraints - The constraints to apply.
* @returns A promise which resolves when the constraints have been successfully applied.
*/
async applyConstraints(constraints?: AudioConstraints): Promise<void> {
async applyConstraints(constraints?: AppliableAudioConstraints): Promise<void> {
logger.log(`Applying constraints to local track:`, constraints);
return this.inputTrack.applyConstraints(constraints).then(() => {
this[LocalStreamEventNames.ConstraintsChange].emit();
Expand Down
11 changes: 5 additions & 6 deletions src/media/local-video-stream.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { logger } from '../util/logger';
import { LocalStream, LocalStreamEventNames } from './local-stream';

// TODO: see note on AudioConstraints in local-audio-stream
export type VideoConstraints = Partial<
Pick<MediaTrackConstraints, 'aspectRatio' | 'facingMode' | 'frameRate' | 'height' | 'width'>
// These are the video constraints that can be applied via applyConstraints.
export type AppliableVideoConstraints = Pick<
MediaTrackConstraints,
'aspectRatio' | 'frameRate' | 'height' | 'width'
>;

/**
* See https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/contentHint.
*/
export type VideoContentHint = 'motion' | 'detail' | 'text' | '';

// TODO: content hint api/type should move here

/**
* A video LocalStream.
*/
Expand All @@ -23,7 +22,7 @@ export class LocalVideoStream extends LocalStream {
* @param constraints - The constraints to apply.
* @returns A promise which resolves when the constraints have been successfully applied.
*/
async applyConstraints(constraints?: VideoConstraints): Promise<void> {
async applyConstraints(constraints?: AppliableVideoConstraints): Promise<void> {
logger.log(`Applying constraints to local track:`, constraints);
return this.inputTrack.applyConstraints(constraints).then(() => {
this[LocalStreamEventNames.ConstraintsChange].emit();
Expand Down

0 comments on commit b92e5af

Please sign in to comment.