Closed Bug 1397977 Opened 7 years ago Closed 2 years ago

devicechange event mustn't be kept from tab in focus (or later receiving focus)

Categories

(Core :: WebRTC: Audio/Video, defect, P2)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1753131
Tracking Status
firefox57 --- affected

People

(Reporter: jib, Unassigned)

References

Details

The spec [1] requires us to always fire the devicechange event on tabs where:

  • permission is "granted",
  • any of the input devices are attached to an active MediaStream in the browsing context, or
  • the active document is fully active and has focus.

Our current implementation is too conservative, only firing on the first two categories.

[1] https://w3c.github.io/mediacapture-main/getusermedia.html#mediadevices
Rank: 22
Priority: -- → P2
Mass change P2->P3 to align with new Mozilla triage process.
Priority: P2 → P3
Upping priority as a fix is overdue.
Rank: 22 → 18
Priority: P3 → P2

(In reply to Jan-Ivar Bruaroey [:jib] (needinfo? me) from comment #0)

The spec [1] requires us to always fire the devicechange event on tabs where:

• permission is "granted",
• any of the input devices are attached to an active MediaStream in the
browsing context, or
• the active document is fully active and has focus.

Our current implementation is too conservative, only firing on the first two
categories.

[1] https://w3c.github.io/mediacapture-main/getusermedia.html#mediadevices

At Firefox 77.0.1 (32-bit) ondevicechange is fired when the active document does not have focus.

Is this already fixed?

Note, the jsfiddle link https://fiddle.jshell.net/jib1/LbtxeLvw/show at https://stackoverflow.com/a/62161568 is 404.

Cannot reproduce the issue described at https://stackoverflow.com/questions/62154061/firefox-32-bit-does-not-fire-ondevicechange-event at 32 -bit Linux.

Perhaps OP needs to post a minimal, complete, verifiable example.

Observed this bug today on Unity content when running on Windows 10 and Firefox 81, the following code does not work in Firefox, but works on Chrome:

<html>
<body>
<script>
	function test() {
		console.log('starting media enumeration');
		var t0 = performance.now();
		navigator.mediaDevices.enumerateDevices().then(function(devices) {
			console.log('finished media enumeration, took ' + (performance.now() - t0));
			devices.forEach(function(device) {
				console.log(device);
			});
		});
	}
	test();

	navigator.mediaDevices.ondevicechange = function(event) { // Fires in Chrome, not in Firefox
		console.log('ondevicechange');
		test();
	}

	navigator.mediaDevices.addEventListener('devicechange', function(event) { // Fires in Chrome, not in Firefox
		console.log('devicechange');
		test();
	});
</script>
</body>
</html>

Open e.g. just via file:// .

Considering shipping the following polling workaround in Unity, not sure of the performance implications:

	// Work around Firefox bug on Windows:
	// https://bugzilla.mozilla.org/show_bug.cgi?id=1397977, devicechange
	// events do not fire, so resort to polling for device changes once every
	// 60 seconds.
	if (/Firefox/.test(navigator.userAgent)) {
		setInterval(test, 60000);
	}

Maybe this will cause stuttering on Unity content on Windows, but cannot think of any other way to resolve.

#8 devicechange is fired at Firefox 81 and Nightly 83 (Linux, 64-bit) when USB camera plus microphone device is connected to machine when media.navigator.permission.disabled is set to true at about:config.

#8 Note, at Chromium 88 label of devices is always empty string "" at enumerateDevices() at file: protocol when running the provided HTML, including after calling navigator.mediaDevices.getUserMedia({video: true}) granting permissions for the page.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → DUPLICATE
No longer blocks: 1397978
You need to log in before you can comment on or make changes to this bug.