new VideoInput( [ options ] )

Description

Creates a new VideoInput object and attaches it to the specified <video> element for viewing. If no <video> element is specified, the stream will not be visible. If the special value "create" is used, a new <video> element is created and appended to the <body>. A reference to the video element is accessible via the video property.

By default, the first video input track will be used. To find a specific video input, a MediaTrackConstraints must be specified in the constraints parameter.

Parameters
Name Type Attributes Description
options Object <optional>
Name Type Attributes Description
element HTMLVideoElement | "create" <optional>

The <video> element to attach the video stream to. If none is supplied, the video feed will not be visible. If the special value "create" is used, a new <video> element will be created and appended to the body.

elementId string <optional>

The id attribute of the new <video> element (if a new <video> element is created).

Details

Classes


new VideoInput( [ options ] )

Members


capabilities :MediaTrackCapabilities

Description

A MediaTrackCapabilities object detailing the exact capabilities of the video track (or null if no video track is currently open).

Details
MediaTrackCapabilities

capture :ImageCapture

Description

An ImageCapture object used to grab frames per the ImageCapture API.

Details
ImageCapture

constraints :MediaTrackConstraints

Description

The constraints which must be met by the video track. At the minimum, the value true is used which means all input video streams.

Details
MediaTrackConstraints

opacity :number

Description

The opacity of the <video> element used to display the video stream (between 0 and 1).

Details
number

settings :MediaTrackSettings

Description

A MediaTrackSettings object detailing the precise settings of the video track (or null if no stream is open).

Details
MediaTrackSettings

started :boolean

Description

Whether or not the video input is currently started.

Details
boolean

stream :MediaStream

Description

The actual media stream that is currently being used.

Details
MediaStream

timeouts :Object

Description

An object containing the timeouts used throughout this class (mostly for internal use)

Details
Object

track :MediaStreamTrack

Description

The video track currently being used. This will be null if there are no active stream.

Details
MediaStreamTrack

video :HTMLMediaElement

Description

The <video> element used to display the video feed (may be null if none is used)

Details
HTMLMediaElement

Methods


cancelFade()

Description

Cancels any fade ins or fade outs that are currently ongoing.

Details

<async> destroy() → {Promise.<void>}

Description

Properly destroys this object and all internal references. By calling this method when you are done with this object, you insure there are no lingering listeners or processes.

Returns
Details

<async> fade( [ type [, duration ] ] ) → {Promise.<void>}

Description

Fades the <video> element in or out for the specified duration.

Parameters
Name Type Attributes Default Description
type string <optional>
"in"

Type of fade ("in" or "out")

duration number <optional>
5000

Duration of fade in milliseconds

Returns
Details

<async> fadeIn( [ duration ] ) → {Promise.<void>}

Description

Fades in the <video> element used to display the video feed.

Parameters
Name Type Attributes Default Description
duration number <optional>
5000

Duration of the fade in (in milliseconds)

Returns
Details

<async> fadeOut( [ duration ] ) → {Promise.<void>}

Description

Fades out the <video> element used to display the video feed.

Parameters
Name Type Attributes Default Description
duration number <optional>
5000

Duration of the fade out (in milliseconds)

Returns
Details

<async> grabFrame( [ options ] ) → {Promise.<(ImageBitmap|DOMString|Blob)>}

Description

Grabs a frame from the video stream and returns it in the specified data format.

Parameters
Name Type Attributes Description
options Object <optional>
Name Type Attributes Default Description
format string <optional>
"ImageBitmap"

The format to return the image data in. Can be: "ImageBitmap" (default), "Blob" or "ObjectURL".

mimeType string <optional>
"image/png"

If the image is being returned as a Blob, you can specify the MIME type of that blob. Typically, this will be "image/png" (default) or "image/jpeg" but can also be any image MIME type supported by the environment.

quality number <optional>

For certain MIME types such as image/jpeg or image/webp, a quality parameter can be specified. This should be a float between 0 and 1.

Returns
Details

<async> start( [ options ] ) → {Promise.<void>}

Description

Tries to find a video stream matching the specified constraints. If one is found, the stream is attached to the <video> element specified upon construction of the VideoInput object (if any).

Parameters
Name Type Attributes Description
options Object <optional>
Name Type Attributes Default Description
deviceId boolean <optional>

The id of a specific device to connect to. Device IDs can be viewed by calling the getInputs() method.

visible boolean <optional>
true

Whether the <video> element should initially be visible or not.

constraints MediaTrackConstraints <optional>

The video constraints to apply when looking for an input video track (see MediaTrackConstraints for more info).

Returns
Details

<async> stop() → {Promise.<void>}

Description

Disconnects the video input and stops all associated tracks.

Returns
Details