MediaStreamTrack

Signature

// Not constructed directly; obtained from a stream:
const [videoTrack] = stream.getVideoTracks();
const [audioTrack] = stream.getAudioTracks();

What it does

Represents one media source within a stream: a single audio or video feed. Tracks are what an RTCPeerConnection actually sends and receives.

Key members

Member Kind Purpose
kind property audio or video.
id property Unique track identifier.
label property Human-readable source name.
enabled property Set false to mute the track without stopping it.
muted property Read-only; true when no data flows from the source.
readyState property live or ended.
stop() method Permanently end the track and release the device.
applyConstraints() method Re-request resolution, frame rate, or other settings.
getSettings() method The current effective settings.
ended / mute / unmute event Source lifecycle changes.

Behaviour & constraints

  • enabled = false keeps the track live but sends silence or black frames: cheap toggle for mute.
  • stop() is irreversible and frees the underlying device (camera light off).
  • muted is controlled by the source, not your code; only enabled is writable.
  • A stopped track stays in its stream until removed but reports readyState ended.
  • applyConstraints() may reject if the device cannot honour the request.

Example

const [video] = stream.getVideoTracks();

// Toggle camera off without dropping the negotiation:
video.enabled = false;

// Replace the track on an existing sender, no renegotiation:
const sender = pc.getSenders().find((s) => s.track?.kind === 'video');
await sender.replaceTrack(newVideoTrack);

See also