v159 · dom · media session
Video-call mute controls
A call UI should only show “muted” once the browser has accepted the new capture state — in browsers with a capture-pause policy the spec lets that take a prompt, or be refused with NotAllowedError. With Chrome 159 the control bar can await setMicrophoneActive() / setCameraActive(), and the same code registers togglemicrophone, togglecamera and hangup handlers so the browser’s own capture UI drives the same state.
This page opens no camera or microphone and asks for no permission: it only reports the call’s desired capture state to the browser, which is all these methods do. In a real call you would also set track.enabled on your MediaStreamTracks.
Your tile
In call. Microphone and camera reported active.
Browser acknowledgement log
the pattern
async function setMic(active) {
micBtn.setAttribute("aria-busy", "true");
try {
// Promise.resolve() normalises: Chrome 159 returns Promise<undefined>,
// Chrome ≤158 returns undefined — both become an awaitable promise.
await Promise.resolve(navigator.mediaSession.setMicrophoneActive(active));
track.enabled = active; // only after the browser accepted it
micBtn.setAttribute("aria-pressed", String(!active));
} catch (e) {
showError(e.name); // NotAllowedError / InvalidStateError
} finally {
micBtn.removeAttribute("aria-busy");
}
}
navigator.mediaSession.setActionHandler("togglemicrophone", () => setMic(!micActive));
navigator.mediaSession.setActionHandler("togglecamera", () => setCam(!camActive));
navigator.mediaSession.setActionHandler("hangup", () => leave());
// Leaving: report both off and wait for both acknowledgements
await Promise.all([setMic(false), setCam(false)]);
Chromium resolves immediately (it has no pause policy and never prompts), so the busy state is brief here. Safari can take longer. The browser surfaces the toggle buttons in its own UI only while the page is really capturing, so in this demo the handlers are registered but your browser is unlikely to call them.