-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb5e058
commit 925bafb
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./recorder"; | ||
export * from "./userMedia"; | ||
export * from "./navigator"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { MediaStream, MediaStreamTrack } from "../media/track"; | ||
|
||
export class Navigator { | ||
readonly mediaDevices: MediaDevices; | ||
|
||
constructor(props: ConstructorParameters<typeof MediaDevices>[0] = {}) { | ||
this.mediaDevices = new MediaDevices(props); | ||
} | ||
} | ||
|
||
class MediaDevices extends EventTarget { | ||
video?: MediaStreamTrack; | ||
audio?: MediaStreamTrack; | ||
|
||
constructor(props: { video?: MediaStreamTrack; audio?: MediaStreamTrack }) { | ||
super(); | ||
this.video = props.video; | ||
this.audio = props.audio; | ||
} | ||
|
||
readonly getUserMedia = async ( | ||
constraints: MediaStreamConstraints, | ||
): Promise<MediaStream> => { | ||
if (constraints.video && constraints.audio) { | ||
return new MediaStream([this.video!, this.audio!]); | ||
} else if (constraints.audio) { | ||
return new MediaStream([this.audio!]); | ||
} else if (constraints.video) { | ||
return new MediaStream([this.video!]); | ||
} | ||
|
||
throw new Error("Not implemented"); | ||
}; | ||
|
||
readonly getDisplayMedia = this.getUserMedia; | ||
} | ||
|
||
interface MediaStreamConstraints { | ||
audio?: boolean | MediaTrackConstraints; | ||
peerIdentity?: string; | ||
preferCurrentTab?: boolean; | ||
video?: boolean | MediaTrackConstraints; | ||
} | ||
|
||
interface MediaTrackConstraints extends MediaTrackConstraintSet { | ||
advanced?: MediaTrackConstraintSet[]; | ||
} | ||
|
||
interface MediaTrackConstraintSet { | ||
aspectRatio?: ConstrainDouble; | ||
autoGainControl?: ConstrainBoolean; | ||
channelCount?: ConstrainULong; | ||
deviceId?: ConstrainDOMString; | ||
displaySurface?: ConstrainDOMString; | ||
echoCancellation?: ConstrainBoolean; | ||
facingMode?: ConstrainDOMString; | ||
frameRate?: ConstrainDouble; | ||
groupId?: ConstrainDOMString; | ||
height?: ConstrainULong; | ||
noiseSuppression?: ConstrainBoolean; | ||
sampleRate?: ConstrainULong; | ||
sampleSize?: ConstrainULong; | ||
width?: ConstrainULong; | ||
} | ||
|
||
type ConstrainDOMString = string | string[] | ConstrainDOMStringParameters; | ||
interface ConstrainDOMStringParameters { | ||
exact?: string | string[]; | ||
ideal?: string | string[]; | ||
} | ||
type ConstrainBoolean = boolean | ConstrainBooleanParameters; | ||
interface ConstrainBooleanParameters { | ||
exact?: boolean; | ||
ideal?: boolean; | ||
} | ||
type ConstrainULong = number | ConstrainULongRange; | ||
interface ConstrainULongRange extends ULongRange { | ||
exact?: number; | ||
ideal?: number; | ||
} | ||
interface ULongRange { | ||
max?: number; | ||
min?: number; | ||
} | ||
type ConstrainDouble = number | ConstrainDoubleRange; | ||
interface ConstrainDoubleRange extends DoubleRange { | ||
exact?: number; | ||
ideal?: number; | ||
} | ||
interface DoubleRange { | ||
max?: number; | ||
min?: number; | ||
} |