diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/webrtc/get_user_media_in_frame.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/webrtc/get_user_media_in_frame.html | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/browser/base/content/test/webrtc/get_user_media_in_frame.html b/browser/base/content/test/webrtc/get_user_media_in_frame.html new file mode 100644 index 0000000000..13922b291f --- /dev/null +++ b/browser/base/content/test/webrtc/get_user_media_in_frame.html @@ -0,0 +1,97 @@ +<!DOCTYPE html> +<html> +<head><meta charset="UTF-8"></head> +<body> +<div id="message"></div> +<script> +// Specifies whether we are using fake streams to run this automation +var useFakeStreams = true; +try { + var audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev"); + var videoDevice = SpecialPowers.getCharPref("media.video_loopback_dev"); + dump("TEST DEVICES: Using media devices:\n"); + dump("audio: " + audioDevice + "\nvideo: " + videoDevice + "\n"); + useFakeStreams = false; +} catch (e) { + dump("TEST DEVICES: No test devices found (in media.{audio,video}_loopback_dev, using fake streams.\n"); + useFakeStreams = true; +} + +function message(m) { + document.getElementById("message").innerHTML += `${m}<br>`; + window.top.postMessage(m, "*"); +} + +var gStreams = []; + +function requestDevice(aAudio, aVideo, aShare) { + var opts = {video: aVideo, audio: aAudio}; + if (aShare) { + opts.video = { mediaSource: aShare }; + } else if (useFakeStreams) { + opts.fake = true; + } + + window.navigator.mediaDevices.getUserMedia(opts) + .then(stream => { + gStreams.push(stream); + message("ok"); + }, err => message("error: " + err)); +} +message("pending"); + +function stopTracks(aKind) { + for (let stream of gStreams) { + for (let track of stream.getTracks()) { + if (track.kind == aKind) { + track.stop(); + stream.removeTrack(track); + } + } + } + gStreams = gStreams.filter(s => !!s.getTracks().length); +} + +function closeStream() { + for (let stream of gStreams) { + for (let track of stream.getTracks()) { + track.stop(); + } + } + gStreams = []; + message("closed"); +} + +const query = document.location.search.substring(1); +const params = new URLSearchParams(query); +const origins = params.getAll("origin"); +const nested = params.getAll("nested"); +const gumpage = nested.length + ? "get_user_media_in_frame.html" + : "get_user_media.html"; +let id = 1; +if (!origins.length) { + for(let i = 0; i < 2; ++i) { + const iframe = document.createElement("iframe"); + iframe.id = `frame${id++}`; + iframe.src = gumpage; + document.body.appendChild(iframe); + } +} else { + for (let origin of origins) { + const iframe = document.createElement("iframe"); + iframe.id = `frame${id++}`; + const base = new URL("browser/browser/base/content/test/webrtc/", origin).href; + const url = new URL(gumpage, base); + for (let nestedOrigin of nested) { + url.searchParams.append("origin", nestedOrigin); + } + iframe.src = url.href; + iframe.allow = "camera;microphone"; + iframe.style = `width:${300 * Math.max(1, nested.length) + (nested.length ? 50 : 0)}px;`; + document.body.appendChild(iframe); + } +} +</script> +</body> +</html> |