Why when both audio and video MediaStreamTracks enabled parameter set to false, “on-air” indicator keeps being turned on?

我是研究僧i 提交于 2021-01-27 15:50:38

问题


W3C http://www.w3.org/TR/mediacapture-streams/#life-cycle-and-media-flow article on media flow lifecycle says:

When all tracks connected to a source are muted or disabled, the "on-air" or "recording" indicator for that source can be turned off; when the track is no longer muted or disabled, it must be turned back on.

Is mentioned behaviour implemented in Chrome or not?


回答1:


Update: Firefox now supports turning off the camera light on mute. Edits in bold.

I gather from the subject that you know the answer is no.

Neither Chrome nor Firefox turn off the camera light while a site (temporarily) disables a camera stream. The spec says "can" for turning it off, but "MUST" for turning it back on, so both browsers are in compliance.

You can try it here:

var start = () => navigator.mediaDevices.getUserMedia({ video: true })
  .then(stream => video.srcObject = stream)
  .catch(e => log(e.name));

toggle.onclick = () => {
  var track = video.srcObject && video.srcObject.getVideoTracks()[0];
  if (!track) return;
  toggle.innerHTML = (track.enabled = !track.enabled) ? "Disable" : "Enable";
}

var log = msg => div.innerHTML += "<p>" + msg + "</p>";
<video id="video" height="120" width="160" autoplay></video><br>
<button onclick="start()">Start!</button>
<button id="toggle">Disable</button><div id="div"></div>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>

Note: In Chrome use https://jsfiddle.net/jib1/b6tyjm4s/ instead (getUserMedia + snippets != <3).

As to why, the spec also says:

When permission is not stored, permission should last only until such time as all MediaStreamTracks sourced from that device have been stopped.

This is observable from the camera light as well as in-browser camera & microphone live indicators. For non-persistent permissions, both browsers guarantee users that a site's access ends when the camera light goes off. Turning off the light while a site temporarily disables a stream would break this guarantee. In-browser indicators may buttress this problem.

I'd have to speculate when it comes to https in Chrome, but at least for Firefox, where permission grants are non-persistent by default, this is why.



来源:https://stackoverflow.com/questions/33304281/why-when-both-audio-and-video-mediastreamtracks-enabled-parameter-set-to-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!