Skip to content

RTCMediaDevice

Ajša Terko edited this page Feb 19, 2024 · 1 revision



getAudioInputDevices()

Description

Returns an array of MediaDevice objects representing the available audio input devices.

Arguments

  • none

Returns

Example

RTCMediaDevice.getAudioInputDevices().then(
    mediaDevices => {
        console.log(`Available audio input devices: ${mediaDevices.map(device => device.label).join(', ')}`)
    }
);



getAudioOutputDevices()

Description

Returns an array of MediaDevice objects representing the available audio output devices.

Arguments

  • none

Returns

Example

RTCMediaDevice.getAudioOutputDevices().then(
    mediaDevices => {
        console.log(`Available audio ouput devices: ${mediaDevices.map(device => device.label).join(', ')}`)
    }
);



getVideoInputDevices()

Description

Returns an array of MediaDevice objects representing the available video input devices.

Arguments

  • none

Returns

Example

RTCMediaDevice.getVideoInputDevices().then(
    mediaDevices => {
        console.log(`Available video input devices: ${mediaDevices.map(device => device.label).join(', ')}`)
    }
);



getMediaStream(deviceId)

Description

Returns a MediaStream object that represents a stream of media content from a device associated with a given deviceId.

Arguments

  • deviceId: string - Audio or video input device identifier.

Returns

Example

RTCMediaDevice.getAudioInputDevices().then(mediaDevices => {
    let deviceId = mediaDevices[0].deviceId;
    RTCMediaDevice.getMediaStream(deviceId)
        .then(stream => $('#my-audio').srcObject = stream);
});



getAudioMediaStream(deviceId)

Description

Returns a MediaStream object that represents a stream of an audio media content from a device associated with a given deviceId.

Arguments

  • deviceId: string - Audio input device identifier.

Returns

Example

RTCMediaDevice.getAudioMediaStream(null)
    .then(stream => $('#my-audio').srcObject = stream);



getVideoMediaStream(deviceId, cameraOrientation)

Description

Returns a MediaStream object that represents a stream of a video media content from a device associated with a given deviceId.

Arguments

  • deviceId: string - Video input device identifier.
  • cameraOrientation: CameraOrientation - Optional enum value representing camera facing mode of the preview video. Default value is FRONT.

Returns

Example

RTCMediaDevice.getVideoMediaStream(null)
    .then(stream => $('#my-video').srcObject = stream);



closeMediaStream(mediaStream)

Description

Closes a media stream. This should be done whenever the stream is not needed anymore or an interaction with it is over.

Arguments

  • mediaStream: MediaStream - A media stream that you want to close.

Returns

  • N/A

Example

const stream = $('#my-video').srcObject;

RTCMediaDevice.closeMediaStream(stream);
$('#my-video').srcObject = null;

Tutorials

Migration guides

Reference documentation

Clone this wiki locally