MediaStream: active property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
Theactive read-only property of theMediaStream interface returns a Boolean value which istrue if the stream is currently active; otherwise, it returnsfalse. A stream is consideredactive if at least one ofitsMediaStreamTracks does not have its propertyMediaStreamTrack.readyStateset toended. Once every track has ended, the stream'sactive property becomesfalse.
In this article
Value
A Boolean value which istrue if the stream is currently active;otherwise, the value isfalse.
Examples
In this example, a new stream whose source is the user's local camera and microphone isrequested usinggetUserMedia(). When thatstream becomes available (that is, when the returnedPromise is fulfilled,a button on the page is updated based on whether or not the stream is currently active.
const promise = navigator.mediaDevices.getUserMedia({ audio: true, video: true,});promise.then((stream) => { const startBtn = document.querySelector("#startBtn"); startBtn.disabled = stream.active;});Specifications
| Specification |
|---|
| Media Capture and Streams> # dom-mediastream-active> |