blob: a63f502505605b40f50f6f6646ef9f5f1b0c064f [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script>
let stream = null;
function promptForCapture()
{
navigator.mediaDevices.enumerateDevices().then(() => {
return navigator.mediaDevices.getUserMedia({ audio: false, video: true })
}).then((s) => {
stream = s;
video.srcObject = stream;
console.log("Got user media");
}).catch((error) => console.log(`Failed with error: ${error}`));
}
function stop(kind)
{
let activeTracks = [];
stream.getTracks().forEach(track => {
if (!kind || track.kind == kind)
track.stop();
else
activeTracks.push(track);
});
if (!activeTracks.length) {
stream = null;
video.srcObject = null;
}
}
function haveStream()
{
return stream !== null;
}
function doMultipleGetUserMediaSynchronously()
{
navigator.mediaDevices.getUserMedia({video: true});
navigator.mediaDevices.getUserMedia({video: true});
navigator.mediaDevices.getUserMedia({video: true});
// This one should prompt.
navigator.mediaDevices.getUserMedia({audio: true});
navigator.mediaDevices.getUserMedia({audio: true});
navigator.mediaDevices.getUserMedia({audio: true});
navigator.mediaDevices.getUserMedia({audio: true, video: true});
}
function captureAudio()
{
navigator.mediaDevices.getUserMedia({audio: true}).then(s => stream = s);
}
function captureVideo()
{
navigator.mediaDevices.getUserMedia({video: true}).then(s => video.srcObject = s);
}
function captureAudioAndVideo()
{
navigator.mediaDevices.getUserMedia({audio: true, video: true}).then(s => stream = s);
}
function notifyEndedEvent()
{
if (!stream || !stream.getVideoTracks().length) {
window.webkit.messageHandlers.gum.postMessage("No stream or video track");
return;
}
let waitForEndedEvent = true;
stream.getVideoTracks()[0].onended = () => {
if (!waitForEndedEvent)
return;
waitForEndedEvent = false;
window.webkit.messageHandlers.gum.postMessage("PASS");
}
setTimeout(() => {
if (!waitForEndedEvent)
return;
waitForEndedEvent = false;
window.webkit.messageHandlers.gum.postMessage("Did not receive an ended event after 5 seconds");
}, 5000);
}
function checkGetCapabilities() {
window.webkit.messageHandlers.gum.postMessage(RTCRtpSender.getCapabilities('video') != null ? "PASS" : "FAIL");
}
</script>
<head>
<body onload="promptForCapture()">
<video id="video" controls></video>
<p>
<button onclick="stop()">Stop</button>
</p>
</body>
</html>