browser/base/content/test/webrtc/get_user_media.html
author Sebastian Hengst <archaeopteryx@coole-files.de>
Thu, 29 Jun 2017 01:01:15 +0200
changeset 366665 36ea00c880db9a3a16e5e9e8441bdf87e3012f81
parent 366639 1cd9e27f0fa16bd65edc431ca37bbcd5ad72b3bd
child 367193 003e74a2a953449614ea1355f7f5b9dfdcf1654c
permissions -rw-r--r--
Backed out changeset 1cd9e27f0fa1 (bug 1351608)

<!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;
  window.parent.postMessage(m, "*");
}

var gStreams = [];

function requestDevice(aAudio, aVideo, aShare, aBadDevice = false) {
  var opts = {video: aVideo, audio: aAudio};
  if (aShare) {
    opts.video = {
      mozMediaSource: aShare,
      mediaSource: aShare
    }
  } else if (useFakeStreams) {
    opts.fake = true;
  }

  if (aVideo && aBadDevice) {
    opts.video = {
      deviceId: "bad device"
    }
    opts.fake = true;
  }

  if (aAudio && aBadDevice) {
    opts.audio = {
      deviceId: "bad device"
    }
    opts.fake = true;
  }

  window.navigator.mediaDevices.getUserMedia(opts)
    .then(stream => {
      gStreams.push(stream);
      message("ok");
    }, err => message("error: " + err));
}
message("pending");

function closeStream() {
  for (let stream of gStreams) {
    if (stream) {
      stream.getTracks().forEach(t => t.stop());
      stream = null;
    }
  }
  gStreams = [];
  message("closed");
}
</script>
</body>
</html>